Skip to content

Commit

Permalink
fix config by pod status not updating issue
Browse files Browse the repository at this point in the history
Signed-off-by: Avinash Patnala <[email protected]>
  • Loading branch information
Avinash Patnala committed Sep 20, 2024
1 parent a240878 commit d545b1f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
7 changes: 7 additions & 0 deletions pkg/controller/config/config_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
cm "github.com/open-policy-agent/gatekeeper/v3/pkg/cachemanager"
"github.com/open-policy-agent/gatekeeper/v3/pkg/cachemanager/aggregator"
"github.com/open-policy-agent/gatekeeper/v3/pkg/controller/config/process"
"github.com/open-policy-agent/gatekeeper/v3/pkg/controller/configstatus"
"github.com/open-policy-agent/gatekeeper/v3/pkg/keys"
"github.com/open-policy-agent/gatekeeper/v3/pkg/readiness"
"github.com/open-policy-agent/gatekeeper/v3/pkg/util"
Expand Down Expand Up @@ -118,6 +119,12 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error {
return err
}

err = c.Watch(
source.Kind(mgr.GetCache(), &statusv1beta1.ConfigPodStatus{}, handler.TypedEnqueueRequestsFromMapFunc(configstatus.PodStatusToConfigMapper(true, util.EventPackerMapFunc()))))
if err != nil {
return err
}

return nil
}

Expand Down
14 changes: 7 additions & 7 deletions pkg/controller/configstatus/configstatus_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@ func newReconciler(mgr manager.Manager) reconcile.Reconciler {
}
}

type PackerMap func(obj client.Object) []reconcile.Request

// PodStatusToConfigMapper correlates a ConfigPodStatus with its corresponding Config.
// `selfOnly` tells the mapper to only map statuses corresponding to the current pod.
func PodStatusToConfigMapper(selfOnly bool) handler.TypedMapFunc[*v1beta1.ConfigPodStatus] {
return func(_ context.Context, obj *v1beta1.ConfigPodStatus) []reconcile.Request {
func PodStatusToConfigMapper(selfOnly bool, packerMap handler.MapFunc) handler.TypedMapFunc[*v1beta1.ConfigPodStatus] {
return func(ctx context.Context, obj *v1beta1.ConfigPodStatus) []reconcile.Request {
labels := obj.GetLabels()
name, ok := labels[v1beta1.ConfigNameLabel]
if !ok {
Expand Down Expand Up @@ -101,16 +103,14 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error {
return err
}

// Watch for changes to ExpansionTemplateStatus
// Watch for changes to ConfigStatus
err = c.Watch(
source.Kind(mgr.GetCache(), &v1beta1.ConfigPodStatus{},
handler.TypedEnqueueRequestsFromMapFunc(PodStatusToConfigMapper(false)),
))
source.Kind(mgr.GetCache(), &v1beta1.ConfigPodStatus{}, handler.TypedEnqueueRequestsFromMapFunc(PodStatusToConfigMapper(false, util.EventPackerMapFunc()))))
if err != nil {
return err
}

// Watch for changes to ExpansionTemplate
// Watch for changes to Config
err = c.Watch(source.Kind(mgr.GetCache(), &configv1alpha1.Config{}, &handler.TypedEnqueueRequestForObject[*configv1alpha1.Config]{}))
if err != nil {
return err
Expand Down

0 comments on commit d545b1f

Please sign in to comment.