Skip to content

Commit

Permalink
Merge pull request #3112 from Josh-Tigera/josh.policyrec-mt-watches
Browse files Browse the repository at this point in the history
PolicyRecommendation should enqueue global resource watched object ch…
  • Loading branch information
marvin-tigera authored Jan 11, 2024
2 parents f45194d + 89a73ca commit a0c7471
Showing 1 changed file with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ func Add(mgr manager.Manager, opts options.AddOptions) error {
return err
}

// Determine how to handle watch events for cluster-scoped resources. For multi-tenant clusters,
// we should update all tenants whenever one changes. For single-tenant clusters, we can just queue the object.
var eventHandler handler.EventHandler = &handler.EnqueueRequestForObject{}
if opts.MultiTenant {
eventHandler = utils.EnqueueAllTenants(mgr.GetClient())
if err = policyRecController.Watch(&source.Kind{Type: &operatorv1.Tenant{}}, &handler.EnqueueRequestForObject{}); err != nil {
return fmt.Errorf("policy-recommendation-controller failed to watch Tenant resource: %w", err)
}
}

installNS, _, watchNamespaces := tenancy.GetWatchNamespaces(opts.MultiTenant, render.PolicyRecommendationNamespace)

go utils.WaitToAddLicenseKeyWatch(policyRecController, k8sClient, log, licenseAPIReady)
Expand All @@ -98,15 +108,15 @@ func Add(mgr manager.Manager, opts options.AddOptions) error {
return err
}

if err = utils.AddInstallationWatch(policyRecController); err != nil {
if err = policyRecController.Watch(&source.Kind{Type: &operatorv1.Installation{}}, eventHandler); err != nil {
return fmt.Errorf("policy-recommendation-controller failed to watch Installation resource: %w", err)
}

if err = imageset.AddImageSetWatch(policyRecController); err != nil {
if err = policyRecController.Watch(&source.Kind{Type: &operatorv1.ImageSet{}}, eventHandler); err != nil {
return fmt.Errorf("policy-recommendation-controller failed to watch ImageSet: %w", err)
}

if err = utils.AddAPIServerWatch(policyRecController); err != nil {
if err = policyRecController.Watch(&source.Kind{Type: &operatorv1.APIServer{}}, eventHandler); err != nil {
return fmt.Errorf("policy-recommendation-controller failed to watch APIServer resource: %w", err)
}

Expand All @@ -124,13 +134,11 @@ func Add(mgr manager.Manager, opts options.AddOptions) error {
}
}

err = policyRecController.Watch(&source.Kind{Type: &operatorv1.ManagementCluster{}}, &handler.EnqueueRequestForObject{})
if err != nil {
if err = policyRecController.Watch(&source.Kind{Type: &operatorv1.ManagementCluster{}}, eventHandler); err != nil {
return fmt.Errorf("policy-recommendation-controller failed to watch ManagementCluster resource: %w", err)
}

err = policyRecController.Watch(&source.Kind{Type: &operatorv1.ManagementClusterConnection{}}, &handler.EnqueueRequestForObject{})
if err != nil {
if err = policyRecController.Watch(&source.Kind{Type: &operatorv1.ManagementClusterConnection{}}, eventHandler); err != nil {
return fmt.Errorf("policy-recommendation-controller failed to watch ManagementClusterConnection resource: %w", err)
}

Expand Down

0 comments on commit a0c7471

Please sign in to comment.