Merge pull request #4950 from whitewindmills/bindID-webhook

cleanup dead code of generating binding permanent id
This commit is contained in:
karmada-bot 2024-05-21 10:22:25 +08:00 committed by GitHub
commit 1ebaf1d5a8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 2 additions and 22 deletions

View File

@ -20,7 +20,6 @@ import (
"context" "context"
"fmt" "fmt"
"github.com/google/uuid"
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/equality"
apierrors "k8s.io/apimachinery/pkg/api/errors" apierrors "k8s.io/apimachinery/pkg/api/errors"
@ -407,10 +406,6 @@ func (c *MCSController) propagateService(ctx context.Context, mcs *networkingv1a
"try again later after binding is garbage collected, see https://github.com/karmada-io/karmada/issues/2090") "try again later after binding is garbage collected, see https://github.com/karmada-io/karmada/issues/2090")
} }
if util.GetLabelValue(bindingCopy.Labels, workv1alpha2.ResourceBindingPermanentIDLabel) == "" {
bindingCopy.Labels = util.DedupeAndMergeLabels(bindingCopy.Labels,
map[string]string{workv1alpha2.ResourceBindingPermanentIDLabel: uuid.New().String()})
}
// Just update necessary fields, especially avoid modifying Spec.Clusters which is scheduling result, if already exists. // Just update necessary fields, especially avoid modifying Spec.Clusters which is scheduling result, if already exists.
bindingCopy.Annotations = util.DedupeAndMergeAnnotations(bindingCopy.Annotations, binding.Annotations) bindingCopy.Annotations = util.DedupeAndMergeAnnotations(bindingCopy.Annotations, binding.Annotations)
bindingCopy.Labels = util.DedupeAndMergeLabels(bindingCopy.Labels, binding.Labels) bindingCopy.Labels = util.DedupeAndMergeLabels(bindingCopy.Labels, binding.Labels)

View File

@ -21,7 +21,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/google/uuid"
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors" apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta" "k8s.io/apimachinery/pkg/api/meta"
@ -538,8 +537,6 @@ func (d *DependenciesDistributor) createOrUpdateAttachedBinding(attachedBinding
return err return err
} }
attachedBinding.Labels = util.DedupeAndMergeLabels(attachedBinding.Labels,
map[string]string{workv1alpha2.ResourceBindingPermanentIDLabel: uuid.New().String()})
if err := d.Client.Create(context.TODO(), attachedBinding); err != nil { if err := d.Client.Create(context.TODO(), attachedBinding); err != nil {
return err return err
} }
@ -653,8 +650,8 @@ func buildAttachedBinding(binding *workv1alpha2.ResourceBinding, object *unstruc
Clusters: binding.Spec.Clusters, Clusters: binding.Spec.Clusters,
}) })
policyID := util.GetLabelValue(binding.Labels, workv1alpha2.ResourceBindingPermanentIDLabel) bindingID := util.GetLabelValue(binding.Labels, workv1alpha2.ResourceBindingPermanentIDLabel)
dependedLabels = util.DedupeAndMergeLabels(dependedLabels, map[string]string{bindingDependedIDLabelKey: policyID}) dependedLabels = util.DedupeAndMergeLabels(dependedLabels, map[string]string{bindingDependedIDLabelKey: bindingID})
return &workv1alpha2.ResourceBinding{ return &workv1alpha2.ResourceBinding{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: names.GenerateBindingName(object.GetKind(), object.GetName()), Name: names.GenerateBindingName(object.GetKind(), object.GetName()),

View File

@ -496,10 +496,6 @@ func (d *ResourceDetector) ApplyPolicy(object *unstructured.Unstructured, object
"try again later after binding is garbage collected, see https://github.com/karmada-io/karmada/issues/2090") "try again later after binding is garbage collected, see https://github.com/karmada-io/karmada/issues/2090")
} }
if util.GetLabelValue(bindingCopy.Labels, workv1alpha2.ResourceBindingPermanentIDLabel) == "" {
bindingCopy.Labels = util.DedupeAndMergeLabels(bindingCopy.Labels,
map[string]string{workv1alpha2.ResourceBindingPermanentIDLabel: uuid.New().String()})
}
// Just update necessary fields, especially avoid modifying Spec.Clusters which is scheduling result, if already exists. // Just update necessary fields, especially avoid modifying Spec.Clusters which is scheduling result, if already exists.
bindingCopy.Annotations = util.DedupeAndMergeAnnotations(bindingCopy.Annotations, binding.Annotations) bindingCopy.Annotations = util.DedupeAndMergeAnnotations(bindingCopy.Annotations, binding.Annotations)
bindingCopy.Labels = util.DedupeAndMergeLabels(bindingCopy.Labels, binding.Labels) bindingCopy.Labels = util.DedupeAndMergeLabels(bindingCopy.Labels, binding.Labels)
@ -596,10 +592,6 @@ func (d *ResourceDetector) ApplyClusterPolicy(object *unstructured.Unstructured,
"try again later after binding is garbage collected, see https://github.com/karmada-io/karmada/issues/2090") "try again later after binding is garbage collected, see https://github.com/karmada-io/karmada/issues/2090")
} }
if util.GetLabelValue(bindingCopy.Labels, workv1alpha2.ResourceBindingPermanentIDLabel) == "" {
bindingCopy.Labels = util.DedupeAndMergeLabels(bindingCopy.Labels,
map[string]string{workv1alpha2.ResourceBindingPermanentIDLabel: uuid.New().String()})
}
// Just update necessary fields, especially avoid modifying Spec.Clusters which is scheduling result, if already exists. // Just update necessary fields, especially avoid modifying Spec.Clusters which is scheduling result, if already exists.
bindingCopy.Annotations = util.DedupeAndMergeAnnotations(bindingCopy.Annotations, binding.Annotations) bindingCopy.Annotations = util.DedupeAndMergeAnnotations(bindingCopy.Annotations, binding.Annotations)
bindingCopy.Labels = util.DedupeAndMergeLabels(bindingCopy.Labels, binding.Labels) bindingCopy.Labels = util.DedupeAndMergeLabels(bindingCopy.Labels, binding.Labels)
@ -646,10 +638,6 @@ func (d *ResourceDetector) ApplyClusterPolicy(object *unstructured.Unstructured,
"try again later after binding is garbage collected, see https://github.com/karmada-io/karmada/issues/2090") "try again later after binding is garbage collected, see https://github.com/karmada-io/karmada/issues/2090")
} }
if util.GetLabelValue(bindingCopy.Labels, workv1alpha2.ClusterResourceBindingPermanentIDLabel) == "" {
bindingCopy.Labels = util.DedupeAndMergeLabels(bindingCopy.Labels,
map[string]string{workv1alpha2.ClusterResourceBindingPermanentIDLabel: uuid.New().String()})
}
// Just update necessary fields, especially avoid modifying Spec.Clusters which is scheduling result, if already exists. // Just update necessary fields, especially avoid modifying Spec.Clusters which is scheduling result, if already exists.
bindingCopy.Annotations = util.DedupeAndMergeAnnotations(bindingCopy.Annotations, binding.Annotations) bindingCopy.Annotations = util.DedupeAndMergeAnnotations(bindingCopy.Annotations, binding.Annotations)
bindingCopy.Labels = util.DedupeAndMergeLabels(bindingCopy.Labels, binding.Labels) bindingCopy.Labels = util.DedupeAndMergeLabels(bindingCopy.Labels, binding.Labels)