util

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2018 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Overview

TODO: consider moving it to a more generic package.

Index

Constants

View Source
const (
	DefaultFederationSystemNamespace = "federation-system"
	MulticlusterPublicNamespace      = "kube-multicluster-public"
	DefaultClusterAvailableDelay     = 20 * time.Second
	DefaultClusterUnavailableDelay   = 60 * time.Second

	KubeAPIQPS              = 20.0
	KubeAPIBurst            = 30
	KubeconfigSecretDataKey = "kubeconfig"
)
View Source
const (
	NoResyncPeriod time.Duration = 0 * time.Second

	NamespaceKind     = "Namespace"
	ServiceKind       = "Service"
	ClusterNameField  = "clusterName"
	ClusterNamesField = "clusterNames"
)

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

View Source
const (
	OperationTypeAdd    = "add"
	OperationTypeUpdate = "update"
	OperationTypeDelete = "delete"
)

Variables

View Source
var KubeconfigGetterForSecret = func(secret *apiv1.Secret) clientcmd.KubeconfigGetter {
	return func() (*clientcmdapi.Config, error) {
		data, ok := secret.Data[KubeconfigSecretDataKey]
		if !ok {
			return nil, fmt.Errorf("secret does not have data with key %s", KubeconfigSecretDataKey)
		}
		return clientcmd.Load(data)
	}
}

KubeconfigGetterForSecret gets the kubeconfig from the given secret. This is to inject a different KubeconfigGetter in tests. We don't use the standard one which calls NewInCluster in tests to avoid having to set up service accounts and mount files with secret tokens.

Functions

func BuildClusterConfig

func BuildClusterConfig(fedCluster *fedv1a1.FederatedCluster, kubeClient kubeclientset.Interface, crClient crclientset.Interface, fedNamespace string, clusterNamespace string) (*restclient.Config, error)

BuildClusterConfig returns a restclient.Config that can be used to configure a client for the given FederatedCluster or an error. The kubernetes and cluster-registry clients are used to access kubernetes secrets in the federation namespace and cluster-registry records in the clusterNamespace, respectively.

func ConfigMapEquivalent

func ConfigMapEquivalent(s1, s2 *api_v1.ConfigMap) bool

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

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(placement *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 IsClusterReady added in v0.0.2

func IsClusterReady(cluster *fedv1a1.FederatedCluster) 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 NewResourceInformer

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

func NewTriggerOnAllChanges

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

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

func NewTriggerOnMetaAndFieldChanges

func NewTriggerOnMetaAndFieldChanges(field string, triggerFunc func(pkgruntime.Object)) *cache.ResourceEventHandlerFuncs

Returns cache.ResourceEventHandlerFuncs that trigger the given function on object add/delete or ObjectMeta or given field is updated.

func NewTriggerOnMetaAndSpecChanges

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

Returns cache.ResourceEventHandlerFuncs that trigger the given function on object add and delete as well as spec/object meta on update.

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 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 SecretEquivalent

func SecretEquivalent(s1, s2 api_v1.Secret) bool

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

func SetClusterNames

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

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{})

Types

type ClusterLifecycleHandlerFuncs

type ClusterLifecycleHandlerFuncs struct {
	// Fired when the cluster becomes available.
	ClusterAvailable func(*fedv1a1.FederatedCluster)
	// Fired when the cluster becomes unavailable. The second arg contains data that was present
	// in the cluster before deletion.
	ClusterUnavailable func(*fedv1a1.FederatedCluster, []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
	FieldValue interface{}
}

type ClusterOverrides added in v0.0.2

type ClusterOverrides map[string][]ClusterOverride

func GetClusterOverrides added in v0.0.3

func GetClusterOverrides(typeConfig typeconfig.Interface, override *unstructured.Unstructured) (ClusterOverrides, error)

type ComparisonHelper

type ComparisonHelper interface {
	GetVersion(objectMeta metav1.Object) string
	Equivalent(objMeta1, objectMeta2 metav1.Object) bool
}

func NewComparisonHelper

func NewComparisonHelper(comparisonField common.VersionComparisonField) (ComparisonHelper, error)

NewComparisonHelper instantiates and returns a Resource or Generation Helper struct that implements the ComparisonHelper interface based on the version comparison type passed in.

type ControllerConfig added in v0.0.3

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

ControllerConfig defines the configuration common to federation controllers.

func (*ControllerConfig) AllClients added in v0.0.3

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(

	fedClient fedclientset.Interface,
	kubeClient kubeclientset.Interface,
	crClient crclientset.Interface,
	namespaces FederationNamespaces,
	apiResource *metav1.APIResource,
	triggerFunc func(pkgruntime.Object),
	clusterLifecycle *ClusterLifecycleHandlerFuncs) FederatedInformer

Builds a FederatedInformer for the given federation client and factory.

type FederatedInformerForTestOnly

type FederatedInformerForTestOnly interface {
	FederatedInformer

	SetClientFactory(func(*fedv1a1.FederatedCluster) (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 FederatedOperation

type FederatedOperation struct {
	Type        FederatedOperationType
	ClusterName string
	Obj         pkgruntime.Object
	Key         string
}

FederatedOperation definition contains type (add/update/delete) and the object itself.

type FederatedOperationHandler

type FederatedOperationHandler func(ResourceClient, pkgruntime.Object) (string, error)

A function that executes some operation using the passed client and object.

type FederatedOperationType

type FederatedOperationType string

Type of the operation that can be executed in Federated.

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 []*fedv1a1.FederatedCluster) 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 FederatedUpdater

type FederatedUpdater interface {
	// Executes the given set of operations.
	Update([]FederatedOperation) (map[string]string, []error)
}

A helper that executes the given set of updates on federation, in parallel.

func NewFederatedUpdater

func NewFederatedUpdater(federation FederationView, kind string, timeout time.Duration, recorder record.EventRecorder, add, update, del FederatedOperationHandler) FederatedUpdater

type FederationNamespaces added in v0.0.3

type FederationNamespaces struct {
	FederationNamespace string
	ClusterNamespace    string
	TargetNamespace     string
}

FederationNamespaces defines the namespace configuration shared by most federation controllers.

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() ([]*fedv1a1.FederatedCluster, error)

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

	// GetReadyCluster returns the cluster with the given name, if found.
	GetReadyCluster(name string) (*fedv1a1.FederatedCluster, 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 GenerationHelper

type GenerationHelper struct{}

func (GenerationHelper) Equivalent

func (GenerationHelper) Equivalent(obj1Meta, obj2Meta metav1.Object) bool

Equivalent returns true if both object metas passed in are equivalent, false otherwise.

func (GenerationHelper) GetVersion

func (GenerationHelper) GetVersion(objectMeta metav1.Object) string

GetVersion returns a string containing the version in the resource's ObjectMeta using the resource comparison type to perform for that resource.

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
}

func NewResourceClient

func NewResourceClient(pool dynamic.ClientPool, apiResource *metav1.APIResource) (ResourceClient, error)

func NewResourceClientFromConfig

func NewResourceClientFromConfig(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 ResourceHelper

type ResourceHelper struct{}

func (ResourceHelper) Equivalent

func (ResourceHelper) Equivalent(obj1Meta, obj2Meta metav1.Object) bool

Equivalent returns true for ResourceVersion comparison as it doesn't require comparing ObjectMeta.

func (ResourceHelper) GetVersion

func (ResourceHelper) GetVersion(objectMeta metav1.Object) string

GetVersion returns a string containing the version in the resource's ObjectMeta using the resource comparison type to perform for that resource.

type TargetInformerFactory

type TargetInformerFactory func(*fedv1a1.FederatedCluster, 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
Package to help federation controllers to delete federated resources from underlying clusters when the resource is deleted from federation control plane.
Package to help federation controllers to delete federated resources from underlying clusters when the resource is deleted from federation control plane.
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