Move labels to apis
Signed-off-by: pigletfly <wangbing.adam@gmail.com>
This commit is contained in:
parent
08f3ef9995
commit
8edb376966
|
@ -0,0 +1,12 @@
|
|||
package v1alpha1
|
||||
|
||||
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"
|
||||
)
|
|
@ -0,0 +1,18 @@
|
|||
package v1alpha1
|
||||
|
||||
const (
|
||||
// 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"
|
||||
)
|
|
@ -47,8 +47,8 @@ func (c *ResourceBindingController) Reconcile(ctx context.Context, req controlle
|
|||
// The resource no longer exist, clean up derived Work objects.
|
||||
if errors.IsNotFound(err) {
|
||||
return helper.DeleteWorks(c.Client, labels.Set{
|
||||
util.ResourceBindingNamespaceLabel: req.Namespace,
|
||||
util.ResourceBindingNameLabel: req.Name,
|
||||
workv1alpha1.ResourceBindingNamespaceLabel: req.Namespace,
|
||||
workv1alpha1.ResourceBindingNameLabel: req.Name,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -116,8 +116,8 @@ func (c *ResourceBindingController) SetupWithManager(mgr controllerruntime.Manag
|
|||
var requests []reconcile.Request
|
||||
|
||||
labels := a.GetLabels()
|
||||
resourcebindingNamespace, namespaceExist := labels[util.ResourceBindingNamespaceLabel]
|
||||
resourcebindingName, nameExist := labels[util.ResourceBindingNameLabel]
|
||||
resourcebindingNamespace, namespaceExist := labels[workv1alpha1.ResourceBindingNamespaceLabel]
|
||||
resourcebindingName, nameExist := labels[workv1alpha1.ResourceBindingNameLabel]
|
||||
if !namespaceExist || !nameExist {
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ func (c *ClusterResourceBindingController) Reconcile(ctx context.Context, req co
|
|||
// The resource no longer exist, clean up derived Work objects.
|
||||
if errors.IsNotFound(err) {
|
||||
return helper.DeleteWorks(c.Client, labels.Set{
|
||||
util.ClusterResourceBindingLabel: req.Name,
|
||||
workv1alpha1.ClusterResourceBindingLabel: req.Name,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -110,7 +110,7 @@ func (c *ClusterResourceBindingController) SetupWithManager(mgr controllerruntim
|
|||
var requests []reconcile.Request
|
||||
|
||||
labels := a.GetLabels()
|
||||
clusterResourcebindingName, nameExist := labels[util.ClusterResourceBindingLabel]
|
||||
clusterResourcebindingName, nameExist := labels[workv1alpha1.ClusterResourceBindingLabel]
|
||||
if !nameExist {
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -98,8 +98,8 @@ func (c *HorizontalPodAutoscalerController) buildWorks(hpa *autoscalingv1.Horizo
|
|||
},
|
||||
}
|
||||
|
||||
util.MergeLabel(hpaObj, util.WorkNamespaceLabel, workNamespace)
|
||||
util.MergeLabel(hpaObj, util.WorkNameLabel, workName)
|
||||
util.MergeLabel(hpaObj, workv1alpha1.WorkNamespaceLabel, workNamespace)
|
||||
util.MergeLabel(hpaObj, workv1alpha1.WorkNameLabel, workName)
|
||||
|
||||
if err = helper.CreateOrUpdateWork(c.Client, objectMeta, hpaObj); err != nil {
|
||||
return err
|
||||
|
|
|
@ -40,8 +40,8 @@ func (c *EndpointSliceController) Reconcile(ctx context.Context, req controllerr
|
|||
if errors.IsNotFound(err) {
|
||||
// Cleanup derived EndpointSlices after work has been removed.
|
||||
return helper.DeleteEndpointSlice(c.Client, labels.Set{
|
||||
util.WorkNamespaceLabel: req.Namespace,
|
||||
util.WorkNameLabel: req.Name,
|
||||
workv1alpha1.WorkNamespaceLabel: req.Namespace,
|
||||
workv1alpha1.WorkNameLabel: req.Name,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -96,8 +96,8 @@ func (c *EndpointSliceController) collectEndpointSliceFromWork(work *workv1alpha
|
|||
|
||||
desiredEndpointSlice := deriveEndpointSlice(endpointSlice, clusterName)
|
||||
desiredEndpointSlice.Labels = map[string]string{
|
||||
util.WorkNamespaceLabel: work.Namespace,
|
||||
util.WorkNameLabel: work.Name,
|
||||
workv1alpha1.WorkNamespaceLabel: work.Namespace,
|
||||
workv1alpha1.WorkNameLabel: work.Name,
|
||||
discoveryv1beta1.LabelServiceName: names.GenerateDerivedServiceName(work.Labels[util.ServiceNameLabel]),
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ import (
|
|||
"sigs.k8s.io/controller-runtime/pkg/source"
|
||||
|
||||
"github.com/karmada-io/karmada/pkg/apis/cluster/v1alpha1"
|
||||
workv1alpha1 "github.com/karmada-io/karmada/pkg/apis/work/v1alpha1"
|
||||
"github.com/karmada-io/karmada/pkg/util"
|
||||
"github.com/karmada-io/karmada/pkg/util/helper"
|
||||
"github.com/karmada-io/karmada/pkg/util/names"
|
||||
|
@ -121,8 +122,8 @@ func (c *Controller) buildWorks(namespace *v1.Namespace, clusters []v1alpha1.Clu
|
|||
},
|
||||
}
|
||||
|
||||
util.MergeLabel(namespaceObj, util.WorkNamespaceLabel, workNamespace)
|
||||
util.MergeLabel(namespaceObj, util.WorkNameLabel, workName)
|
||||
util.MergeLabel(namespaceObj, workv1alpha1.WorkNamespaceLabel, workNamespace)
|
||||
util.MergeLabel(namespaceObj, workv1alpha1.WorkNameLabel, workName)
|
||||
|
||||
if err = helper.CreateOrUpdateWork(c.Client, objectMeta, namespaceObj); err != nil {
|
||||
return err
|
||||
|
|
|
@ -134,8 +134,8 @@ func (c *WorkStatusController) syncWorkStatus(key util.QueueKey) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
workNamespace := util.GetLabelValue(obj.GetLabels(), util.WorkNamespaceLabel)
|
||||
workName := util.GetLabelValue(obj.GetLabels(), util.WorkNameLabel)
|
||||
workNamespace := util.GetLabelValue(obj.GetLabels(), workv1alpha1.WorkNamespaceLabel)
|
||||
workName := util.GetLabelValue(obj.GetLabels(), workv1alpha1.WorkNameLabel)
|
||||
if len(workNamespace) == 0 || len(workName) == 0 {
|
||||
klog.Infof("Ignore object(%s) which not managed by karmada.", fedKey.String())
|
||||
return nil
|
||||
|
|
|
@ -190,8 +190,8 @@ func (s *Scheduler) onPropagationPolicyUpdate(old, cur interface{}) {
|
|||
}
|
||||
|
||||
selector := labels.SelectorFromSet(labels.Set{
|
||||
util.PropagationPolicyNamespaceLabel: oldPropagationPolicy.Namespace,
|
||||
util.PropagationPolicyNameLabel: oldPropagationPolicy.Name,
|
||||
policyv1alpha1.PropagationPolicyNamespaceLabel: oldPropagationPolicy.Namespace,
|
||||
policyv1alpha1.PropagationPolicyNameLabel: oldPropagationPolicy.Name,
|
||||
})
|
||||
|
||||
err := s.requeueResourceBindings(selector)
|
||||
|
@ -210,7 +210,7 @@ func (s *Scheduler) onClusterPropagationPolicyUpdate(old, cur interface{}) {
|
|||
}
|
||||
|
||||
selector := labels.SelectorFromSet(labels.Set{
|
||||
util.ClusterPropagationPolicyLabel: oldClusterPropagationPolicy.Name,
|
||||
policyv1alpha1.ClusterPropagationPolicyLabel: oldClusterPropagationPolicy.Name,
|
||||
})
|
||||
|
||||
err := s.requeueClusterResourceBindings(selector)
|
||||
|
@ -275,7 +275,7 @@ func (s *Scheduler) getPlacement(resourceBinding *workv1alpha1.ResourceBinding)
|
|||
var policyName string
|
||||
var policyNamespace string
|
||||
var err error
|
||||
if clusterPolicyName = util.GetLabelValue(resourceBinding.Labels, util.ClusterPropagationPolicyLabel); clusterPolicyName != "" {
|
||||
if clusterPolicyName = util.GetLabelValue(resourceBinding.Labels, policyv1alpha1.ClusterPropagationPolicyLabel); clusterPolicyName != "" {
|
||||
var clusterPolicy *policyv1alpha1.ClusterPropagationPolicy
|
||||
clusterPolicy, err = s.clusterPolicyLister.Get(clusterPolicyName)
|
||||
if err != nil {
|
||||
|
@ -285,8 +285,8 @@ func (s *Scheduler) getPlacement(resourceBinding *workv1alpha1.ResourceBinding)
|
|||
placement = clusterPolicy.Spec.Placement
|
||||
}
|
||||
|
||||
if policyName = util.GetLabelValue(resourceBinding.Labels, util.PropagationPolicyNameLabel); policyName != "" {
|
||||
policyNamespace = util.GetLabelValue(resourceBinding.Labels, util.PropagationPolicyNamespaceLabel)
|
||||
if policyName = util.GetLabelValue(resourceBinding.Labels, policyv1alpha1.PropagationPolicyNameLabel); policyName != "" {
|
||||
policyNamespace = util.GetLabelValue(resourceBinding.Labels, policyv1alpha1.PropagationPolicyNamespaceLabel)
|
||||
var policy *policyv1alpha1.PropagationPolicy
|
||||
policy, err = s.policyLister.PropagationPolicies(policyNamespace).Get(policyName)
|
||||
if err != nil {
|
||||
|
@ -370,7 +370,7 @@ func (s *Scheduler) getScheduleType(key string) ScheduleType {
|
|||
return FirstSchedule
|
||||
}
|
||||
|
||||
policyName := util.GetLabelValue(binding.Labels, util.ClusterPropagationPolicyLabel)
|
||||
policyName := util.GetLabelValue(binding.Labels, policyv1alpha1.ClusterPropagationPolicyLabel)
|
||||
|
||||
policy, err := s.clusterPolicyLister.Get(policyName)
|
||||
if err != nil {
|
||||
|
@ -459,7 +459,7 @@ func (s *Scheduler) scheduleOne(key string) (err error) {
|
|||
return nil
|
||||
}
|
||||
|
||||
clusterPolicyName := util.GetLabelValue(clusterResourceBinding.Labels, util.ClusterPropagationPolicyLabel)
|
||||
clusterPolicyName := util.GetLabelValue(clusterResourceBinding.Labels, policyv1alpha1.ClusterPropagationPolicyLabel)
|
||||
|
||||
clusterPolicy, err := s.clusterPolicyLister.Get(clusterPolicyName)
|
||||
if err != nil {
|
||||
|
@ -670,7 +670,7 @@ func (s *Scheduler) rescheduleOne(key string) (err error) {
|
|||
}
|
||||
|
||||
func (s *Scheduler) rescheduleClusterResourceBinding(clusterResourceBinding *workv1alpha1.ClusterResourceBinding) error {
|
||||
policyName := util.GetLabelValue(clusterResourceBinding.Labels, util.ClusterPropagationPolicyLabel)
|
||||
policyName := util.GetLabelValue(clusterResourceBinding.Labels, policyv1alpha1.ClusterPropagationPolicyLabel)
|
||||
policy, err := s.clusterPolicyLister.Get(policyName)
|
||||
if err != nil {
|
||||
klog.Errorf("Failed to get policy by policyName(%s): Error: %v", policyName, err)
|
||||
|
@ -805,7 +805,7 @@ func (s *Scheduler) scaleScheduleOne(key string) (err error) {
|
|||
return nil
|
||||
}
|
||||
|
||||
clusterPolicyName := util.GetLabelValue(clusterResourceBinding.Labels, util.ClusterPropagationPolicyLabel)
|
||||
clusterPolicyName := util.GetLabelValue(clusterResourceBinding.Labels, policyv1alpha1.ClusterPropagationPolicyLabel)
|
||||
|
||||
clusterPolicy, err := s.clusterPolicyLister.Get(clusterPolicyName)
|
||||
if err != nil {
|
||||
|
|
|
@ -1,30 +1,6 @@
|
|||
package util
|
||||
|
||||
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"
|
||||
|
||||
// ServiceNamespaceLabel is added to work object, which is report by member cluster, to specify service namespace associated with EndpointSlice.
|
||||
ServiceNamespaceLabel = "endpointslice.karmada.io/namespace"
|
||||
|
||||
|
|
|
@ -375,8 +375,8 @@ func (d *ResourceDetector) ApplyPolicy(object *unstructured.Unstructured, object
|
|||
}
|
||||
|
||||
policyLabels := map[string]string{
|
||||
util.PropagationPolicyNamespaceLabel: policy.GetNamespace(),
|
||||
util.PropagationPolicyNameLabel: policy.GetName(),
|
||||
policyv1alpha1.PropagationPolicyNamespaceLabel: policy.GetNamespace(),
|
||||
policyv1alpha1.PropagationPolicyNameLabel: policy.GetName(),
|
||||
}
|
||||
|
||||
binding, err := d.BuildResourceBinding(object, objectKey, policyLabels)
|
||||
|
@ -418,7 +418,7 @@ func (d *ResourceDetector) ApplyClusterPolicy(object *unstructured.Unstructured,
|
|||
}
|
||||
|
||||
policyLabels := map[string]string{
|
||||
util.ClusterPropagationPolicyLabel: policy.GetName(),
|
||||
policyv1alpha1.ClusterPropagationPolicyLabel: policy.GetName(),
|
||||
}
|
||||
|
||||
// Build `ResourceBinding` or `ClusterResourceBinding` according to the resource template's scope.
|
||||
|
@ -529,30 +529,30 @@ func (d *ResourceDetector) GetObject(objectKey keys.ClusterWideKey) (runtime.Obj
|
|||
|
||||
// ClaimPolicyForObject set policy identifier which the object associated with.
|
||||
func (d *ResourceDetector) ClaimPolicyForObject(object *unstructured.Unstructured, policyNamespace string, policyName string) error {
|
||||
claimedNS := util.GetLabelValue(object.GetLabels(), util.PropagationPolicyNamespaceLabel)
|
||||
claimedName := util.GetLabelValue(object.GetLabels(), util.PropagationPolicyNameLabel)
|
||||
claimedNS := util.GetLabelValue(object.GetLabels(), policyv1alpha1.PropagationPolicyNamespaceLabel)
|
||||
claimedName := util.GetLabelValue(object.GetLabels(), policyv1alpha1.PropagationPolicyNameLabel)
|
||||
|
||||
// object has been claimed, don't need to claim again
|
||||
if claimedNS == policyNamespace && claimedName == policyName {
|
||||
return nil
|
||||
}
|
||||
|
||||
util.MergeLabel(object, util.PropagationPolicyNamespaceLabel, policyNamespace)
|
||||
util.MergeLabel(object, util.PropagationPolicyNameLabel, policyName)
|
||||
util.MergeLabel(object, policyv1alpha1.PropagationPolicyNamespaceLabel, policyNamespace)
|
||||
util.MergeLabel(object, policyv1alpha1.PropagationPolicyNameLabel, policyName)
|
||||
|
||||
return d.Client.Update(context.TODO(), object)
|
||||
}
|
||||
|
||||
// ClaimClusterPolicyForObject set cluster identifier which the object associated with.
|
||||
func (d *ResourceDetector) ClaimClusterPolicyForObject(object *unstructured.Unstructured, policyName string) error {
|
||||
claimedName := util.GetLabelValue(object.GetLabels(), util.ClusterPropagationPolicyLabel)
|
||||
claimedName := util.GetLabelValue(object.GetLabels(), policyv1alpha1.ClusterPropagationPolicyLabel)
|
||||
|
||||
// object has been claimed, don't need to claim again
|
||||
if claimedName == policyName {
|
||||
return nil
|
||||
}
|
||||
|
||||
util.MergeLabel(object, util.ClusterPropagationPolicyLabel, policyName)
|
||||
util.MergeLabel(object, policyv1alpha1.ClusterPropagationPolicyLabel, policyName)
|
||||
return d.Client.Update(context.TODO(), object)
|
||||
}
|
||||
|
||||
|
@ -826,8 +826,8 @@ func (d *ResourceDetector) ReconcileClusterPropagationPolicy(key util.QueueKey)
|
|||
// original resource to match another policy.
|
||||
func (d *ResourceDetector) HandlePropagationPolicyDeletion(policyNS string, policyName string) error {
|
||||
labelSet := labels.Set{
|
||||
util.PropagationPolicyNamespaceLabel: policyNS,
|
||||
util.PropagationPolicyNameLabel: policyName,
|
||||
policyv1alpha1.PropagationPolicyNamespaceLabel: policyNS,
|
||||
policyv1alpha1.PropagationPolicyNameLabel: policyName,
|
||||
}
|
||||
|
||||
rbs, err := helper.GetResourceBindings(d.Client, labelSet)
|
||||
|
@ -839,7 +839,7 @@ func (d *ResourceDetector) HandlePropagationPolicyDeletion(policyNS string, poli
|
|||
for itemIndex, binding := range rbs.Items {
|
||||
// Cleanup the labels from the object referencing by binding.
|
||||
// In addition, this will give the object a chance to match another policy.
|
||||
if err := d.CleanupLabels(binding.Spec.Resource, util.PropagationPolicyNameLabel, util.PropagationPolicyNameLabel); err != nil {
|
||||
if err := d.CleanupLabels(binding.Spec.Resource, policyv1alpha1.PropagationPolicyNameLabel, policyv1alpha1.PropagationPolicyNameLabel); err != nil {
|
||||
klog.Errorf("Failed to cleanup label from resource(%s-%s/%s) when resource binding(%s/%s) removing, error: %v",
|
||||
binding.Spec.Resource.Kind, binding.Spec.Resource.Namespace, binding.Spec.Resource.Name, binding.Namespace, binding.Name, err)
|
||||
return err
|
||||
|
@ -861,7 +861,7 @@ func (d *ResourceDetector) HandlePropagationPolicyDeletion(policyNS string, poli
|
|||
func (d *ResourceDetector) HandleClusterPropagationPolicyDeletion(policyName string) error {
|
||||
var errs []error
|
||||
labelSet := labels.Set{
|
||||
util.ClusterPropagationPolicyLabel: policyName,
|
||||
policyv1alpha1.ClusterPropagationPolicyLabel: policyName,
|
||||
}
|
||||
|
||||
// load and remove the ClusterResourceBindings which labeled with current policy
|
||||
|
@ -873,7 +873,7 @@ func (d *ResourceDetector) HandleClusterPropagationPolicyDeletion(policyName str
|
|||
for itemIndex, binding := range crbs.Items {
|
||||
// Cleanup the labels from the object referencing by binding.
|
||||
// In addition, this will give the object a chance to match another policy.
|
||||
if err := d.CleanupLabels(binding.Spec.Resource, util.ClusterPropagationPolicyLabel); err != nil {
|
||||
if err := d.CleanupLabels(binding.Spec.Resource, policyv1alpha1.ClusterPropagationPolicyLabel); err != nil {
|
||||
klog.Errorf("Failed to cleanup label from resource(%s-%s/%s) when cluster resource binding(%s) removing, error: %v",
|
||||
binding.Spec.Resource.Kind, binding.Spec.Resource.Namespace, binding.Spec.Resource.Name, binding.Name, err)
|
||||
errs = append(errs, err)
|
||||
|
@ -896,7 +896,7 @@ func (d *ResourceDetector) HandleClusterPropagationPolicyDeletion(policyName str
|
|||
for itemIndex, binding := range rbs.Items {
|
||||
// Cleanup the labels from the object referencing by binding.
|
||||
// In addition, this will give the object a chance to match another policy.
|
||||
if err := d.CleanupLabels(binding.Spec.Resource, util.ClusterPropagationPolicyLabel); err != nil {
|
||||
if err := d.CleanupLabels(binding.Spec.Resource, policyv1alpha1.ClusterPropagationPolicyLabel); err != nil {
|
||||
klog.Errorf("Failed to cleanup label from resource binding(%s/%s), error: %v", binding.Namespace, binding.Name, err)
|
||||
errs = append(errs, err)
|
||||
}
|
||||
|
|
|
@ -93,8 +93,8 @@ func FindOrphanWorks(c client.Client, bindingNamespace, bindingName string, clus
|
|||
workList := &workv1alpha1.WorkList{}
|
||||
if scope == apiextensionsv1.NamespaceScoped {
|
||||
selector := labels.SelectorFromSet(labels.Set{
|
||||
util.ResourceBindingNamespaceLabel: bindingNamespace,
|
||||
util.ResourceBindingNameLabel: bindingName,
|
||||
workv1alpha1.ResourceBindingNamespaceLabel: bindingNamespace,
|
||||
workv1alpha1.ResourceBindingNameLabel: bindingName,
|
||||
})
|
||||
|
||||
if err := c.List(context.TODO(), workList, &client.ListOptions{LabelSelector: selector}); err != nil {
|
||||
|
@ -102,7 +102,7 @@ func FindOrphanWorks(c client.Client, bindingNamespace, bindingName string, clus
|
|||
}
|
||||
} else {
|
||||
selector := labels.SelectorFromSet(labels.Set{
|
||||
util.ClusterResourceBindingLabel: bindingName,
|
||||
workv1alpha1.ClusterResourceBindingLabel: bindingName,
|
||||
})
|
||||
|
||||
if err := c.List(context.TODO(), workList, &client.ListOptions{LabelSelector: selector}); err != nil {
|
||||
|
@ -238,17 +238,17 @@ func getRSPAndReplicaInfos(c client.Client, workload *unstructured.Unstructured,
|
|||
|
||||
func mergeLabel(workload *unstructured.Unstructured, workNamespace string, binding metav1.Object, scope apiextensionsv1.ResourceScope) map[string]string {
|
||||
var workLabel = make(map[string]string)
|
||||
util.MergeLabel(workload, util.WorkNamespaceLabel, workNamespace)
|
||||
util.MergeLabel(workload, util.WorkNameLabel, names.GenerateWorkName(workload.GetKind(), workload.GetName(), workload.GetNamespace()))
|
||||
util.MergeLabel(workload, workv1alpha1.WorkNamespaceLabel, workNamespace)
|
||||
util.MergeLabel(workload, workv1alpha1.WorkNameLabel, names.GenerateWorkName(workload.GetKind(), workload.GetName(), workload.GetNamespace()))
|
||||
|
||||
if scope == apiextensionsv1.NamespaceScoped {
|
||||
util.MergeLabel(workload, util.ResourceBindingNamespaceLabel, binding.GetNamespace())
|
||||
util.MergeLabel(workload, util.ResourceBindingNameLabel, binding.GetName())
|
||||
workLabel[util.ResourceBindingNamespaceLabel] = binding.GetNamespace()
|
||||
workLabel[util.ResourceBindingNameLabel] = binding.GetName()
|
||||
util.MergeLabel(workload, workv1alpha1.ResourceBindingNamespaceLabel, binding.GetNamespace())
|
||||
util.MergeLabel(workload, workv1alpha1.ResourceBindingNameLabel, binding.GetName())
|
||||
workLabel[workv1alpha1.ResourceBindingNamespaceLabel] = binding.GetNamespace()
|
||||
workLabel[workv1alpha1.ResourceBindingNameLabel] = binding.GetName()
|
||||
} else {
|
||||
util.MergeLabel(workload, util.ClusterResourceBindingLabel, binding.GetName())
|
||||
workLabel[util.ClusterResourceBindingLabel] = binding.GetName()
|
||||
util.MergeLabel(workload, workv1alpha1.ClusterResourceBindingLabel, binding.GetName())
|
||||
workLabel[workv1alpha1.ClusterResourceBindingLabel] = binding.GetName()
|
||||
}
|
||||
|
||||
return workLabel
|
||||
|
|
|
@ -13,7 +13,6 @@ import (
|
|||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
|
||||
workv1alpha1 "github.com/karmada-io/karmada/pkg/apis/work/v1alpha1"
|
||||
"github.com/karmada-io/karmada/pkg/util"
|
||||
"github.com/karmada-io/karmada/pkg/util/names"
|
||||
)
|
||||
|
||||
|
@ -21,8 +20,8 @@ import (
|
|||
// then aggregate status info to current ResourceBinding status.
|
||||
func AggregateResourceBindingWorkStatus(c client.Client, binding *workv1alpha1.ResourceBinding, workload *unstructured.Unstructured) error {
|
||||
aggregatedStatuses, err := assembleWorkStatus(c, labels.SelectorFromSet(labels.Set{
|
||||
util.ResourceBindingNamespaceLabel: binding.Namespace,
|
||||
util.ResourceBindingNameLabel: binding.Name,
|
||||
workv1alpha1.ResourceBindingNamespaceLabel: binding.Namespace,
|
||||
workv1alpha1.ResourceBindingNameLabel: binding.Name,
|
||||
}), workload)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -49,7 +48,7 @@ func AggregateResourceBindingWorkStatus(c client.Client, binding *workv1alpha1.R
|
|||
// then aggregate status info to current ClusterResourceBinding status.
|
||||
func AggregateClusterResourceBindingWorkStatus(c client.Client, binding *workv1alpha1.ClusterResourceBinding, workload *unstructured.Unstructured) error {
|
||||
aggregatedStatuses, err := assembleWorkStatus(c, labels.SelectorFromSet(labels.Set{
|
||||
util.ClusterResourceBindingLabel: binding.Name,
|
||||
workv1alpha1.ClusterResourceBindingLabel: binding.Name,
|
||||
}), workload)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -15,6 +15,7 @@ import (
|
|||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
|
||||
"github.com/karmada-io/karmada/pkg/apis/cluster/v1alpha1"
|
||||
workv1alpha1 "github.com/karmada-io/karmada/pkg/apis/work/v1alpha1"
|
||||
"github.com/karmada-io/karmada/pkg/util"
|
||||
"github.com/karmada-io/karmada/pkg/util/restmapper"
|
||||
)
|
||||
|
@ -81,7 +82,7 @@ func (o *objectWatcherImpl) Create(cluster *v1alpha1.Cluster, desireObj *unstruc
|
|||
}
|
||||
|
||||
// Avoid updating resources that not managed by karmada.
|
||||
if util.GetLabelValue(desireObj.GetLabels(), util.WorkNameLabel) != util.GetLabelValue(existObj.GetLabels(), util.WorkNameLabel) {
|
||||
if util.GetLabelValue(desireObj.GetLabels(), workv1alpha1.WorkNameLabel) != util.GetLabelValue(existObj.GetLabels(), workv1alpha1.WorkNameLabel) {
|
||||
return fmt.Errorf("resource(kind=%s, %s/%s) already exist in cluster %v but not managed by karamda", desireObj.GetKind(), desireObj.GetNamespace(), desireObj.GetName(), cluster.Name)
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"k8s.io/client-go/util/workqueue"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
workv1alpha1 "github.com/karmada-io/karmada/pkg/apis/work/v1alpha1"
|
||||
"github.com/karmada-io/karmada/pkg/util/informermanager/keys"
|
||||
"github.com/karmada-io/karmada/pkg/util/names"
|
||||
)
|
||||
|
@ -84,7 +85,7 @@ func GenerateKey(obj interface{}) (QueueKey, error) {
|
|||
|
||||
// getClusterNameFromLabel gets cluster name from ownerLabel, if label not exist, means resource is not created by karmada.
|
||||
func getClusterNameFromLabel(resource *unstructured.Unstructured) (string, error) {
|
||||
workNamespace := GetLabelValue(resource.GetLabels(), WorkNamespaceLabel)
|
||||
workNamespace := GetLabelValue(resource.GetLabels(), workv1alpha1.WorkNamespaceLabel)
|
||||
if len(workNamespace) == 0 {
|
||||
klog.V(4).Infof("Ignore resource(%s/%s/%s) which not managed by karmada", resource.GetKind(), resource.GetNamespace(), resource.GetName())
|
||||
return "", nil
|
||||
|
|
Loading…
Reference in New Issue