helper

package
v1.3.6 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2023 License: Apache-2.0 Imports: 38 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// FullyAppliedSuccessReason defines the success reason for the FullyApplied condition.
	FullyAppliedSuccessReason = "FullyAppliedSuccess"
	// FullyAppliedFailedReason defines the failure reason for the FullyApplied condition.
	FullyAppliedFailedReason = "FullyAppliedFailed"
	// FullyAppliedSuccessMessage defines the success message for the FullyApplied condition.
	FullyAppliedSuccessMessage = "All works have been successfully applied"
	// FullyAppliedFailedMessage defines the failure message for the FullyApplied condition.
	FullyAppliedFailedMessage = "Failed to apply all works, see status.aggregatedStatus for details"
)
View Source
const DenyReasonResourceSelectorsModify = "modify ResourceSelectors is forbidden"

DenyReasonResourceSelectorsModify constructs a reason indicating that modify ResourceSelectors is not allowed.

Variables

This section is empty.

Functions

func AddTolerations added in v1.3.0

func AddTolerations(placement *policyv1alpha1.Placement, tolerationsToAdd ...*corev1.Toleration)

AddTolerations add some tolerations if not existed.

func AggregateClusterResourceBindingWorkStatus added in v0.5.0

func AggregateClusterResourceBindingWorkStatus(c client.Client, binding *workv1alpha2.ClusterResourceBinding, workload *unstructured.Unstructured) error

AggregateClusterResourceBindingWorkStatus will collect all work statuses with current ClusterResourceBinding objects, then aggregate status info to current ClusterResourceBinding status.

func AggregateResourceBindingWorkStatus added in v0.5.0

func AggregateResourceBindingWorkStatus(c client.Client, binding *workv1alpha2.ResourceBinding, workload *unstructured.Unstructured) error

AggregateResourceBindingWorkStatus will collect all work statuses with current ResourceBinding objects, then aggregate status info to current ResourceBinding status.

func ApplyReplica added in v1.0.0

func ApplyReplica(workload *unstructured.Unstructured, desireReplica int64, field string) error

ApplyReplica applies the Replica value for the specific field.

func BuildStatusRawExtension added in v1.1.0

func BuildStatusRawExtension(status interface{}) (*runtime.RawExtension, error)

BuildStatusRawExtension builds raw JSON by a status map.

func ConvertToTypedObject added in v1.3.0

func ConvertToTypedObject(in, out interface{}) error

ConvertToTypedObject converts an unstructured object to typed.

func CreateOrUpdateEndpointSlice added in v0.7.0

func CreateOrUpdateEndpointSlice(client client.Client, endpointSlice *discoveryv1.EndpointSlice) error

CreateOrUpdateEndpointSlice creates a EndpointSlice object if not exist, or updates if it already exist.

func CreateOrUpdateWork added in v0.7.0

func CreateOrUpdateWork(client client.Client, workMeta metav1.ObjectMeta, resource *unstructured.Unstructured) error

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

func DeleteEndpointSlice added in v0.7.0

func DeleteEndpointSlice(c client.Client, selector labels.Set) error

DeleteEndpointSlice will delete all EndpointSlice objects by labels.

func DeleteWorkByCRBName added in v0.10.0

func DeleteWorkByCRBName(c client.Client, name string) error

DeleteWorkByCRBName will delete all Work objects by ClusterResourceBinding name.

func DeleteWorkByRBNamespaceAndName added in v0.10.0

func DeleteWorkByRBNamespaceAndName(c client.Client, namespace, name string) error

DeleteWorkByRBNamespaceAndName will delete all Work objects by ResourceBinding namespace and name.

func DeleteWorks added in v0.7.0

func DeleteWorks(c client.Client, namespace, name string) error

DeleteWorks will delete all Work objects by labels.

func FetchWorkload

func FetchWorkload(dynamicClient dynamic.Interface, informerManager genericmanager.SingleClusterInformerManager,
	restMapper meta.RESTMapper, resource workv1alpha2.ObjectReference) (*unstructured.Unstructured, error)

FetchWorkload fetches the kubernetes resource to be propagated.

func FindOrphanWorks

func FindOrphanWorks(c client.Client, bindingNamespace, bindingName string, expectClusters sets.String) ([]workv1alpha1.Work, error)

FindOrphanWorks retrieves all works that labeled with current binding(ResourceBinding or ClusterResourceBinding) objects, then pick the works that not meet current binding declaration.

func GenEventRef added in v1.3.0

func GenEventRef(resource *unstructured.Unstructured) (*corev1.ObjectReference, error)

GenEventRef returns the event reference. sets the UID(.spec.uid) that might be missing for fire events. Do nothing if the UID already exist, otherwise set the UID from annotation.

func GenMergePatch added in v1.3.0

func GenMergePatch(originalObj interface{}, modifiedObj interface{}) (patchBytes []byte, err error)

GenMergePatch will return a merge patch document capable of converting the original object to the modified object. The merge patch format is primarily intended for use with the HTTP PATCH method as a means of describing a set of modifications to a target resource's content.

func GenerateNodeClaimByPodSpec added in v0.9.0

func GenerateNodeClaimByPodSpec(podSpec *corev1.PodSpec) *workv1alpha2.NodeClaim

GenerateNodeClaimByPodSpec will return a NodeClaim from PodSpec.

func GenerateReplicaRequirements added in v0.10.0

func GenerateReplicaRequirements(podTemplate *corev1.PodTemplateSpec) *workv1alpha2.ReplicaRequirements

GenerateReplicaRequirements generates replica requirements for node and resources.

func GenerateResourceSelectorForServiceImport added in v0.7.0

func GenerateResourceSelectorForServiceImport(svcImport policyv1alpha1.ResourceSelector) []policyv1alpha1.ResourceSelector

GenerateResourceSelectorForServiceImport generates resource selectors for ServiceImport.

func GetAppliedPlacement added in v1.3.0

func GetAppliedPlacement(annotations map[string]string) (*policyv1alpha1.Placement, error)

GetAppliedPlacement will get applied placement from annotations.

func GetClusterResourceBindings added in v0.6.0

func GetClusterResourceBindings(c client.Client, ls labels.Set) (*workv1alpha2.ClusterResourceBindingList, error)

GetClusterResourceBindings returns a ClusterResourceBindingList by labels.

func GetEndpointSlices added in v0.7.0

func GetEndpointSlices(c client.Client, ls labels.Set) (*discoveryv1.EndpointSliceList, error)

GetEndpointSlices returns a EndpointSliceList by labels

func GetFollowedResourceSelectorsWhenMatchServiceImport added in v0.7.0

func GetFollowedResourceSelectorsWhenMatchServiceImport(resourceSelectors []policyv1alpha1.ResourceSelector) []policyv1alpha1.ResourceSelector

GetFollowedResourceSelectorsWhenMatchServiceImport get followed derived-service and endpointSlices resource selectors when policy's ResourceSelectors contains ResourceSelector, whose kind is ServiceImport.

func GetJobFinishedStatus added in v1.0.4

func GetJobFinishedStatus(jobStatus *batchv1.JobStatus) (bool, batchv1.JobConditionType)

GetJobFinishedStatus checks whether the given Job has finished execution. It does not discriminate between successful and failed terminations.

func GetManifestIndex added in v0.5.0

func GetManifestIndex(manifests []workv1alpha1.Manifest, clusterObj *unstructured.Unstructured) (int, error)

GetManifestIndex get the index of clusterObj in manifest list, if not exist return -1.

func GetMatchingTolerations added in v1.3.0

func GetMatchingTolerations(taints []corev1.Taint, tolerations []corev1.Toleration) (bool, []corev1.Toleration)

GetMatchingTolerations returns true and list of Tolerations matching all Taints if all are tolerated, or false otherwise.

func GetMinTolerationTime added in v1.3.0

func GetMinTolerationTime(noExecuteTaints []corev1.Taint, usedTolerations []corev1.Toleration) time.Duration

GetMinTolerationTime returns minimal toleration time from the given slice, or -1 if it's infinite.

func GetNoExecuteTaints added in v1.3.0

func GetNoExecuteTaints(taints []corev1.Taint) []corev1.Taint

GetNoExecuteTaints will get all NoExecute taints.

func GetObjectFromCache added in v0.7.0

func GetObjectFromCache(
	restMapper meta.RESTMapper,
	manager genericmanager.MultiClusterInformerManager,
	fedKey keys.FederatedKey,
) (*unstructured.Unstructured, error)

GetObjectFromCache gets full object information from cache by key in worker queue.

func GetObjectFromSingleClusterCache added in v1.1.0

func GetObjectFromSingleClusterCache(restMapper meta.RESTMapper, manager genericmanager.SingleClusterInformerManager,
	cwk *keys.ClusterWideKey) (*unstructured.Unstructured, error)

GetObjectFromSingleClusterCache gets full object information from single cluster cache by key in worker queue.

func GetPodCondition added in v1.1.0

func GetPodCondition(status *corev1.PodStatus, conditionType corev1.PodConditionType) (int, *corev1.PodCondition)

GetPodCondition extracts the provided condition from the given status and returns that. Returns nil and -1 if the condition is not present, and the index of the located condition.

func GetPodConditionFromList added in v1.1.0

func GetPodConditionFromList(conditions []corev1.PodCondition, conditionType corev1.PodConditionType) (int, *corev1.PodCondition)

GetPodConditionFromList extracts the provided condition from the given list of condition and returns the index of the condition and the condition. Returns -1 and nil if the condition is not present.

func GetResourceBindings added in v0.6.0

func GetResourceBindings(c client.Client, ls labels.Set) (*workv1alpha2.ResourceBindingList, error)

GetResourceBindings returns a ResourceBindingList by labels

func GetWorksByBindingNamespaceName added in v1.3.0

func GetWorksByBindingNamespaceName(c client.Client, bindingNamespace, bindingName string) (*workv1alpha1.WorkList, error)

GetWorksByBindingNamespaceName get WorkList by matching same Namespace and same Name.

func GetWorksByLabelsSet added in v1.2.0

func GetWorksByLabelsSet(c client.Client, ls labels.Set) (*workv1alpha1.WorkList, error)

GetWorksByLabelsSet get WorkList by matching labels.Set.

func HasNoExecuteTaints added in v1.3.0

func HasNoExecuteTaints(taints []corev1.Taint) bool

HasNoExecuteTaints check if NoExecute taints exist.

func HasScheduledReplica added in v0.7.0

func HasScheduledReplica(scheduleResult []workv1alpha2.TargetCluster) bool

HasScheduledReplica checks if the scheduler has assigned replicas for a cluster.

func IsAPIEnabled added in v0.7.0

func IsAPIEnabled(APIEnablements []clusterv1alpha1.APIEnablement, groupVersion string, kind string) bool

IsAPIEnabled checks if target API (or CRD) referencing by groupVersion and kind has been installed.

func IsBindingScheduled added in v1.0.0

func IsBindingScheduled(status *workv1alpha2.ResourceBindingStatus) bool

IsBindingScheduled will check if resourceBinding/clusterResourceBinding is successfully scheduled.

func IsClusterOverridePolicyExist

func IsClusterOverridePolicyExist(c client.Client, name string) (bool, error)

IsClusterOverridePolicyExist checks if specific ClusterOverridePolicy exist.

func IsDependentClusterOverridesPresent

func IsDependentClusterOverridesPresent(c client.Client, policy *policyv1alpha1.ClusterPropagationPolicy) (bool, error)

IsDependentClusterOverridesPresent checks if a ClusterPropagationPolicy's dependent ClusterOverridePolicy all exist.

func IsDependentOverridesPresent

func IsDependentOverridesPresent(c client.Client, policy *policyv1alpha1.PropagationPolicy) (bool, error)

IsDependentOverridesPresent checks if a PropagationPolicy's dependent OverridePolicy all exist.

func IsOverridePolicyExist

func IsOverridePolicyExist(c client.Client, ns string, name string) (bool, error)

IsOverridePolicyExist checks if specific OverridePolicy exist.

func IsReplicaDynamicDivided added in v1.1.0

func IsReplicaDynamicDivided(strategy *policyv1alpha1.ReplicaSchedulingStrategy) bool

IsReplicaDynamicDivided checks if a PropagationPolicy schedules replicas as dynamic.

func IsResourceApplied added in v0.7.0

func IsResourceApplied(workStatus *workv1alpha1.WorkStatus) bool

IsResourceApplied checks whether resource has been dispatched to member cluster or not

func NewClusterPredicateOnAgent added in v0.7.0

func NewClusterPredicateOnAgent(clusterName string) predicate.Funcs

NewClusterPredicateOnAgent generates an event filter function with Cluster for karmada-agent.

func NewExecutionPredicate added in v0.7.0

func NewExecutionPredicate(mgr controllerruntime.Manager) predicate.Funcs

NewExecutionPredicate generates the event filter function to skip events that the controllers are uninterested. Used by controllers: - execution controller working in karmada-controller-manager - work status controller working in karmada-controller-manager

func NewExecutionPredicateOnAgent added in v0.7.0

func NewExecutionPredicateOnAgent() predicate.Funcs

NewExecutionPredicateOnAgent generates the event filter function to skip events that the controllers are uninterested. Used by controllers: - execution controller working in agent - work status controller working in agent

func NewNotReadyToleration added in v1.3.0

func NewNotReadyToleration(tolerationSeconds int64) *corev1.Toleration

NewNotReadyToleration returns a default not ready toleration.

func NewPredicateForServiceExportController added in v0.7.0

func NewPredicateForServiceExportController(mgr controllerruntime.Manager) predicate.Funcs

NewPredicateForServiceExportController generates an event filter function for ServiceExport controller running by karmada-controller-manager.

func NewPredicateForServiceExportControllerOnAgent added in v0.7.0

func NewPredicateForServiceExportControllerOnAgent(curClusterName string) predicate.Funcs

NewPredicateForServiceExportControllerOnAgent generates an event filter function for ServiceExport controller running by karmada-agent.

func NewUnreachableToleration added in v1.3.0

func NewUnreachableToleration(tolerationSeconds int64) *corev1.Toleration

NewUnreachableToleration returns a default unreachable toleration.

func NodeReady added in v0.10.0

func NodeReady(node *corev1.Node) bool

NodeReady checks whether the node condition is ready.

func ObtainBindingSpecExistingClusters added in v1.3.0

func ObtainBindingSpecExistingClusters(bindingSpec workv1alpha2.ResourceBindingSpec) sets.String

ObtainBindingSpecExistingClusters will obtain the cluster slice existing in the binding's spec field.

func ParsingJobStatus added in v1.0.0

func ParsingJobStatus(obj *batchv1.Job, status []workv1alpha2.AggregatedStatusItem) (*batchv1.JobStatus, error)

ParsingJobStatus generates new status of given 'AggregatedStatusItem'.

func RemoveOrphanWorks

func RemoveOrphanWorks(c client.Client, works []workv1alpha1.Work) error

RemoveOrphanWorks will remove orphan works.

func SetDefaultSpreadConstraints

func SetDefaultSpreadConstraints(spreadConstraints []policyv1alpha1.SpreadConstraint)

SetDefaultSpreadConstraints set default spread constraints if both 'SpreadByField' and 'SpreadByLabel' not set.

func TaintExists added in v1.2.0

func TaintExists(taints []corev1.Taint, taintToFind *corev1.Taint) bool

TaintExists checks if the given taint exists in list of taints. Returns true if exists false otherwise.

func ToUnstructured added in v1.0.4

func ToUnstructured(obj interface{}) (*unstructured.Unstructured, error)

ToUnstructured converts a typed object to an unstructured object.

func TolerationExists added in v1.3.0

func TolerationExists(tolerations []corev1.Toleration, tolerationToFind *corev1.Toleration) bool

TolerationExists checks if the given toleration exists in list of tolerations. Returns true if exists false otherwise.

func UpdateClusterControllerTaint added in v1.2.0

func UpdateClusterControllerTaint(ctx context.Context, client client.Client, taintsToAdd, taintsToRemove []*corev1.Taint, cluster *clusterv1alpha1.Cluster) error

UpdateClusterControllerTaint add and remove some taints.

func ValidateSpreadConstraint

func ValidateSpreadConstraint(spreadConstraints []policyv1alpha1.SpreadConstraint) error

ValidateSpreadConstraint tests if the constraints is valid.

Types

type ClusterWeightInfo added in v0.5.0

type ClusterWeightInfo struct {
	ClusterName string
	Weight      int64
}

ClusterWeightInfo records the weight of a cluster

type ClusterWeightInfoList added in v0.5.0

type ClusterWeightInfoList []ClusterWeightInfo

ClusterWeightInfoList is a slice of ClusterWeightInfo that implements sort.Interface to sort by Value.

func SortClusterByWeight added in v0.7.0

func SortClusterByWeight(m map[string]int64) ClusterWeightInfoList

SortClusterByWeight sort clusters by the weight

func (ClusterWeightInfoList) Len added in v0.5.0

func (p ClusterWeightInfoList) Len() int

func (ClusterWeightInfoList) Less added in v0.5.0

func (p ClusterWeightInfoList) Less(i, j int) bool

func (ClusterWeightInfoList) Swap added in v0.5.0

func (p ClusterWeightInfoList) Swap(i, j int)

Jump to

Keyboard shortcuts

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