Coder Social home page Coder Social logo

PolicyMarkedLabels and policyMarkedAnnotations of rb/crb may be lost when deleting the old pp/cpp and binding a new one about karmada HOT 5 OPEN

zhzhuang-zju avatar zhzhuang-zju commented on August 16, 2024 1
PolicyMarkedLabels and policyMarkedAnnotations of rb/crb may be lost when deleting the old pp/cpp and binding a new one

from karmada.

Comments (5)

whitewindmills avatar whitewindmills commented on August 16, 2024

great analysis, do you have any idea to fix this?

from karmada.

zhzhuang-zju avatar zhzhuang-zju commented on August 16, 2024

great analysis, do you have any idea to fix this?

When performing a clean up of marks on rb/crb, we can compare the value of the label policyv1alpha1.ClusterPropagationPolicyPermanentIDLabel on the cb/crb with the policyId value of the deleted CPP/PP. If they are not the same, it indicates that the rb/crb has already claimed to a new CPP/PP, and there is no need to clean up the label/annotation.

just like:

func (d *ResourceDetector) HandleClusterPropagationPolicyDeletion(policyID string) error {
	var errs []error
	labelSet := labels.Set{
		policyv1alpha1.ClusterPropagationPolicyPermanentIDLabel: policyID,
	}

	cleanupMarksFun := func(obj metav1.Object) bool {
		if obj.GetLabels()[policyv1alpha1.ClusterPropagationPolicyPermanentIDLabel] != policyId {
			return false
		}
		util.RemoveLabels(obj, clusterPropagationPolicyMarkedLabels...)
		util.RemoveAnnotations(obj, clusterPropagationPolicyMarkedAnnotations...)
		return true
	}
        ... ...
}

func (d *ResourceDetector) CleanupResourceBindingMarks(rb *workv1alpha2.ResourceBinding, cleanupFunc func(obj metav1.Object) bool) error {
	return retry.RetryOnConflict(retry.DefaultRetry, func() (err error) {
		if !cleanupFunc(rb) {
			klog.Infof("xxxx no need to clean up xxx")
			return nil
		}
		updateErr := d.Client.Update(context.TODO(), rb)
		if updateErr == nil {
			return nil
		}

		updated := &workv1alpha2.ResourceBinding{}
		if err = d.Client.Get(context.TODO(), client.ObjectKey{Namespace: rb.GetNamespace(), Name: rb.GetName()}, updated); err == nil {
			rb = updated.DeepCopy()
		} else {
			klog.Errorf("Failed to get updated resource binding %s/%s: %v", rb.GetNamespace(), rb.GetName(), err)
		}
		return updateErr
	})
}

from karmada.

whitewindmills avatar whitewindmills commented on August 16, 2024

it's a good answer.

from karmada.

XiShanYongYe-Chang avatar XiShanYongYe-Chang commented on August 16, 2024

In favor of #5319
/assign

from karmada.

XiShanYongYe-Chang avatar XiShanYongYe-Chang commented on August 16, 2024

I'm sorry, I made the wrong assign.
/assign @zhzhuang-zju
/unassign

from karmada.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.