util

package
v1.4.8-beta.0 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2016 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

TODO: consider moving it to a more generic package.

Index

Constants

View Source
const (
	KubeAPIQPS              = 20.0
	KubeAPIBurst            = 30
	KubeconfigSecretDataKey = "kubeconfig"
)
View Source
const (
	OperationTypeAdd    = "add"
	OperationTypeUpdate = "update"
	OperationTypeDelete = "delete"
)

Variables

View Source
var KubeconfigGetterForCluster = func(c *federation_v1beta1.Cluster) clientcmd.KubeconfigGetter {
	return func() (*clientcmdapi.Config, error) {
		secretRefName := ""
		if c.Spec.SecretRef != nil {
			secretRefName = c.Spec.SecretRef.Name
		} else {
			glog.Infof("didnt find secretRef for cluster %s. Trying insecure access", c.Name)
		}
		return KubeconfigGetterForSecret(secretRefName)()
	}
}

This is to inject a different kubeconfigGetter in tests. We dont use the standard one which calls NewInCluster in tests to avoid having to setup service accounts and mount files with secret tokens.

View Source
var KubeconfigGetterForSecret = func(secretName string) clientcmd.KubeconfigGetter {
	return func() (*clientcmdapi.Config, error) {
		var data []byte
		if secretName != "" {

			namespace := os.Getenv("POD_NAMESPACE")
			if namespace == "" {
				return nil, fmt.Errorf("unexpected: POD_NAMESPACE env var returned empty string")
			}

			client, err := client.NewInCluster()
			if err != nil {
				return nil, fmt.Errorf("error in creating in-cluster client: %s", err)
			}
			data = []byte{}
			var secret *api.Secret
			err = wait.PollImmediate(1*time.Second, getSecretTimeout, func() (bool, error) {
				secret, err = client.Secrets(namespace).Get(secretName)
				if err == nil {
					return true, nil
				}
				glog.Warningf("error in fetching secret: %s", err)
				return false, nil
			})
			if err != nil {
				return nil, fmt.Errorf("timed out waiting for secret: %s", err)
			}
			if secret == nil {
				return nil, fmt.Errorf("unexpected: received null secret %s", secretName)
			}
			ok := false
			data, ok = secret.Data[KubeconfigSecretDataKey]
			if !ok {
				return nil, fmt.Errorf("secret does not have data with key: %s", KubeconfigSecretDataKey)
			}
		}
		return clientcmd.Load(data)
	}
}

KubeconfigGettterForSecret is used to get the kubeconfig from the given secret.

Functions

func BuildClusterConfig

func BuildClusterConfig(c *federation_v1beta1.Cluster) (*restclient.Config, error)

func CopyObjectMeta added in v1.4.0

func CopyObjectMeta(obj api_v1.ObjectMeta) api_v1.ObjectMeta

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 DeepCopyObjectMeta added in v1.4.0

func DeepCopyObjectMeta(obj api_v1.ObjectMeta) api_v1.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 GetClientsetForCluster added in v1.4.0

func GetClientsetForCluster(cluster *federation_v1beta1.Cluster) (*federation_release_1_4.Clientset, error)

Retruns Clientset for the given cluster.

func NewTriggerOnAllChanges added in v1.4.0

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

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

func NewTriggerOnMetaAndSpecChanges added in v1.4.0

func NewTriggerOnMetaAndSpecChanges(triggerFunc func(pkg_runtime.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 ObjectMetaEquivalent added in v1.4.0

func ObjectMetaEquivalent(a, b api_v1.ObjectMeta) bool

Checks if cluster-independed, user provided data in two given ObjectMeta are eqaul. 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 SecretEquivalent added in v1.4.0

func SecretEquivalent(s1, s2 api_v1.Secret) bool

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

Types

type ClusterLifecycleHandlerFuncs added in v1.4.0

type ClusterLifecycleHandlerFuncs struct {
	// Fired when the cluster becomes available.
	ClusterAvailable func(*federation_api.Cluster)
	// Fired when the cluster becomes unavailable. The second arg contains data that was present
	// in the cluster before deletion.
	ClusterUnavailable func(*federation_api.Cluster, []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 DelayingDeliverer added in v1.4.0

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

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

func NewDelayingDeliverer added in v1.4.0

func NewDelayingDeliverer() *DelayingDeliverer

func NewDelayingDelivererWithChannel added in v1.4.0

func NewDelayingDelivererWithChannel(targetChannel chan *DelayingDelivererItem) *DelayingDeliverer

func (*DelayingDeliverer) DeliverAfter added in v1.4.0

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

Delivers value after the given delay.

func (*DelayingDeliverer) DeliverAt added in v1.4.0

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

Delivers value at the given time.

func (*DelayingDeliverer) GetTargetChannel added in v1.4.0

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

Gets target channel of the deliverer.

func (*DelayingDeliverer) Start added in v1.4.0

func (d *DelayingDeliverer) Start()

Starts the DelayingDeliverer.

func (*DelayingDeliverer) StartWithHandler added in v1.4.0

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

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

func (*DelayingDeliverer) Stop added in v1.4.0

func (d *DelayingDeliverer) Stop()

Stops the DelayingDeliverer. Undelivered items are discarded.

type DelayingDelivererItem added in v1.4.0

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 added in v1.4.0

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 added in v1.4.0

func NewFederatedInformer(
	federationClient federation_release_1_4.Interface,
	targetInformerFactory TargetInformerFactory,
	clusterLifecycle *ClusterLifecycleHandlerFuncs) FederatedInformer

Builds a FederatedInformer for the given federation client and factory.

type FederatedInformerForTestOnly added in v1.4.0

type FederatedInformerForTestOnly interface {
	FederatedInformer

	SetClientFactory(func(*federation_api.Cluster) (kube_release_1_4.Interface, error))
}

FederatedInformer with extra method for setting fake clients.

type FederatedObject added in v1.4.0

type FederatedObject struct {
	Object      interface{}
	ClusterName string
}

An object with an origin information.

type FederatedOperation added in v1.4.0

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

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

type FederatedOperationHandler added in v1.4.0

type FederatedOperationHandler func(kube_release_1_4.Interface, pkg_runtime.Object) error

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

type FederatedOperationType added in v1.4.0

type FederatedOperationType string

Type of the operation that can be executed in Federated.

type FederatedReadOnlyStore added in v1.4.0

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

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

	// 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 []*federation_api.Cluster) bool
}

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

type FederatedUpdater added in v1.4.0

type FederatedUpdater interface {
	// Executes the given set of operations within the specified timeout.
	// Timeout is best-effort. There is no guarantee that the underlying operations are
	// stopped when it is reached. However the function will return after the timeout
	// with a non-nil error.
	Update([]FederatedOperation, time.Duration) error

	UpdateWithOnError([]FederatedOperation, time.Duration, func(FederatedOperation, error)) error
}

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

func NewFederatedUpdater added in v1.4.0

func NewFederatedUpdater(federation FederationView, add, update, del FederatedOperationHandler) FederatedUpdater

type FederationView added in v1.4.0

type FederationView interface {
	// GetClientsetForCluster returns a clientset for the cluster, if present.
	GetClientsetForCluster(clusterName string) (kube_release_1_4.Interface, error)

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

	// GetReadyCluster returns the cluster with the given name, if found.
	GetReadyCluster(name string) (*federation_api.Cluster, 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 TargetInformerFactory added in v1.4.0

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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