Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
Signed-off-by: Wen Zhou <wenzhou@redhat.com>
  • Loading branch information
zdtsw committed Jan 14, 2025
1 parent d200a2e commit ba4bb88
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 27 deletions.
2 changes: 0 additions & 2 deletions controllers/components/kueue/kueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import (

type componentHandler struct{}

var enableVAP bool

func init() { //nolint:gochecknoinits
cr.Add(&componentHandler{})
}
Expand Down
24 changes: 9 additions & 15 deletions controllers/components/kueue/kueue_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}).
Expand All @@ -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{},
Expand All @@ -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
}

Expand Down
8 changes: 5 additions & 3 deletions controllers/components/kueue/kueue_controller_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
7 changes: 0 additions & 7 deletions controllers/components/kueue/kueue_support.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
}

0 comments on commit ba4bb88

Please sign in to comment.