Skip to content

Commit

Permalink
Merge pull request #4138 from jwcesign/fix-version-sync
Browse files Browse the repository at this point in the history
fix: Sync workload's status.observedGeneration if it's updated
  • Loading branch information
karmada-bot authored Oct 24, 2023
2 parents 0fe6f14 + e50f414 commit d6cc5b9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
34 changes: 34 additions & 0 deletions pkg/controllers/status/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,40 @@ import (
"github.com/karmada-io/karmada/pkg/util/restmapper"
)

var rbPredicateFn = builder.WithPredicates(predicate.Funcs{
CreateFunc: func(e event.CreateEvent) bool { return false },
UpdateFunc: func(e event.UpdateEvent) bool {
var oldResourceVersion, newResourceVersion string

// NOTE: We add this logic to prevent the situation as following:
// 1. Create Deployment and HPA.
// 2. Propagate Deployment with divided policy and propagate HPA with duplicated policy.
// 3. HPA scaled up the Deployment in member clusters
// 4. hpareplicassyncer update Deployment's replicas based on HPA status in Kamarda control plane.
// 5. It will cause the Deployment.status.observedGeneration != Deployment.metadata.generation(this is needed in some workflow cases)
switch oldBinding := e.ObjectOld.(type) {
case *workv1alpha2.ResourceBinding:
oldResourceVersion = oldBinding.Spec.Resource.ResourceVersion
case *workv1alpha2.ClusterResourceBinding:
oldResourceVersion = oldBinding.Spec.Resource.ResourceVersion
default:
return false
}

switch newBinding := e.ObjectNew.(type) {
case *workv1alpha2.ResourceBinding:
newResourceVersion = newBinding.Spec.Resource.ResourceVersion
case *workv1alpha2.ClusterResourceBinding:
newResourceVersion = newBinding.Spec.Resource.ResourceVersion
default:
return false
}

return !reflect.DeepEqual(oldResourceVersion, newResourceVersion)
},
DeleteFunc: func(e event.DeleteEvent) bool { return false },
})

var workPredicateFn = builder.WithPredicates(predicate.Funcs{
CreateFunc: func(e event.CreateEvent) bool { return false },
UpdateFunc: func(e event.UpdateEvent) bool {
Expand Down
1 change: 1 addition & 0 deletions pkg/controllers/status/crb_status_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func (c *CRBStatusController) SetupWithManager(mgr controllerruntime.Manager) er
})

return controllerruntime.NewControllerManagedBy(mgr).Named("clusterResourceBinding_status_controller").
For(&workv1alpha2.ResourceBinding{}, rbPredicateFn).
Watches(&workv1alpha1.Work{}, handler.EnqueueRequestsFromMapFunc(workMapFunc), workPredicateFn).
WithOptions(controller.Options{RateLimiter: ratelimiterflag.DefaultControllerRateLimiter(c.RateLimiterOptions)}).
Complete(c)
Expand Down
1 change: 1 addition & 0 deletions pkg/controllers/status/rb_status_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func (c *RBStatusController) SetupWithManager(mgr controllerruntime.Manager) err
})

return controllerruntime.NewControllerManagedBy(mgr).Named("resourceBinding_status_controller").
For(&workv1alpha2.ResourceBinding{}, rbPredicateFn).
Watches(&workv1alpha1.Work{}, handler.EnqueueRequestsFromMapFunc(workMapFunc), workPredicateFn).
WithOptions(controller.Options{RateLimiter: ratelimiterflag.DefaultControllerRateLimiter(c.RateLimiterOptions)}).
Complete(c)
Expand Down

0 comments on commit d6cc5b9

Please sign in to comment.