helper

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2022 License: Apache-2.0 Imports: 39 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 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 map[string]interface{}) (*runtime.RawExtension, error)

BuildStatusRawExtension builds raw JSON by a status map.

func ConvertToClusterPropagationPolicy added in v0.8.0

func ConvertToClusterPropagationPolicy(obj *unstructured.Unstructured) (*policyv1alpha1.ClusterPropagationPolicy, error)

ConvertToClusterPropagationPolicy converts a ClusterPropagationPolicy object from unstructured to typed.

func ConvertToDaemonSet added in v0.9.0

func ConvertToDaemonSet(obj *unstructured.Unstructured) (*appsv1.DaemonSet, error)

ConvertToDaemonSet converts a DaemonSet object from unstructured to typed.

func ConvertToDeployment added in v0.9.0

func ConvertToDeployment(obj *unstructured.Unstructured) (*appsv1.Deployment, error)

ConvertToDeployment converts a Deployment object from unstructured to typed.

func ConvertToEndpointSlice added in v0.9.0

func ConvertToEndpointSlice(obj *unstructured.Unstructured) (*discoveryv1.EndpointSlice, error)

ConvertToEndpointSlice converts a EndpointSlice object from unstructured to typed.

func ConvertToIngress added in v1.1.0

func ConvertToIngress(obj *unstructured.Unstructured) (*extensionsv1beta1.Ingress, error)

ConvertToIngress converts a Service object from unstructured to typed.

func ConvertToJob added in v0.9.0

func ConvertToJob(obj *unstructured.Unstructured) (*batchv1.Job, error)

ConvertToJob converts a Job object from unstructured to typed.

func ConvertToNode added in v0.9.0

func ConvertToNode(obj *unstructured.Unstructured) (*corev1.Node, error)

ConvertToNode converts a Node object from unstructured to typed.

func ConvertToPod added in v0.9.0

func ConvertToPod(obj *unstructured.Unstructured) (*corev1.Pod, error)

ConvertToPod converts a Pod object from unstructured to typed.

func ConvertToPropagationPolicy added in v0.8.0

func ConvertToPropagationPolicy(obj *unstructured.Unstructured) (*policyv1alpha1.PropagationPolicy, error)

ConvertToPropagationPolicy converts a PropagationPolicy object from unstructured to typed.

func ConvertToReplicaSet added in v0.9.0

func ConvertToReplicaSet(obj *unstructured.Unstructured) (*appsv1.ReplicaSet, error)

ConvertToReplicaSet converts a ReplicaSet object from unstructured to typed.

func ConvertToResourceBinding added in v0.8.0

func ConvertToResourceBinding(obj *unstructured.Unstructured) (*workv1alpha2.ResourceBinding, error)

ConvertToResourceBinding converts a ResourceBinding object from unstructured to typed.

func ConvertToResourceExploringWebhookConfiguration added in v0.10.0

func ConvertToResourceExploringWebhookConfiguration(obj *unstructured.Unstructured) (*configv1alpha1.ResourceInterpreterWebhookConfiguration, error)

ConvertToResourceExploringWebhookConfiguration converts a ResourceInterpreterWebhookConfiguration object from unstructured to typed.

func ConvertToService added in v1.1.0

func ConvertToService(obj *unstructured.Unstructured) (*corev1.Service, error)

ConvertToService converts a Service object from unstructured to typed.

func ConvertToStatefulSet added in v0.9.0

func ConvertToStatefulSet(obj *unstructured.Unstructured) (*appsv1.StatefulSet, error)

ConvertToStatefulSet converts a StatefulSet object from unstructured 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, selector labels.Set) error

DeleteWorks will delete all Work objects by labels.

func FetchWorkload

func FetchWorkload(dynamicClient dynamic.Interface, informerManager informermanager.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, clusterNames []string, scope apiextensionsv1.ResourceScope) ([]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 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 GetBindingClusterNames

func GetBindingClusterNames(targetClusters []workv1alpha2.TargetCluster, bindingSnapshot []workv1alpha2.BindingSnapshot) []string

GetBindingClusterNames will get clusterName list from bind clusters field and requiredBy field.

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 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 GetObjectFromCache added in v0.7.0

func GetObjectFromCache(
	restMapper meta.RESTMapper,
	manager informermanager.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 informermanager.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 GetWorks added in v0.7.0

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

GetWorks returns a WorkList by labels

func GetWorksByLabelSelector added in v0.10.0

func GetWorksByLabelSelector(c client.Client, selector labels.Selector) (*workv1alpha1.WorkList, error)

GetWorksByLabelSelector get WorkList by matching label selector.

func HasScheduledReplica added in v0.7.0

func HasScheduledReplica(scheduleResult []workv1alpha2.TargetCluster) bool

HasScheduledReplica checks if the scheduler has assigned replicas for each 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 IsWorkContains added in v0.7.0

func IsWorkContains(workStatus *workv1alpha1.WorkStatus, targetResource schema.GroupVersionKind) bool

IsWorkContains checks if the target resource exists in a work. Note: This function checks the Work object's status to detect the target resource, so the Work should be 'Applied', otherwise always returns false.

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 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 NodeReady added in v0.10.0

func NodeReady(node *corev1.Node) bool

NodeReady checks whether the node condition is ready.

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

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

ToUnstructured converts a typed object to an unstructured object.

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