util

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2021 License: Apache-2.0 Imports: 28 Imported by: 10

Documentation

Index

Constants

View Source
const (
	// PropagationPolicyNamespaceLabel is added to objects to specify associated PropagationPolicy namespace.
	PropagationPolicyNamespaceLabel = "propagationpolicy.karmada.io/namespace"

	// PropagationPolicyNameLabel is added to objects to specify associated PropagationPolicy's name.
	PropagationPolicyNameLabel = "propagationpolicy.karmada.io/name"

	// ClusterPropagationPolicyLabel is added to objects to specify associated ClusterPropagationPolicy.
	ClusterPropagationPolicyLabel = "clusterpropagationpolicy.karmada.io/name"

	// ResourceBindingNamespaceLabel is added to objects to specify associated ResourceBinding's namespace.
	ResourceBindingNamespaceLabel = "resourcebinding.karmada.io/namespace"

	// ResourceBindingNameLabel is added to objects to specify associated ResourceBinding's name.
	ResourceBindingNameLabel = "resourcebinding.karmada.io/name"

	// ClusterResourceBindingLabel is added to objects to specify associated ClusterResourceBinding.
	ClusterResourceBindingLabel = "clusterresourcebinding.karmada.io/name"

	// WorkNamespaceLabel is added to objects to specify associated Work's namespace.
	WorkNamespaceLabel = "work.karmada.io/namespace"

	// WorkNameLabel is added to objects to specify associated Work's name.
	WorkNameLabel = "work.karmada.io/name"
)
View Source
const (
	// PolicyPlacementAnnotation is the annotation of a policy's placement.
	// It is intended to set on ResourceBinding or ClusterResourceBinding objects to record applied placement declaration.
	// The placement could be either PropagationPolicy's or ClusterPropagationPolicy's.
	PolicyPlacementAnnotation = "policy.karmada.io/applied-placement"

	// AppliedOverrides is the annotation which used to record override items an object applied.
	// It is intended to set on Work objects to record applied overrides.
	// The overrides items should be sorted alphabetically in ascending order by OverridePolicy's name.
	AppliedOverrides = "policy.karmada.io/applied-overrides"

	// AppliedClusterOverrides is the annotation which used to record override items an object applied.
	// It is intended to set on Work objects to record applied overrides.
	// The overrides items should be sorted alphabetically in ascending order by ClusterOverridePolicy's name.
	AppliedClusterOverrides = "policy.karmada.io/applied-cluster-overrides"
)

Define annotations used by karmada system.

View Source
const (
	// ClusterControllerFinalizer is added to Cluster to ensure Work as well as the
	// execution space (namespace) is deleted before itself is deleted.
	ClusterControllerFinalizer = "karmada.io/cluster-controller"

	// ExecutionControllerFinalizer is added to Work to ensure manifests propagated to member cluster
	// is deleted before Work itself is deleted.
	ExecutionControllerFinalizer = "karmada.io/execution-controller"
)

Define finalizers used by karmada system.

Variables

This section is empty.

Functions

func ClusterMatches added in v0.3.0

func ClusterMatches(cluster *clusterv1alpha1.Cluster, affinity v1alpha1.ClusterAffinity) bool

ClusterMatches tells if specific cluster matches the affinity. TODO(RainbowMango): Now support ClusterAffinity.ClusterNames, ClusterAffinity.ExcludeClusters and ClusterAffinity.LabelSelector. More rules will be implemented later.

func ClusterNamesMatches added in v0.3.0

func ClusterNamesMatches(cluster *clusterv1alpha1.Cluster, clusterNames []string) bool

ClusterNamesMatches tells if specific cluster matches the clusterNames affinity.

func CreateClusterRole

func CreateClusterRole(client kubeclient.Interface, clusterRoleObj *rbacv1.ClusterRole) (*rbacv1.ClusterRole, error)

CreateClusterRole just try to create the ClusterRole.

func CreateClusterRoleBinding

func CreateClusterRoleBinding(client kubeclient.Interface, clusterRoleBindingObj *rbacv1.ClusterRoleBinding) (*rbacv1.ClusterRoleBinding, error)

CreateClusterRoleBinding just try to create the ClusterRoleBinding.

func CreateNamespace

func CreateNamespace(client kubeclient.Interface, namespaceObj *corev1.Namespace) (*corev1.Namespace, error)

CreateNamespace just try to create the namespace.

func CreateOrUpdateWork added in v0.4.0

func CreateOrUpdateWork(client client.Client, objectMeta metav1.ObjectMeta, rawExtension []byte) error

CreateOrUpdateWork creates a Work object if not exist, or updates if it already exist.

func CreateSecret

func CreateSecret(client kubeclient.Interface, secret *corev1.Secret) (*corev1.Secret, error)

CreateSecret just try to create the secret.

func CreateServiceAccount

func CreateServiceAccount(client kubeclient.Interface, saObj *corev1.ServiceAccount) (*corev1.ServiceAccount, error)

CreateServiceAccount just try to create the ServiceAccount.

func DeleteClusterRole

func DeleteClusterRole(client kubeclient.Interface, name string) error

DeleteClusterRole just try to delete the ClusterRole.

func DeleteClusterRoleBinding

func DeleteClusterRoleBinding(client kubeclient.Interface, name string) error

DeleteClusterRoleBinding just try to delete the ClusterRoleBinding.

func DeleteNamespace

func DeleteNamespace(client kubeclient.Interface, namespace string) error

DeleteNamespace just try to delete the namespace.

func DeleteSecret

func DeleteSecret(client kubeclient.Interface, namespace, name string) error

DeleteSecret just try to delete the secret.

func DeleteServiceAccount

func DeleteServiceAccount(client kubeclient.Interface, namespace, name string) error

DeleteServiceAccount just try to delete the ServiceAccount.

func GetBindingClusterNames added in v0.3.0

func GetBindingClusterNames(binding *workv1alpha1.ResourceBinding) []string

GetBindingClusterNames will get clusterName list from bind clusters field

func GetCluster added in v0.3.0

func GetCluster(hostClient client.Client, clusterName string) (*v1alpha1.Cluster, error)

GetCluster returns the given Cluster resource

func GetLabelValue

func GetLabelValue(labels map[string]string, labelKey string) string

GetLabelValue retrieves the value via 'labelKey' if exist, otherwise returns an empty string.

func GetTargetSecret

func GetTargetSecret(client kubeclient.Interface, secretReferences []corev1.ObjectReference, targetType corev1.SecretType, targetNamespace string) (*corev1.Secret, error)

GetTargetSecret will get secrets(type=targetType, namespace=targetNamespace) from a list of secret references.

func IsClusterReady added in v0.3.0

func IsClusterReady(clusterStatus *v1alpha1.ClusterStatus) bool

IsClusterReady tells whether the cluster status in 'Ready' condition.

func IsClusterRoleBindingExist

func IsClusterRoleBindingExist(client kubeclient.Interface, name string) (bool, error)

IsClusterRoleBindingExist tells if specific ClusterRole already exists.

func IsClusterRoleExist

func IsClusterRoleExist(client kubeclient.Interface, name string) (bool, error)

IsClusterRoleExist tells if specific ClusterRole already exists.

func IsNamespaceExist

func IsNamespaceExist(client kubeclient.Interface, namespace string) (bool, error)

IsNamespaceExist tells if specific already exists.

func IsServiceAccountExist

func IsServiceAccountExist(client kubeclient.Interface, namespace string, name string) (bool, error)

IsServiceAccountExist tells if specific service account already exists.

func MergeAnnotation added in v0.3.0

func MergeAnnotation(obj *unstructured.Unstructured, annotationKey string, annotationValue string)

MergeAnnotation adds annotation for the given object.

func MergeLabel

func MergeLabel(obj *unstructured.Unstructured, labelKey string, labelValue string)

MergeLabel adds label for the given object.

func PatchSecret

func PatchSecret(client kubeclient.Interface, namespace, name string, pt types.PatchType, patchSecretBody *corev1.Secret) error

PatchSecret just try to patch the secret.

func ResourceMatchSelectors added in v0.5.0

func ResourceMatchSelectors(resource *unstructured.Unstructured, selectors ...v1alpha1.ResourceSelector) bool

ResourceMatchSelectors tells if the specific resource matches the selectors.

func ResourceMatches added in v0.3.0

func ResourceMatches(resource *unstructured.Unstructured, rs v1alpha1.ResourceSelector) bool

ResourceMatches tells if the specific resource matches the selector.

Types

type AsyncWorker

type AsyncWorker interface {
	// AddRateLimited adds item to queue.
	AddRateLimited(item interface{})
	// EnqueueRateLimited generates the key for objects then adds the key as an item to queue.
	EnqueueRateLimited(obj runtime.Object)
	Run(workerNumber int, stopChan <-chan struct{})
}

AsyncWorker is a worker to process resources periodic with a rateLimitingQueue.

func NewAsyncWorker

func NewAsyncWorker(name string, interval time.Duration, keyFunc KeyFunc, reconcileFunc ReconcileFunc) AsyncWorker

NewAsyncWorker returns a asyncWorker which can process resource periodic.

type ClusterClient

type ClusterClient struct {
	KubeClient  *kubeclientset.Clientset
	ClusterName string
}

ClusterClient stands for a cluster Clientset for the given member cluster

func NewClusterClientSet

func NewClusterClientSet(c *v1alpha1.Cluster, client client.Client) (*ClusterClient, error)

NewClusterClientSet returns a ClusterClient for the given member cluster.

func NewClusterClientSetForAgent added in v0.5.0

func NewClusterClientSetForAgent(c *v1alpha1.Cluster, client client.Client) (*ClusterClient, error)

NewClusterClientSetForAgent returns a ClusterClient for the given member cluster which will be used in karmada agent.

type DynamicClusterClient

type DynamicClusterClient struct {
	DynamicClientSet dynamic.Interface
	ClusterName      string
}

DynamicClusterClient stands for a dynamic client for the given member cluster

func NewClusterDynamicClientSet

func NewClusterDynamicClientSet(c *v1alpha1.Cluster, client client.Client) (*DynamicClusterClient, error)

NewClusterDynamicClientSet returns a dynamic client for the given member cluster.

func NewClusterDynamicClientSetForAgent added in v0.5.0

func NewClusterDynamicClientSetForAgent(c *v1alpha1.Cluster, client client.Client) (*DynamicClusterClient, error)

NewClusterDynamicClientSetForAgent returns a dynamic client for the given member cluster which will be used in karmada agent.

type KeyFunc added in v0.4.0

type KeyFunc func(obj interface{}) (QueueKey, error)

KeyFunc knows how to make a key from an object. Implementations should be deterministic.

type QueueKey added in v0.4.0

type QueueKey interface{}

QueueKey is the item key that stores in queue. The key could be arbitrary types.

In some cases, people would like store different resources in a same queue, the traditional full-qualified key, such as '<namespace>/<name>', can't distinguish which resource the key belongs to, the key might carry more information of a resource, such as GVK(Group Version Kind), in that cases people need to use self-defined key, e.g. a struct.

func GenerateKey

func GenerateKey(obj interface{}) (QueueKey, error)

GenerateKey generates a key from obj, the key contains cluster, GVK, namespace and name. TODO(RainbowMango): Move this function out of this file, to it's user.

type ReconcileFunc added in v0.4.0

type ReconcileFunc func(key QueueKey) error

ReconcileFunc knows how to consume items(key) from the queue.

type SpreadGroup added in v0.3.0

type SpreadGroup struct {
	// The outer map's keys are SpreadConstraint. The values (inner map) of the outer map are maps with string
	// keys and []string values. The inner map's key should specify the cluster group name.
	GroupRecord map[v1alpha1.SpreadConstraint]map[string][]string
	sync.RWMutex
}

SpreadGroup stores the cluster group info for given spread constraints

func NewSpreadGroup added in v0.3.0

func NewSpreadGroup() *SpreadGroup

NewSpreadGroup initializes a SpreadGroup

func (*SpreadGroup) InitialGroupRecord added in v0.3.0

func (ss *SpreadGroup) InitialGroupRecord(constraint v1alpha1.SpreadConstraint)

InitialGroupRecord initials a spread state record

Jump to

Keyboard shortcuts

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