diff --git a/bundle/manifests/datasciencecluster.opendatahub.io_datascienceclusters.yaml b/bundle/manifests/datasciencecluster.opendatahub.io_datascienceclusters.yaml index 7ec8e179cd6..ade6d378fb4 100644 --- a/bundle/manifests/datasciencecluster.opendatahub.io_datascienceclusters.yaml +++ b/bundle/manifests/datasciencecluster.opendatahub.io_datascienceclusters.yaml @@ -966,6 +966,8 @@ spec: properties: name: type: string + ocpversion: + type: string version: type: string type: object diff --git a/bundle/manifests/dscinitialization.opendatahub.io_dscinitializations.yaml b/bundle/manifests/dscinitialization.opendatahub.io_dscinitializations.yaml index a4138f67837..d20a09eea08 100644 --- a/bundle/manifests/dscinitialization.opendatahub.io_dscinitializations.yaml +++ b/bundle/manifests/dscinitialization.opendatahub.io_dscinitializations.yaml @@ -304,6 +304,8 @@ spec: properties: name: type: string + ocpversion: + type: string version: type: string type: object diff --git a/config/crd/bases/datasciencecluster.opendatahub.io_datascienceclusters.yaml b/config/crd/bases/datasciencecluster.opendatahub.io_datascienceclusters.yaml index 6a1c89dea45..6f2b7d79dc0 100644 --- a/config/crd/bases/datasciencecluster.opendatahub.io_datascienceclusters.yaml +++ b/config/crd/bases/datasciencecluster.opendatahub.io_datascienceclusters.yaml @@ -966,6 +966,8 @@ spec: properties: name: type: string + ocpversion: + type: string version: type: string type: object diff --git a/config/crd/bases/dscinitialization.opendatahub.io_dscinitializations.yaml b/config/crd/bases/dscinitialization.opendatahub.io_dscinitializations.yaml index d1750a44756..6371d7c444b 100644 --- a/config/crd/bases/dscinitialization.opendatahub.io_dscinitializations.yaml +++ b/config/crd/bases/dscinitialization.opendatahub.io_dscinitializations.yaml @@ -304,6 +304,8 @@ spec: properties: name: type: string + ocpversion: + type: string version: type: string type: object diff --git a/controllers/components/kueue/kueue_controller.go b/controllers/components/kueue/kueue_controller.go index f6ba3da1b98..cdae3062171 100644 --- a/controllers/components/kueue/kueue_controller.go +++ b/controllers/components/kueue/kueue_controller.go @@ -63,11 +63,11 @@ func (s *componentHandler) NewComponentReconciler(ctx context.Context, mgr ctrl. // Owns(&admissionregistrationv1.ValidatingAdmissionPolicyBinding{}). WatchesGVK( gvk.ValidatingAdmissionPolicy, - reconciler.Dynamic(), + reconciler.Dynamic(vapPredicate), ). WatchesGVK( gvk.ValidatingAdmissionPolicyBinding, - reconciler.Dynamic(), + reconciler.Dynamic(vapPredicate), ). Owns(&appsv1.Deployment{}, reconciler.WithPredicates(resources.NewDeploymentPredicate())). Watches( diff --git a/controllers/components/kueue/kueue_controller_actions.go b/controllers/components/kueue/kueue_controller_actions.go index 8973943a961..4dd571afc1f 100644 --- a/controllers/components/kueue/kueue_controller_actions.go +++ b/controllers/components/kueue/kueue_controller_actions.go @@ -4,27 +4,17 @@ import ( "context" "fmt" - ctrl "sigs.k8s.io/controller-runtime" - componentApi "github.com/opendatahub-io/opendatahub-operator/v2/apis/components/v1alpha1" - "github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster" odhtypes "github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/types" odhdeploy "github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy" ) func initialize(ctx context.Context, rr *odhtypes.ReconciliationRequest) error { rr.Manifests = append(rr.Manifests, manifestsPath()) - // Add OCP 4.17+ specific manifests if Minor > 16 { - ov, err := cluster.GetOCPVersion(ctx, rr.Client) - if err != nil { - return fmt.Errorf("failed to get OCP version: %w", err) - } - ctrl.Log.Info("OCP: ", "version", ov.String()) - if ov.Minor > 16 { // it is safe to have to check only on minor, v3 has EOL last version is 11 - ctrl.Log.Info("OCP version is over 4.16") + // Add OCP 4.17+ specific manifests if Minor > 16 + if rr.Release.OCPVersion.Minor > 16 { 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 4632b0ca8ad..59edaf7f9e9 100644 --- a/controllers/components/kueue/kueue_support.go +++ b/controllers/components/kueue/kueue_support.go @@ -1,10 +1,13 @@ package kueue import ( + "context" + conditionsv1 "github.com/openshift/custom-resource-status/conditions/v1" componentApi "github.com/opendatahub-io/opendatahub-operator/v2/apis/components/v1alpha1" "github.com/opendatahub-io/opendatahub-operator/v2/controllers/status" + "github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster" odhtypes "github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/types" odhdeploy "github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy" ) @@ -41,3 +44,8 @@ func extramanifestsPath() odhtypes.ManifestInfo { SourcePath: "rhoai/ocp-4.17-addons", } } + +// Add OCP 4.17+ specific manifests if Minor > 16 . +func vapPredicate(context.Context, *odhtypes.ReconciliationRequest) bool { + return cluster.GetRelease().OCPVersion.Minor > 16 +} diff --git a/pkg/cluster/cluster_config.go b/pkg/cluster/cluster_config.go index aa3503964c7..d97767ee2af 100644 --- a/pkg/cluster/cluster_config.go +++ b/pkg/cluster/cluster_config.go @@ -28,8 +28,9 @@ type Platform string // Release includes information on operator version and platform // +kubebuilder:object:generate=true type Release struct { - Name Platform `json:"name,omitempty"` - Version version.OperatorVersion `json:"version,omitempty"` + Name Platform `json:"name,omitempty"` + Version version.OperatorVersion `json:"version,omitempty"` + OCPVersion version.OperatorVersion `json:"ocpversion,omitempty"` // would like to just use semversion but it does not has deepcopy... } var clusterConfig struct { @@ -95,14 +96,18 @@ func GetDomain(ctx context.Context, c client.Client) (string, error) { return domain, err } -func GetOCPVersion(ctx context.Context, c client.Client) (semver.Version, error) { +func getOCPVersion(ctx context.Context, c client.Client) (version.OperatorVersion, error) { clusterVersion := &configv1.ClusterVersion{} if err := c.Get(ctx, client.ObjectKey{ - Name: "version", + Name: OpenShiftVersionObj, }, clusterVersion); err != nil { - return semver.Version{}, errors.New("unable to get OCP version") + return version.OperatorVersion{}, errors.New("unable to get OCP version") } - return semver.Make(clusterVersion.Status.History[0].Version) + v, err := semver.ParseTolerant(clusterVersion.Status.History[0].Version) + if err != nil { + return version.OperatorVersion{}, errors.New("unable to parse OCP version") + } + return version.OperatorVersion{Version: v}, nil } func getOperatorNamespace() (string, error) { @@ -209,6 +214,13 @@ func getRelease(ctx context.Context, cli client.Client) (Release, error) { Version: semver.Version{}, }, } + // Set OCP + ocpVersion, err := getOCPVersion(ctx, cli) + if err != nil { + return initRelease, err + } + initRelease.OCPVersion = ocpVersion + // Set platform platform, err := getPlatform(ctx, cli) if err != nil { diff --git a/pkg/cluster/const.go b/pkg/cluster/const.go index 6a6562bff07..af8242ded2d 100644 --- a/pkg/cluster/const.go +++ b/pkg/cluster/const.go @@ -15,4 +15,7 @@ const ( // Default cluster-scope Authentication CR name. ClusterAuthenticationObj = "cluster" + + // Default OpenShift version CR name. + OpenShiftVersionObj = "version" ) diff --git a/pkg/cluster/zz_generated.deepcopy.go b/pkg/cluster/zz_generated.deepcopy.go index 0bc3e0f557d..af3db0e96ce 100644 --- a/pkg/cluster/zz_generated.deepcopy.go +++ b/pkg/cluster/zz_generated.deepcopy.go @@ -26,6 +26,7 @@ import () func (in *Release) DeepCopyInto(out *Release) { *out = *in in.Version.DeepCopyInto(&out.Version) + in.OCPVersion.DeepCopyInto(&out.OCPVersion) } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Release. diff --git a/tests/e2e/kueue_test.go b/tests/e2e/kueue_test.go index c159cc071f3..75f742f9877 100644 --- a/tests/e2e/kueue_test.go +++ b/tests/e2e/kueue_test.go @@ -15,6 +15,7 @@ import ( corev1 "k8s.io/api/core/v1" k8serr "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/wait" "k8s.io/client-go/util/retry" @@ -59,6 +60,11 @@ func kueueTestSuite(t *testing.T) { require.NoError(t, err, "error getting all Kueue's Ownerrefrences") }) + t.Run("Validate Kueue Dynamically create VAP", func(t *testing.T) { + err = kueueCtx.validateVAPReady() + require.NoError(t, err, "Kueue instance is not Ready") + }) + t.Run("Validate Kueue Ready", func(t *testing.T) { err = kueueCtx.validateKueueReady() require.NoError(t, err, "Kueue instance is not Ready") @@ -164,6 +170,29 @@ func (tc *KueueTestCtx) testOwnerReferences() error { return nil } +func (tc *KueueTestCtx) validateVAPReady() error { + // get OCP version from DSC + keydsc := types.NamespacedName{Name: "default-dsc"} + dsc := &dscv1.DataScienceCluster{} + err := tc.testCtx.customClient.Get(tc.testCtx.ctx, keydsc, dsc) + if err != nil { + return fmt.Errorf("expect one DSC CR to be found but got error: %w", err) + } + + // if ocp is 4.17+ then VAP should be created. + if dsc.Status.Release.OCPVersion.Minor > 16 { + keyvap := types.NamespacedName{Name: "kueue-validating-admission-policy"} + vap := &unstructured.Unstructured{} + vap.SetGroupVersionKind(gvk.ValidatingAdmissionPolicy) + + err := tc.testCtx.customClient.Get(tc.testCtx.ctx, keyvap, vap) + if err != nil { + return fmt.Errorf("expect validatingadminssionpolicy to be found but got error: %w", err) + } + } + return nil +} + // Verify Kueue instance is in Ready phase when kueue deployments are up and running. func (tc *KueueTestCtx) validateKueueReady() error { err := wait.PollUntilContextTimeout(tc.testCtx.ctx, generalRetryInterval, componentReadyTimeout, true, func(ctx context.Context) (bool, error) {