open-cluster-management.io/governance-policy-propagator@v0.13.0/controllers/automation/PolicyAutomationPredicate.go (about)

     1  // Copyright Contributors to the Open Cluster Management project
     2  
     3  package automation
     4  
     5  import (
     6  	"k8s.io/apimachinery/pkg/api/equality"
     7  	"sigs.k8s.io/controller-runtime/pkg/event"
     8  	"sigs.k8s.io/controller-runtime/pkg/predicate"
     9  
    10  	policyv1beta1 "open-cluster-management.io/governance-policy-propagator/api/v1beta1"
    11  )
    12  
    13  // we only want to watch for pb contains policy as subjects
    14  var policyAuomtationPredicateFuncs = predicate.Funcs{
    15  	UpdateFunc: func(e event.UpdateEvent) bool {
    16  		//nolint:forcetypeassert
    17  		policyAutomationNew := e.ObjectNew.(*policyv1beta1.PolicyAutomation)
    18  		//nolint:forcetypeassert
    19  		policyAutomationOld := e.ObjectOld.(*policyv1beta1.PolicyAutomation)
    20  
    21  		if policyAutomationNew.Spec.PolicyRef == "" {
    22  			return false
    23  		}
    24  
    25  		if policyAutomationNew.ObjectMeta.Annotations["policy.open-cluster-management.io/rerun"] == "true" {
    26  			return true
    27  		}
    28  
    29  		return !equality.Semantic.DeepEqual(policyAutomationNew.Spec, policyAutomationOld.Spec)
    30  	},
    31  	CreateFunc: func(e event.CreateEvent) bool {
    32  		//nolint:forcetypeassert
    33  		policyAutomationNew := e.Object.(*policyv1beta1.PolicyAutomation)
    34  
    35  		return policyAutomationNew.Spec.PolicyRef != ""
    36  	},
    37  	DeleteFunc: func(e event.DeleteEvent) bool {
    38  		return false
    39  	},
    40  }