Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions controllers/ocmagent/ocmagent_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,12 @@ func (r *OcmAgentReconciler) Reconcile(ctx context.Context, request reconcile.Re
}
}

// Periodically reconcile to check for pull-secret changes
// Since we can't watch openshift-config/pull-secret (due to RBAC/cache issues),
// we reconcile every 5 minutes to detect changes
// Periodically reconcile to detect pull-secret or proxy config drift
return reconcile.Result{RequeueAfter: ctrlconst.SyncPeriodDefault}, nil
}

// SetupWithManager sets up the controller with the Manager.
func (r *OcmAgentReconciler) SetupWithManager(mgr ctrl.Manager) error {
// Note: We use periodic reconciliation instead of watching pull-secret
// due to RBAC/cache issues with openshift-config namespace

return ctrl.NewControllerManagedBy(mgr).
For(&ocmagentv1alpha1.OcmAgent{}).
Owns(&netv1.NetworkPolicy{}).
Expand Down
27 changes: 19 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ import (
// to ensure that exec-entrypoint and run can make use of them.
_ "k8s.io/client-go/plugin/pkg/client/auth"

corev1 "k8s.io/api/core/v1"
apiruntime "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/fields"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"

Expand Down Expand Up @@ -146,6 +148,22 @@ func main() {
DefaultNamespaces: map[string]cache.Config{
operatorNS: {},
},
ByObject: map[client.Object]cache.ByObject{
&corev1.Secret{}: {
Namespaces: map[string]cache.Config{
"openshift-config": {
FieldSelector: fields.OneTermEqualSelector("metadata.name", "pull-secret"),
},
},
},
&corev1.ConfigMap{}: {
Namespaces: map[string]cache.Config{
"openshift-monitoring": {
FieldSelector: fields.OneTermEqualSelector("metadata.name", "ocm-agent"),
},
},
},
},
},
Scheme: scheme,
Metrics: metricsserver.Options{
Expand All @@ -162,17 +180,10 @@ func main() {
os.Exit(1)
}

// Create a separate client for the OAH Builder
kubeConfig := ctrl.GetConfigOrDie()
handlerClient, err := client.New(kubeConfig, client.Options{Scheme: mgr.GetScheme()})
if err != nil {
os.Exit(1)
}

if err = (&ocmagent.OcmAgentReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
OCMAgentHandlerBuilder: ocmagenthandler.NewBuilder(handlerClient),
OCMAgentHandlerBuilder: ocmagenthandler.NewBuilder(mgr.GetClient()),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "OcmAgent")
os.Exit(1)
Expand Down