util

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2020 License: Apache-2.0 Imports: 42 Imported by: 35

Documentation

Overview

TODO: consider moving it to a more generic package.

Index

Constants

View Source
const (
	DefaultKubeFedSystemNamespace = "kube-federation-system"

	KubeAPIQPS   = 20.0
	KubeAPIBurst = 30
	TokenKey     = "token"

	KubeFedConfigName = "kubefed"
)
View Source
const (
	NoResyncPeriod time.Duration = 0 * time.Second

	NamespaceName = "namespaces"
	NamespaceKind = "Namespace"

	ServiceKind = "Service"

	ServiceAccountKind = "ServiceAccount"

	// Common fields
	SpecField     = "spec"
	StatusField   = "status"
	MetadataField = "metadata"

	// ServiceAccount fields
	SecretsField = "secrets"

	// Scale types
	ReplicasField       = "replicas"
	RetainReplicasField = "retainReplicas"

	// Template fields
	TemplateField = "template"

	// Placement fields
	PlacementField       = "placement"
	ClusterSelectorField = "clusterSelector"
	MatchLabelsField     = "matchLabels"

	// Override fields
	OverridesField        = "overrides"
	ClusterNameField      = "clusterName"
	ClusterOverridesField = "clusterOverrides"
	PathField             = "path"
	ValueField            = "value"

	// Cluster reference
	ClustersField = "clusters"
	NameField     = "name"
)

Providing 0 duration to an informer indicates that resync should be delayed as long as possible

View Source
const (
	ManagedByKubeFedLabelKey     = "kubefed.io/managed"
	ManagedByKubeFedLabelValue   = "true"
	UnmanagedByKubeFedLabelValue = "false"
)
View Source
const (
	// If this annotation is present on a federated resource, resources in the
	// member clusters managed by the federated resource should be orphaned.
	// If the annotation is not present (the default), resources in member
	// clusters will be deleted before the federated resource is deleted.
	OrphanManagedResourcesAnnotation = "kubefed.io/orphan"
	OrphanedManagedResourcesValue    = "true"
)

Variables

View Source
var NamespaceForCluster = namespaceForCluster

NamespaceForCluster returns the namespace to use for the given cluster.

View Source
var NamespaceForResource = namespaceForResource

NamespaceForResource returns either the kubefed namespace or resource namespace.

View Source
var QualifiedNameForCluster = qualifiedNameForCluster

QualifiedNameForCluster returns the qualified name to use for the given cluster.

Functions

func AddManagedLabel added in v0.0.9

func AddManagedLabel(obj *unstructured.Unstructured)

AddManagedLabel ensures that the given object has the managed label.

func ApplyJSONPatch added in v0.4.1

func ApplyJSONPatch(obj *unstructured.Unstructured, overrides ClusterOverrides) error

ApplyJSONPatch applies the override on to the given unstructured object.

func BuildClusterConfig

func BuildClusterConfig(fedCluster *fedv1b1.KubeFedCluster, client generic.Client, fedNamespace string) (*restclient.Config, error)

BuildClusterConfig returns a restclient.Config that can be used to configure a client for the given KubeFedCluster or an error. The client is used to access kubernetes secrets in the kubefed namespace.

func CustomizeCertificateValidation added in v0.3.0

func CustomizeCertificateValidation(fedCluster *fedv1b1.KubeFedCluster, tlsConfig *tls.Config) error

CustomizeCertificateValidation modifies an existing tls.Config to disable the desired TLS checks in KubeFedCluster config

func CustomizeTLSTransport added in v0.3.0

func CustomizeTLSTransport(fedCluster *fedv1b1.KubeFedCluster, clientConfig *restclient.Config) error

CustomizeTLSTransport replaces the restclient.Config.Transport with one that implements the desired TLS certificate validations

func DeepCopyRelevantObjectMeta

func DeepCopyRelevantObjectMeta(obj metav1.ObjectMeta) metav1.ObjectMeta

Deep copies cluster-independent, user provided data from the given ObjectMeta struct. If in the future the ObjectMeta structure is expanded then any field that is not populated by the api server should be included here.

func DisableOrphaning added in v0.3.0

func DisableOrphaning(obj *unstructured.Unstructured)

Disables the orphaning mode

func EnableOrphaning added in v0.3.0

func EnableOrphaning(obj *unstructured.Unstructured)

Enables the orphaning mode

func GetClusterNames

func GetClusterNames(obj *unstructured.Unstructured) ([]string, error)

func GetUnstructured added in v0.0.3

func GetUnstructured(resource interface{}) (*unstructured.Unstructured, error)

GetUnstructured return Unstructured for any given kubernetes type

func HasManagedLabel added in v0.0.9

func HasManagedLabel(obj *unstructured.Unstructured) bool

HasManagedLabel indicates whether the given object has the managed label.

func IsClusterReady added in v0.0.2

func IsClusterReady(clusterStatus *fedv1b1.KubeFedClusterStatus) bool

func IsExplicitlyUnmanaged added in v0.3.0

func IsExplicitlyUnmanaged(obj *unstructured.Unstructured) bool

IsExplicitlyUnmanaged indicates whether the given object has the managed label with value false.

func IsOrphaningEnabled added in v0.3.0

func IsOrphaningEnabled(obj *unstructured.Unstructured) bool

IsOrphaningEnabled checks status of "orphaning enable" (OrphanManagedResources: OrphanedManagedResourceslValue') annotation on a resource.

func IsPrimaryCluster

func IsPrimaryCluster(obj, clusterObj pkgruntime.Object) bool

IsPrimaryCluster checks if the caller is working with objects for the primary cluster by checking if the UIDs match for both ObjectMetas passed in. TODO (font): Need to revisit this when cluster ID is available.

func MetaAccessor

func MetaAccessor(obj runtime.Object) metav1.Object

func NewGenericInformer added in v0.0.6

func NewGenericInformer(config *rest.Config, namespace string, obj pkgruntime.Object, resyncPeriod time.Duration, triggerFunc func(pkgruntime.Object)) (cache.Store, cache.Controller, error)

func NewGenericInformerWithEventHandler added in v0.0.7

func NewGenericInformerWithEventHandler(config *rest.Config, namespace string, obj pkgruntime.Object, resyncPeriod time.Duration, resourceEventHandlerFuncs *cache.ResourceEventHandlerFuncs) (cache.Store, cache.Controller, error)

func NewManagedResourceInformer added in v0.0.9

func NewManagedResourceInformer(client ResourceClient, namespace string, apiResource *metav1.APIResource, triggerFunc func(pkgruntime.Object)) (cache.Store, cache.Controller)

NewManagedResourceInformer returns an informer limited to resources managed by KubeFed as indicated by labeling.

func NewResourceInformer

func NewResourceInformer(client ResourceClient, namespace string, apiResource *metav1.APIResource, triggerFunc func(pkgruntime.Object)) (cache.Store, cache.Controller)

NewResourceInformer returns an unfiltered informer.

func NewTriggerOnAllChanges

func NewTriggerOnAllChanges(triggerFunc func(pkgruntime.Object)) *cache.ResourceEventHandlerFuncs

Returns cache.ResourceEventHandlerFuncs that trigger the given function on all object changes.

func ObjFromCache added in v0.0.5

func ObjFromCache(store cache.Store, kind, key string) (*unstructured.Unstructured, error)

func ObjectMetaAndSpecEquivalent

func ObjectMetaAndSpecEquivalent(a, b runtime.Object) bool

Checks if cluster-independent, user provided data in ObjectMeta and Spec in two given top level api objects are equivalent.

func ObjectMetaEquivalent

func ObjectMetaEquivalent(a, b metav1.ObjectMeta) bool

Checks if cluster-independent, user provided data in two given ObjectMeta are equal. If in the future the ObjectMeta structure is expanded then any field that is not populated by the api server should be included here.

func ObjectMetaObjEquivalent

func ObjectMetaObjEquivalent(a, b metav1.Object) bool

Checks if cluster-independent, user provided data in two given ObjectMeta are equal. If in the future the ObjectMeta structure is expanded then any field that is not populated by the api server should be included here.

func ObjectNeedsUpdate added in v0.0.6

func ObjectNeedsUpdate(desiredObj, clusterObj *unstructured.Unstructured, recordedVersion string) bool

ObjectNeedsUpdate determines whether the 2 objects provided cluster object needs to be updated according to the desired object and the recorded version.

func ObjectVersion added in v0.0.6

func ObjectVersion(clusterObj *unstructured.Unstructured) string

ObjectVersion retrieves the field type-prefixed value used for determining currency of the given cluster object.

func PropagatedVersionStatusEquivalent

func PropagatedVersionStatusEquivalent(pvs1, pvs2 *fedv1a1.PropagatedVersionStatus) bool

PropagatedVersionStatusEquivalent returns true if both statuses are equal by comparing Template and Override version, and their ClusterVersion slices; false otherwise.

func RemoveManagedLabel added in v0.0.9

func RemoveManagedLabel(obj *unstructured.Unstructured)

RemoveManagedLabel ensures that the given object does not have the managed label.

func SetClusterNames

func SetClusterNames(obj *unstructured.Unstructured, clusterNames []string) error

func SetOverrides added in v0.0.4

func SetOverrides(fedObject *unstructured.Unstructured, overridesMap OverridesMap) error

SetOverrides sets the spec.overrides field of the unstructured object from the provided overrides map.

func SortClusterVersions

func SortClusterVersions(versions []fedv1a1.ClusterObjectVersion)

SortClusterVersions ASCII sorts the given cluster versions slice based on cluster name.

func StartBackoffGC

func StartBackoffGC(backoff *flowcontrol.Backoff, stopCh <-chan struct{})

func UnstructuredToInterface added in v0.0.6

func UnstructuredToInterface(rawObj *unstructured.Unstructured, obj interface{}) error

UnstructuredToInterface converts an unstructured object to the provided interface by json marshalling/unmarshalling.

Types

type ClusterHealthCheckConfig added in v0.0.9

type ClusterHealthCheckConfig struct {
	Period           time.Duration
	FailureThreshold int64
	SuccessThreshold int64
	Timeout          time.Duration
}

ClusterHealthCheckConfig defines the configurable parameters for cluster health check

type ClusterLifecycleHandlerFuncs

type ClusterLifecycleHandlerFuncs struct {
	// Fired when the cluster becomes available.
	ClusterAvailable func(*fedv1b1.KubeFedCluster)
	// Fired when the cluster becomes unavailable. The second arg contains data that was present
	// in the cluster before deletion.
	ClusterUnavailable func(*fedv1b1.KubeFedCluster, []interface{})
}

A structure with cluster lifecycle handler functions. Cluster is available (and ClusterAvailable is fired) when it is created in federated etcd and ready. Cluster becomes unavailable (and ClusterUnavailable is fired) when it is either deleted or becomes not ready. When cluster spec (IP)is modified both ClusterAvailable and ClusterUnavailable are fired.

type ClusterOverride added in v0.0.3

type ClusterOverride struct {
	Op    string      `json:"op,omitempty"`
	Path  string      `json:"path"`
	Value interface{} `json:"value,omitempty"`
}

type ClusterOverrides added in v0.0.2

type ClusterOverrides []ClusterOverride

Slice of ClusterOverride

type ControllerConfig added in v0.0.3

type ControllerConfig struct {
	KubeFedNamespaces
	KubeConfig              *restclient.Config
	ClusterAvailableDelay   time.Duration
	ClusterUnavailableDelay time.Duration
	MinimizeLatency         bool
	SkipAdoptingResources   bool
}

ControllerConfig defines the configuration common to KubeFed controllers.

func (*ControllerConfig) LimitedScope added in v0.0.6

func (c *ControllerConfig) LimitedScope() bool

type DelayingDeliverer

type DelayingDeliverer struct {
	// contains filtered or unexported fields
}

A structure that pushes the items to the target channel at a given time.

func NewDelayingDeliverer

func NewDelayingDeliverer() *DelayingDeliverer

func NewDelayingDelivererWithChannel

func NewDelayingDelivererWithChannel(targetChannel chan *DelayingDelivererItem) *DelayingDeliverer

func (*DelayingDeliverer) DeliverAfter

func (d *DelayingDeliverer) DeliverAfter(key string, value interface{}, delay time.Duration)

Delivers value after the given delay.

func (*DelayingDeliverer) DeliverAt

func (d *DelayingDeliverer) DeliverAt(key string, value interface{}, deliveryTime time.Time)

Delivers value at the given time.

func (*DelayingDeliverer) GetTargetChannel

func (d *DelayingDeliverer) GetTargetChannel() chan *DelayingDelivererItem

Gets target channel of the deliverer.

func (*DelayingDeliverer) Start

func (d *DelayingDeliverer) Start()

Starts the DelayingDeliverer.

func (*DelayingDeliverer) StartWithHandler

func (d *DelayingDeliverer) StartWithHandler(handler func(*DelayingDelivererItem))

Starts Delaying deliverer with a handler listening on the target channel.

func (*DelayingDeliverer) Stop

func (d *DelayingDeliverer) Stop()

Stops the DelayingDeliverer. Undelivered items are discarded.

type DelayingDelivererItem

type DelayingDelivererItem struct {
	// Key under which the value was added to deliverer.
	Key string
	// Value of the item.
	Value interface{}
	// When the item should be delivered.
	DeliveryTime time.Time
}

DelayingDelivererItem is structure delivered by DelayingDeliverer to the target channel.

type FederatedInformer

type FederatedInformer interface {
	RegisteredClustersView

	// Returns a store created over all stores from target informers.
	GetTargetStore() FederatedReadOnlyStore

	// Starts all the processes.
	Start()

	// Stops all the processes inside the informer.
	Stop()
}

FederatedInformer provides access to clusters registered with a KubeFed control plane and watches a given resource type in registered clusters.

Whenever a new cluster is registered with KubeFed, an informer is created for it using TargetInformerFactory. Informers are stopped when a cluster is either put offline of deleted. It is assumed that some controller keeps an eye on the cluster list and thus the clusters in ETCD are up to date.

func NewFederatedInformer

func NewFederatedInformer(
	config *ControllerConfig,
	client generic.Client,
	apiResource *metav1.APIResource,
	triggerFunc func(pkgruntime.Object),
	clusterLifecycle *ClusterLifecycleHandlerFuncs) (FederatedInformer, error)

Builds a FederatedInformer for the given configuration.

type FederatedObject

type FederatedObject struct {
	Object      interface{}
	ClusterName string
}

An object with an origin information.

type FederatedReadOnlyStore

type FederatedReadOnlyStore interface {
	// Returns all items in the store.
	List() ([]FederatedObject, error)

	// Returns all items from a cluster.
	ListFromCluster(clusterName string) ([]interface{}, error)

	// GetKeyFor returns the key under which the item would be put in the store.
	GetKeyFor(item interface{}) string

	// GetByKey returns the item stored under the given key in the specified cluster (if exist).
	GetByKey(clusterName string, key string) (interface{}, bool, error)

	// Returns the items stored under the given key in all clusters.
	GetFromAllClusters(key string) ([]FederatedObject, error)

	// Checks whether stores for all clusters form the lists (and only these) are there and
	// are synced. This is only a basic check whether the data inside of the store is usable.
	// It is not a full synchronization/locking mechanism it only tries to ensure that out-of-sync
	// issues occur less often.	All users of the interface should assume
	// that there may be significant delays in content updates of all kinds and write their
	// code that it doesn't break if something is slightly out-of-sync.
	ClustersSynced(clusters []*fedv1b1.KubeFedCluster) bool
}

FederatedReadOnlyStore is an overlay over multiple stores created in federated clusters.

type FederatedResource added in v0.0.3

type FederatedResource struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`

	ClusterStatus []ResourceClusterStatus `json:"clusterStatus,omitempty"`
}

FederatedResource is a generic representation of a federated type

type GenericClusterReference added in v0.3.0

type GenericClusterReference struct {
	Name string `json:"name"`
}

type GenericOverride added in v0.0.5

type GenericOverride struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`

	Spec *GenericOverrideSpec `json:"spec,omitempty"`
}

type GenericOverrideItem added in v0.0.5

type GenericOverrideItem struct {
	ClusterName      string            `json:"clusterName"`
	ClusterOverrides []ClusterOverride `json:"clusterOverrides,omitempty"`
}

type GenericOverrideSpec added in v0.0.5

type GenericOverrideSpec struct {
	Overrides []GenericOverrideItem `json:"overrides,omitempty"`
}

type GenericPlacement added in v0.0.4

type GenericPlacement struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`

	Spec GenericPlacementSpec `json:"spec,omitempty"`
}

func UnmarshalGenericPlacement added in v0.3.0

func UnmarshalGenericPlacement(obj *unstructured.Unstructured) (*GenericPlacement, error)

func (*GenericPlacement) ClusterNames added in v0.3.0

func (p *GenericPlacement) ClusterNames() []string

func (*GenericPlacement) ClusterSelector added in v0.3.0

func (p *GenericPlacement) ClusterSelector() (labels.Selector, error)

type GenericPlacementFields added in v0.0.6

type GenericPlacementFields struct {
	Clusters        []GenericClusterReference `json:"clusters,omitempty"`
	ClusterSelector *metav1.LabelSelector     `json:"clusterSelector,omitempty"`
}

type GenericPlacementSpec added in v0.0.4

type GenericPlacementSpec struct {
	Placement GenericPlacementFields `json:"placement,omitempty"`
}

type KubeFedNamespaces added in v0.3.0

type KubeFedNamespaces struct {
	KubeFedNamespace string
	TargetNamespace  string
}

KubeFedNamespaces defines the namespace configuration shared by most kubefed controllers.

type LeaderElectionConfiguration added in v0.0.7

type LeaderElectionConfiguration struct {
	// leaseDuration is the duration that non-leader candidates will wait
	// after observing a leadership renewal until attempting to acquire
	// leadership of a led but unrenewed leader slot. This is effectively the
	// maximum duration that a leader can be stopped before it is replaced
	// by another candidate. This is only applicable if leader election is
	// enabled.
	LeaseDuration time.Duration
	// renewDeadline is the interval between attempts by the acting master to
	// renew a leadership slot before it stops leading. This must be less
	// than or equal to the lease duration. This is only applicable if leader
	// election is enabled.
	RenewDeadline time.Duration
	// retryPeriod is the duration the clients should wait between attempting
	// acquisition and renewal of a leadership. This is only applicable if
	// leader election is enabled.
	RetryPeriod time.Duration
	// resourceLock indicates the resource object type that will be used to lock
	// during leader election cycles.
	ResourceLock fedv1b1.ResourceLockType
}

LeaderElectionConfiguration defines the configuration of leader election clients for controller that can run with leader election enabled.

type OverridesMap added in v0.0.4

type OverridesMap map[string]ClusterOverrides

Mapping of clusterName to overrides for the cluster

func GetOverrides added in v0.0.4

func GetOverrides(rawObj *unstructured.Unstructured) (OverridesMap, error)

GetOverrides returns a map of overrides populated from the given unstructured object.

func (OverridesMap) ToUnstructuredSlice added in v0.0.4

func (m OverridesMap) ToUnstructuredSlice() []interface{}

ToUnstructuredSlice converts the map of overrides to a slice of interfaces that can be set in an unstructured object.

type QualifiedName

type QualifiedName struct {
	Namespace string
	Name      string
}

func NewQualifiedName

func NewQualifiedName(obj pkgruntime.Object) QualifiedName

func (QualifiedName) String

func (n QualifiedName) String() string

String returns the general purpose string representation

type ReconcileFunc added in v0.0.2

type ReconcileFunc func(qualifiedName QualifiedName) ReconciliationStatus

type ReconcileWorker added in v0.0.2

type ReconcileWorker interface {
	Enqueue(qualifiedName QualifiedName)
	EnqueueForClusterSync(qualifiedName QualifiedName)
	EnqueueForError(qualifiedName QualifiedName)
	EnqueueForRetry(qualifiedName QualifiedName)
	EnqueueObject(obj pkgruntime.Object)
	EnqueueWithDelay(qualifiedName QualifiedName, delay time.Duration)
	Run(stopChan <-chan struct{})
	SetDelay(retryDelay, clusterSyncDelay time.Duration)
}

func NewReconcileWorker added in v0.0.2

func NewReconcileWorker(reconcile ReconcileFunc, timing WorkerTiming) ReconcileWorker

type ReconciliationStatus

type ReconciliationStatus int
const (
	StatusAllOK ReconciliationStatus = iota
	StatusNeedsRecheck
	StatusError
	StatusNotSynced
)

type RegisteredClustersView added in v0.3.0

type RegisteredClustersView interface {
	// GetClientForCluster returns a client for the cluster, if present.
	GetClientForCluster(clusterName string) (generic.Client, error)

	// GetUnreadyClusters returns a list of all clusters that are not ready yet.
	GetUnreadyClusters() ([]*fedv1b1.KubeFedCluster, error)

	// GetReadyClusters returns all clusters for which the sub-informers are run.
	GetReadyClusters() ([]*fedv1b1.KubeFedCluster, error)

	// GetClusters returns a list of all clusters.
	GetClusters() ([]*fedv1b1.KubeFedCluster, error)

	// GetReadyCluster returns the cluster with the given name, if found.
	GetReadyCluster(name string) (*fedv1b1.KubeFedCluster, bool, error)

	// ClustersSynced returns true if the view is synced (for the first time).
	ClustersSynced() bool
}

An interface to retrieve both KubeFedCluster resources and clients to access the clusters they represent.

type ResourceClient

type ResourceClient interface {
	Resources(namespace string) dynamic.ResourceInterface
	Kind() string
}

func NewResourceClient

func NewResourceClient(config *rest.Config, apiResource *metav1.APIResource) (ResourceClient, error)

type ResourceClusterStatus added in v0.0.3

type ResourceClusterStatus struct {
	ClusterName string                 `json:"clusterName,omitempty"`
	Status      map[string]interface{} `json:"status,omitempty"`
}

ResourceClusterStatus defines the status of federated resource within a cluster

type SafeMap added in v0.0.7

type SafeMap struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewSafeMap added in v0.0.7

func NewSafeMap() *SafeMap

func (*SafeMap) Delete added in v0.0.7

func (s *SafeMap) Delete(key string)

func (*SafeMap) DeleteAll added in v0.0.8

func (s *SafeMap) DeleteAll()

func (*SafeMap) Get added in v0.0.7

func (s *SafeMap) Get(key string) (interface{}, bool)

func (*SafeMap) GetAll added in v0.0.7

func (s *SafeMap) GetAll() []interface{}

func (*SafeMap) Size added in v0.0.8

func (s *SafeMap) Size() int

func (*SafeMap) Store added in v0.0.7

func (s *SafeMap) Store(key string, value interface{})

type TargetInformerFactory

type TargetInformerFactory func(*fedv1b1.KubeFedCluster, *restclient.Config) (cache.Store, cache.Controller, error)

A function that should be used to create an informer on the target object. Store should use cache.DeletionHandlingMetaNamespaceKeyFunc as a keying function.

type WorkerTiming added in v0.0.2

type WorkerTiming struct {
	Interval         time.Duration
	RetryDelay       time.Duration
	ClusterSyncDelay time.Duration
	InitialBackoff   time.Duration
	MaxBackoff       time.Duration
}

Directories

Path Synopsis
Helper functions for manipulating finalizers.
Helper functions for manipulating finalizers.

Jump to

Keyboard shortcuts

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