util

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 26, 2019 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CombineErrors added in v1.1.0

func CombineErrors(errs ...error) error

CombineErrors takes a list of errors and combines them to one. Generally it will return the first non-nil error, but if a persistent error is found it will be returned instead of non-persistent errors.

func Context added in v1.1.0

func Context() context.Context

Context returns a default Context

func CurrentNamespace added in v1.1.0

func CurrentNamespace() string

CurrentNamespace reads the current namespace from the kube config

func GetAWSRegion added in v1.2.0

func GetAWSRegion() string

GetAWSRegion parses the region from a node's name

func GetContainerStatusLine added in v1.1.0

func GetContainerStatusLine(cont *corev1.ContainerStatus) string

GetContainerStatusLine returns a one liner status for a container

func GetPodStatusLine added in v1.1.0

func GetPodStatusLine(pod *corev1.Pod) string

GetPodStatusLine returns a one liner status for a pod

func IgnoreError added in v1.2.0

func IgnoreError(err error)

IgnoreError do nothing if err is not nil

func InitLogger added in v1.0.1

func InitLogger()

InitLogger initializes the logrus logger with defaults

func IsAWSPlatform added in v1.2.0

func IsAWSPlatform() bool

IsAWSPlatform returns true if this cluster is running on AWS

func IsPersistentError added in v1.1.0

func IsPersistentError(err error) bool

IsPersistentError checks if the provided error is persistent.

func KubeApply

func KubeApply(obj runtime.Object) bool

KubeApply will check if the object exists and will create/update accordingly and report the object status.

func KubeCheck

func KubeCheck(obj runtime.Object) bool

KubeCheck checks if the object exists and reports the object status.

func KubeCheckOptional added in v1.2.0

func KubeCheckOptional(obj runtime.Object) bool

KubeCheckOptional checks if the object exists and reports the object status. It detects the situation of a missing CRD and reports it as an optional feature.

func KubeClient

func KubeClient() client.Client

KubeClient resturns a controller-runtime client We use a lazy mapper and a specialized implementation of fast mapper in order to avoid lags when running a CLI client to a far away cluster.

func KubeConfig

func KubeConfig() *rest.Config

KubeConfig loads kubernetes client config from default locations (flags, user dir, etc)

func KubeCreateSkipExisting

func KubeCreateSkipExisting(obj runtime.Object) bool

KubeCreateSkipExisting will check if the object exists and will create/skip accordingly and report the object status.

func KubeDelete

func KubeDelete(obj runtime.Object, opts ...client.DeleteOptionFunc) bool

KubeDelete deletes an object and reports the object status.

func KubeList added in v1.1.0

func KubeList(list runtime.Object, options *client.ListOptions) bool

KubeList returns a list of objects.

func KubeObject

func KubeObject(text string) runtime.Object

KubeObject loads a text yaml/json to a kubernets object.

func KubeRest added in v1.0.1

func KubeRest() *rest.RESTClient

KubeRest returns a configured kubernetes REST client

func KubeUpdate added in v1.1.0

func KubeUpdate(obj runtime.Object) bool

KubeUpdate updates an object and reports the object status.

func LogError added in v1.2.0

func LogError(err error)

LogError prints the error to the log and continue

func Logger added in v1.1.0

func Logger() *logrus.Entry

Logger returns a default logger

func MapperProvider added in v1.1.0

func MapperProvider(config *rest.Config) (meta.RESTMapper, error)

MapperProvider creates RESTMapper

func NewFastRESTMapper

func NewFastRESTMapper(dc discovery.DiscoveryInterface, filter APIGroupFilterFunc) meta.RESTMapper

NewFastRESTMapper initializes a FastRESTMapper

func NoGroupFilter added in v1.2.0

func NoGroupFilter(*metav1.APIGroup) bool

NoGroupFilter is a filtering function that includes all the server groups

func ObjectKey added in v1.1.0

func ObjectKey(obj runtime.Object) client.ObjectKey

ObjectKey returns the objects key (namespace + name)

func Panic added in v1.0.1

func Panic(err error)

Panic is conviniently calling panic only if err is not nil

func RandomBase64 added in v1.1.0

func RandomBase64(numBytes int) string

RandomBase64 creates a random buffer with numBytes and returns it encoded in base64 Returned string length is 4*math.Ceil(numBytes/3)

func RandomHex added in v1.1.0

func RandomHex(numBytes int) string

RandomHex creates a random buffer with numBytes and returns it encoded in hex Returned string length is 2*numBytes

func ReadCommandFlagSecret added in v1.2.0

func ReadCommandFlagSecret(cmd *cobra.Command, flag string) string

func ReadCommandFlagString added in v1.2.0

func ReadCommandFlagString(cmd *cobra.Command, flag string) string

func RemoveFinalizer added in v1.1.0

func RemoveFinalizer(obj metav1.Object, finalizer string) bool

RemoveFinalizer modifies the object and removes the finalizer

func SecretResetStringDataFromData added in v1.1.0

func SecretResetStringDataFromData(obj runtime.Object)

SecretResetStringDataFromData reads the secret data into string data to streamline the paths that use the secret values as strings.

func SetAvailableCondition added in v1.1.0

func SetAvailableCondition(conditions *[]conditionsv1.Condition, reason string, message string)

SetAvailableCondition updates the status conditions to available state

func SetErrorCondition added in v1.1.0

func SetErrorCondition(conditions *[]conditionsv1.Condition, reason string, message string)

SetErrorCondition updates the status conditions to error state

func SetProgressingCondition added in v1.1.0

func SetProgressingCondition(conditions *[]conditionsv1.Condition, reason string, message string)

SetProgressingCondition updates the status conditions to in-progress state

Types

type APIGroupFilterFunc

type APIGroupFilterFunc func(*metav1.APIGroup) bool

APIGroupFilterFunc is a filtering function to limit the amount of server groups we load

type FastRESTMapper

type FastRESTMapper struct {
	Discovery discovery.DiscoveryInterface
	Filter    APIGroupFilterFunc
	Mapper    meta.RESTMapper
}

FastRESTMapper loads the mapper data from the server with filter and concurrency and rediscovers the mapping on meta.NoKindMatchError errors See https://github.com/kubernetes-sigs/controller-runtime/issues/537

func (*FastRESTMapper) Discover added in v1.0.1

func (m *FastRESTMapper) Discover() error

Discover reads server groups and then reads each group to initialize the mapper groups.

func (*FastRESTMapper) DiscoverGroup added in v1.0.1

func (m *FastRESTMapper) DiscoverGroup(gr *restmapper.APIGroupResources) error

DiscoverGroup reads the server group

func (*FastRESTMapper) DiscoverOnError added in v1.0.1

func (m *FastRESTMapper) DiscoverOnError(err error) bool

DiscoverOnError check if the error is NoMatchError and calls discover

func (*FastRESTMapper) KindFor

KindFor implements Mapper.KindFor

func (*FastRESTMapper) KindsFor

KindsFor implements Mapper.KindsFor

func (*FastRESTMapper) RESTMapping

func (m *FastRESTMapper) RESTMapping(gk schema.GroupKind, versions ...string) (*meta.RESTMapping, error)

RESTMapping implements Mapper.RESTMapping

func (*FastRESTMapper) RESTMappings

func (m *FastRESTMapper) RESTMappings(gk schema.GroupKind, versions ...string) ([]*meta.RESTMapping, error)

RESTMappings implements Mapper.RESTMappings

func (*FastRESTMapper) ResourceFor

ResourceFor implements Mapper.ResourceFor

func (*FastRESTMapper) ResourceSingularizer

func (m *FastRESTMapper) ResourceSingularizer(resource string) (string, error)

ResourceSingularizer implements Mapper.ResourceSingularizer

func (*FastRESTMapper) ResourcesFor

ResourcesFor implements Mapper.ResourcesFor

type PersistentError added in v1.1.0

type PersistentError struct {
	Reason  string
	Message string
}

PersistentError is an error type that tells the reconcile to avoid requeueing.

func NewPersistentError added in v1.1.0

func NewPersistentError(reason string, message string) *PersistentError

NewPersistentError returns a new persistent error.

func (*PersistentError) Error added in v1.1.0

func (e *PersistentError) Error() string

Error function makes PersistentError implement error interface

type PrintColumn added in v1.0.1

type PrintColumn struct {
	Items []string
	Width int
}

PrintColumn is a column in PrintTable

func (*PrintColumn) Pad added in v1.0.1

func (c *PrintColumn) Pad(s string) string

Pad adds padding the provided string to make it print nicely as a table cell

func (*PrintColumn) RecalcWidth added in v1.0.1

func (c *PrintColumn) RecalcWidth()

RecalcWidth can be called to recalculate the column width after manual updates are made

type PrintTable added in v1.0.1

type PrintTable struct {
	Columns []PrintColumn
	NumRows int
}

PrintTable is a table for printing with fixed column width and padding

func (*PrintTable) AddRow added in v1.0.1

func (t *PrintTable) AddRow(items ...string) *PrintTable

AddRow adds a row of headers/values to the table

func (*PrintTable) RecalcWidth added in v1.0.1

func (t *PrintTable) RecalcWidth() *PrintTable

RecalcWidth can be called to recalculate the columns width after manual updates are made

func (*PrintTable) String added in v1.0.1

func (t *PrintTable) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL