Documentation ¶
Overview ¶
TODO: consider moving it to a more generic package.
Index ¶
- Constants
- Variables
- func BuildClusterConfig(c *federation_v1beta1.Cluster) (*restclient.Config, error)
- func CopyObjectMeta(obj api_v1.ObjectMeta) api_v1.ObjectMeta
- func DeepCopyObjectMeta(obj api_v1.ObjectMeta) api_v1.ObjectMeta
- func GetClientsetForCluster(cluster *federation_v1beta1.Cluster) (*fedclientset.Clientset, error)
- func NewTriggerOnAllChanges(triggerFunc func(pkg_runtime.Object)) *cache.ResourceEventHandlerFuncs
- func NewTriggerOnMetaAndSpecChanges(triggerFunc func(pkg_runtime.Object)) *cache.ResourceEventHandlerFuncs
- func ObjectMetaEquivalent(a, b api_v1.ObjectMeta) bool
- func SecretEquivalent(s1, s2 api_v1.Secret) bool
- func VersionizeV1ListOptions(in api.ListOptions) (out v1.ListOptions)
- type ClusterLifecycleHandlerFuncs
- type DelayingDeliverer
- func (d *DelayingDeliverer) DeliverAfter(key string, value interface{}, delay time.Duration)
- func (d *DelayingDeliverer) DeliverAt(key string, value interface{}, deliveryTime time.Time)
- func (d *DelayingDeliverer) GetTargetChannel() chan *DelayingDelivererItem
- func (d *DelayingDeliverer) Start()
- func (d *DelayingDeliverer) StartWithHandler(handler func(*DelayingDelivererItem))
- func (d *DelayingDeliverer) Stop()
- type DelayingDelivererItem
- type FederatedInformer
- type FederatedInformerForTestOnly
- type FederatedObject
- type FederatedOperation
- type FederatedOperationHandler
- type FederatedOperationType
- type FederatedReadOnlyStore
- type FederatedUpdater
- type FederationView
- type TargetInformerFactory
Constants ¶
const ( KubeAPIQPS = 20.0 KubeAPIBurst = 30 KubeconfigSecretDataKey = "kubeconfig" )
const ( OperationTypeAdd = "add" OperationTypeUpdate = "update" OperationTypeDelete = "delete" )
Variables ¶
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("didn't find secretRef for cluster %s. Trying insecure access", c.Name) } return KubeconfigGetterForSecret(secretRefName)() } }
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 setup service accounts and mount files with secret tokens.
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 ¶
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 ¶
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 ¶
func GetClientsetForCluster(cluster *federation_v1beta1.Cluster) (*fedclientset.Clientset, error)
Retruns Clientset for the given cluster.
func NewTriggerOnAllChanges ¶
func NewTriggerOnAllChanges(triggerFunc func(pkg_runtime.Object)) *cache.ResourceEventHandlerFuncs
Returns cache.ResourceEventHandlerFuncs that trigger the given function on all object changes.
func NewTriggerOnMetaAndSpecChanges ¶
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 ¶
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 ¶
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.
func VersionizeV1ListOptions ¶
func VersionizeV1ListOptions(in api.ListOptions) (out v1.ListOptions)
TODO: remove this when Reflector takes an interface rather than a particular ListOptions as input parameter.
Types ¶
type ClusterLifecycleHandlerFuncs ¶
type ClusterLifecycleHandlerFuncs struct { // Fired when the cluster becomes available. ClusterAvailable func(*federation_api.Cluster) // 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 ¶
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) 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( federationClient federationclientset.Interface, targetInformerFactory TargetInformerFactory, clusterLifecycle *ClusterLifecycleHandlerFuncs) FederatedInformer
Builds a FederatedInformer for the given federation client and factory.
type FederatedInformerForTestOnly ¶
type FederatedInformerForTestOnly interface { FederatedInformer SetClientFactory(func(*federation_api.Cluster) (kubeclientset.Interface, 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 pkg_runtime.Object }
FederatedOperation definition contains type (add/update/delete) and the object itself.
type FederatedOperationHandler ¶
type FederatedOperationHandler func(kubeclientset.Interface, pkg_runtime.Object) 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) // 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 ¶
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 ¶
func NewFederatedUpdater(federation FederationView, add, update, del FederatedOperationHandler) FederatedUpdater
type FederationView ¶
type FederationView interface { // GetClientsetForCluster returns a clientset for the cluster, if present. GetClientsetForCluster(clusterName string) (kubeclientset.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 ¶
type TargetInformerFactory func(*federation_api.Cluster, kubeclientset.Interface) (cache.Store, cache.ControllerInterface)
A function that should be used to create an informer on the target object. Store should use cache.DeletionHandlingMetaNamespaceKeyFunc as a keying function.