util

package
v0.1.0-rc1 Latest Latest
Warning

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

Go to latest
Published: May 22, 2019 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Overview

TODO: consider moving it to a more generic package.

Index

Constants

View Source
const (
	DefaultKubeFedSystemNamespace  = "kube-federation-system"
	DefaultClusterAvailableDelay   = 20 * time.Second
	DefaultClusterUnavailableDelay = 60 * time.Second

	KubeAPIQPS   = 20.0
	KubeAPIBurst = 30
	TokenKey     = "token"

	DefaultLeaderElectionLeaseDuration = 15 * time.Second
	DefaultLeaderElectionRenewDeadline = 10 * time.Second
	DefaultLeaderElectionRetryPeriod   = 5 * time.Second
	DefaultLeaderElectionResourceLock  = fedv1b1.ConfigMapsResourceLock

	DefaultClusterHealthCheckPeriod           = 10
	DefaultClusterHealthCheckFailureThreshold = 3
	DefaultClusterHealthCheckSuccessThreshold = 1
	DefaultClusterHealthCheckTimeout          = 3

	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"

	// Propagation status fields
	ConditionsField         = "conditions"
	TypeField               = "type"
	ReasonField             = "reason"
	LastProbeTimeField      = "lastProbeTime"
	LastTransitionTimeField = "lastTransitionTime"

	// 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 (
	ManagedByFederationLabelKey   = "kubefed.k8s.io/managed"
	ManagedByFederationLabelValue = "true"
)

Variables

This section is empty.

Functions

func AddManagedLabel added in v0.0.9

func AddManagedLabel(obj *unstructured.Unstructured)

AddManagedLabel ensures that the given object has the managed label.

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 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 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 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 pkgruntime.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, triggerFunc func(pkgruntime.Object)) (cache.Store, cache.Controller)

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

func NewResourceInformer

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

NewManagedResourceInformer 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 {
	PeriodSeconds    int64
	FailureThreshold int64
	SuccessThreshold int64
	TimeoutSeconds   int64
}

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 {
	Path  string      `json:"path"`
	Value interface{} `json:"value"`
}

type ClusterOverridesMap added in v0.0.4

type ClusterOverridesMap map[string]interface{}

Mapping of qualified path (e.g. spec.replicas) to value

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 federation 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 {
	FederationView

	// 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()
}

A structure that combines an informer running against federated api server and listening for cluster updates with multiple Kubernetes API informers (called target informers) running against federation members. Whenever a new cluster is added to the federation 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 federation client and factory.

type FederatedInformerForTestOnly

type FederatedInformerForTestOnly interface {
	FederatedInformer

	SetClientFactory(func(*fedv1b1.KubeFedCluster) (ResourceClient, error))
}

FederatedInformer with extra method for setting fake clients.

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 FederationView

type FederationView interface {
	// GetClientForCluster returns a client for the cluster, if present.
	GetClientForCluster(clusterName string) (ResourceClient, 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 access federation members and clients.

type GenericClusterReference

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

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

func (*GenericPlacement) ClusterNames

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

func (*GenericPlacement) ClusterSelector

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

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]ClusterOverridesMap

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 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, ResourceClient) (cache.Store, cache.Controller)

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