util

package
v0.3.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// PolicyClaimLabel will set in kubernetes resource, indicates that
	// the resource is occupied by propagationPolicy
	PolicyClaimLabel = "karmada.io/driven-by"
	// OwnerLabel will set in karmada CRDs, indicates that who created it.
	// We can use labelSelector to find who created it quickly.
	// example1: set it in propagationBinding, the label value is propagationPolicy.
	// example2: set it in propagationWork, the label value is propagationBinding.
	// example3: set it in propagationWork, the label value is HPA.
	OwnerLabel = "karmada.io/created-by"
	// OverrideClaimKey will set in propagationwork resource, indicates that
	// the resource is overridden by override policies
	OverrideClaimKey = "karmada.io/overridden-by"

	// AppliedOverrideKey is the key of a OverridePolicy list.
	// It is used to annotates what override policies have been applied for a specific manifest.
	// The value is a comma-separated list of override policy names, the namespace is omitted.
	AppliedOverrideKey = "karmada.io/override"

	// AppliedClusterOverrideKey is the key of a ClusterOverridePolicy list.
	// it is used to annotates what cluster override policies have been applied for a specific manifest.
	// The value is a comma-separated list of cluster override policy names.
	AppliedClusterOverrideKey = "karmada.io/cluster-override"
)
View Source
const (
	// ClusterControllerFinalizer is added to Cluster to ensure PropagationWork as well as the
	// execution space (namespace) is deleted before itself is deleted.
	ClusterControllerFinalizer = "karmada.io/cluster-controller"

	// ExecutionControllerFinalizer is added to PropagationWork to ensure manifests propagated to member cluster
	// is deleted before PropagationWork 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 CreateOrUpdatePropagationWork added in v0.3.0

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

CreateOrUpdatePropagationWork creates or updates propagationWork by controllerutil.CreateOrUpdate

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 GenerateKey

func GenerateKey(obj runtime.Object) (string, error)

GenerateKey generates a key from obj, the key contains cluster, GVK, namespace and name.

func GetBindingClusterNames added in v0.3.0

func GetBindingClusterNames(binding *v1alpha1.PropagationBinding) []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 RemoveIrrelevantField added in v0.3.0

func RemoveIrrelevantField(workload *unstructured.Unstructured)

RemoveIrrelevantField will delete irrelevant field from workload. such as uid, timestamp, status

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 {
	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(reconcile ReconcileHandler, name string, interval time.Duration) 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 kubeclientset.Interface) (*ClusterClient, error)

NewClusterClientSet returns a ClusterClient for the given member cluster.

type ClusterWorkload

type ClusterWorkload struct {
	GVK       schema.GroupVersionKind
	Cluster   string
	Namespace string
	Name      string
}

ClusterWorkload is the thumbnail of cluster workload, it contains GVK, cluster, namespace and name.

func SplitMetaKey

func SplitMetaKey(key string) (ClusterWorkload, error)

SplitMetaKey transforms key to struct ClusterWorkload, struct ClusterWorkload contains cluster, GVK, namespace and name.

func (*ClusterWorkload) GetListerKey

func (w *ClusterWorkload) GetListerKey() string

GetListerKey returns the key that can be used to query full object information by GenericLister

type DynamicClusterClient

type DynamicClusterClient struct {
	DynamicClientSet dynamic.Interface
	ClusterName      string
}

DynamicClusterClient stands for a dynamic client for the given member cluster

func BuildDynamicClusterClient

func BuildDynamicClusterClient(hostClient client.Client, kubeClient kubeclientset.Interface, clusterName string) (*DynamicClusterClient, error)

BuildDynamicClusterClient builds dynamic client for informerFactory by clusterName, it will build kubeconfig from cluster resource and construct dynamic client.

func NewClusterDynamicClientSet

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

NewClusterDynamicClientSet returns a dynamic client for the given member cluster.

type ReconcileHandler

type ReconcileHandler func(key string) error

ReconcileHandler is a callback function for process resources.

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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