diff --git a/controllers/components/kueue/kueue.go b/controllers/components/kueue/kueue.go index 2c2f2bdafb3..23287e9898f 100644 --- a/controllers/components/kueue/kueue.go +++ b/controllers/components/kueue/kueue.go @@ -23,8 +23,6 @@ import ( type componentHandler struct{} -var enableVAP bool - func init() { //nolint:gochecknoinits cr.Add(&componentHandler{}) } diff --git a/controllers/components/kueue/kueue_controller.go b/controllers/components/kueue/kueue_controller.go index 58fde2339ed..37da9104d0f 100644 --- a/controllers/components/kueue/kueue_controller.go +++ b/controllers/components/kueue/kueue_controller.go @@ -44,8 +44,7 @@ import ( ) func (s *componentHandler) NewComponentReconciler(ctx context.Context, mgr ctrl.Manager) error { - enableVAP = cluster.GetClusterInfo().Version.GTE(semver.MustParse("4.17.0")) - _, err := reconciler.ReconcilerFor(mgr, &componentApi.Kueue{}). + b := reconciler.ReconcilerFor(mgr, &componentApi.Kueue{}). // customized Owns() for Component with new predicates Owns(&corev1.ConfigMap{}). Owns(&corev1.Secret{}). @@ -60,16 +59,6 @@ func (s *componentHandler) NewComponentReconciler(ctx context.Context, mgr ctrl. Owns(&promv1.PrometheusRule{}). Owns(&admissionregistrationv1.MutatingWebhookConfiguration{}). Owns(&admissionregistrationv1.ValidatingWebhookConfiguration{}). - // We need dynamically "watch" VAP, because we want it to be configable by user and it can be left behind when kueue is removed. - OwnsGVK( - gvk.ValidatingAdmissionPolicy, - reconciler.Dynamic(vapPredicate), - ). - // We need dynamically "own" VAPB, because we want it has owner so when kueue is removed it gets cleaned. - WatchesGVK( - gvk.ValidatingAdmissionPolicyBinding, - reconciler.Dynamic(vapPredicate), - ). Owns(&appsv1.Deployment{}, reconciler.WithPredicates(resources.NewDeploymentPredicate())). Watches( &extv1.CustomResourceDefinition{}, @@ -92,10 +81,15 @@ func (s *componentHandler) NewComponentReconciler(ctx context.Context, mgr ctrl. )). WithAction(updatestatus.NewAction()). // must be the final action - WithAction(gc.NewAction()). - Build(ctx) + WithAction(gc.NewAction()) + + if cluster.GetClusterInfo().Version.GTE(semver.MustParse("4.17.0")) { + b = b.OwnsGVK(gvk.ValidatingAdmissionPolicy) // "own" VAP, because we want it has owner so when kueue is removed it gets cleaned. + b = b.WatchesGVK(gvk.ValidatingAdmissionPolicyBinding) // "watch" VAPB, because we want it to be configable by user and it can be left behind when kueue is remov + b = b.WithAction(extraInitialize) + } - if err != nil { + if _, err := b.Build(ctx); err != nil { return err // no need customize error, it is done in the caller main } diff --git a/controllers/components/kueue/kueue_controller_actions.go b/controllers/components/kueue/kueue_controller_actions.go index 4e0c506d303..d8324f5ed6c 100644 --- a/controllers/components/kueue/kueue_controller_actions.go +++ b/controllers/components/kueue/kueue_controller_actions.go @@ -14,10 +14,12 @@ import ( func initialize(_ context.Context, rr *odhtypes.ReconciliationRequest) error { rr.Manifests = append(rr.Manifests, manifestsPath()) + return nil +} + +func extraInitialize(_ context.Context, rr *odhtypes.ReconciliationRequest) error { // Add specific manifests if OCP is greater or equal 4.17. - if enableVAP { - rr.Manifests = append(rr.Manifests, extramanifestsPath()) - } + rr.Manifests = append(rr.Manifests, extramanifestsPath()) return nil } diff --git a/controllers/components/kueue/kueue_support.go b/controllers/components/kueue/kueue_support.go index ca5980a72f4..4632b0ca8ad 100644 --- a/controllers/components/kueue/kueue_support.go +++ b/controllers/components/kueue/kueue_support.go @@ -1,8 +1,6 @@ package kueue import ( - "context" - conditionsv1 "github.com/openshift/custom-resource-status/conditions/v1" componentApi "github.com/opendatahub-io/opendatahub-operator/v2/apis/components/v1alpha1" @@ -43,8 +41,3 @@ func extramanifestsPath() odhtypes.ManifestInfo { SourcePath: "rhoai/ocp-4.17-addons", } } - -// return true if OCP is greater or equal 4.17. -func vapPredicate(context.Context, *odhtypes.ReconciliationRequest) bool { - return enableVAP -}