From 199dc92e93d698588f8b8b229f69222ab7cf9633 Mon Sep 17 00:00:00 2001 From: Yauheni Kaliuta Date: Mon, 19 Aug 2024 14:50:45 +0300 Subject: [PATCH] components: move params.env image updating to Init stage Jira: https://issues.redhat.com/browse/RHOAIENG-11592 Image names in environment are not supposed to be changed during runtime of the operator, so it makes sense to update them only on startup. If manifests are overriden by DevFlags, the DevFlags' version will be used. The change is straight forward for most of the components where only images are updated and params.env is located in the kustomize root directory, but some components (dashboard, ray, codeflare, modelregistry) also update some extra parameters. For them image part only is moved to Init since other updates require runtime DSCI information. The patch also changes logic for ray, codeflare, and modelregistry in this regard to update non-image parameters regardless of DevFlags like it was changed in dashboard recently. The DevFlags functionality brings some concerns: - For most components the code is written such a way that as soon as DevFlags supplied the global path variables are changed and never reverted back to the defaults. For some (dashboard, trustyai) there is (still global) OverridePath/entryPath pair and manifests reverted to the default, BUT there is no logic of transition. - codeflare: when manifests are overridden namespace param is updated in the hardcoded (stock) path; This logic is preserved. Signed-off-by: Yauheni Kaliuta --- components/codeflare/codeflare.go | 26 ++++++--- components/dashboard/dashboard.go | 47 ++++++++++++---- .../datasciencepipelines.go | 55 ++++++++++--------- components/kserve/kserve.go | 28 ++++++---- components/kueue/kueue.go | 23 +++++--- .../modelmeshserving/modelmeshserving.go | 55 ++++++++++--------- components/modelregistry/modelregistry.go | 35 +++++++----- components/ray/ray.go | 24 +++++--- .../trainingoperator/trainingoperator.go | 24 +++++--- components/trustyai/trustyai.go | 40 ++++++++------ components/workbenches/workbenches.go | 38 +++++++------ 11 files changed, 244 insertions(+), 151 deletions(-) diff --git a/components/codeflare/codeflare.go b/components/codeflare/codeflare.go index 534e58c319e..ad3d15b168f 100644 --- a/components/codeflare/codeflare.go +++ b/components/codeflare/codeflare.go @@ -12,6 +12,7 @@ import ( operatorv1 "github.com/openshift/api/operator/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/client" + logf "sigs.k8s.io/controller-runtime/pkg/log" dsciv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1" "github.com/opendatahub-io/opendatahub-operator/v2/components" @@ -35,6 +36,20 @@ type CodeFlare struct { components.Component `json:""` } +func (c *CodeFlare) Init(ctx context.Context, _ cluster.Platform) error { + log := logf.FromContext(ctx).WithName(ComponentName) + + var imageParamMap = map[string]string{ + "codeflare-operator-controller-image": "RELATED_IMAGE_ODH_CODEFLARE_OPERATOR_IMAGE", // no need mcad, embedded in cfo + } + + if err := deploy.ApplyParams(ParamsPath, imageParamMap); err != nil { + log.Error(err, "failed to update image", "path", CodeflarePath+"/bases") + } + + return nil +} + func (c *CodeFlare) OverrideManifests(ctx context.Context, _ cluster.Platform) error { // If devflags are set, update default manifests path if len(c.DevFlags.Manifests) != 0 { @@ -65,9 +80,6 @@ func (c *CodeFlare) ReconcileComponent(ctx context.Context, platform cluster.Platform, _ bool) error { l := c.ConfigComponentLogger(logger, ComponentName, dscispec) - var imageParamMap = map[string]string{ - "codeflare-operator-controller-image": "RELATED_IMAGE_ODH_CODEFLARE_OPERATOR_IMAGE", // no need mcad, embedded in cfo - } enabled := c.GetManagementState() == operatorv1.Managed monitoringEnabled := dscispec.Monitoring.ManagementState == operatorv1.Managed @@ -90,11 +102,9 @@ func (c *CodeFlare) ReconcileComponent(ctx context.Context, dependentOperator, ComponentName) } - // Update image parameters only when we do not have customized manifests set - if (dscispec.DevFlags == nil || dscispec.DevFlags.ManifestsUri == "") && (c.DevFlags == nil || len(c.DevFlags.Manifests) == 0) { - if err := deploy.ApplyParams(ParamsPath, imageParamMap, map[string]string{"namespace": dscispec.ApplicationsNamespace}); err != nil { - return fmt.Errorf("failed update image from %s : %w", CodeflarePath+"/bases", err) - } + // It updates stock manifests, overridden manifests should contain proper namespace + if err := deploy.ApplyParams(ParamsPath, nil, map[string]string{"namespace": dscispec.ApplicationsNamespace}); err != nil { + return fmt.Errorf("failed update image from %s : %w", CodeflarePath+"/bases", err) } } diff --git a/components/dashboard/dashboard.go b/components/dashboard/dashboard.go index 1392e25e0fb..ca450799a2c 100644 --- a/components/dashboard/dashboard.go +++ b/components/dashboard/dashboard.go @@ -15,6 +15,7 @@ import ( k8serr "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/client" + logf "sigs.k8s.io/controller-runtime/pkg/log" dsciv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1" "github.com/opendatahub-io/opendatahub-operator/v2/components" @@ -31,6 +32,7 @@ var ( PathSelfDownstream = PathDownstream + "/onprem" PathManagedDownstream = PathDownstream + "/addon" OverridePath = "" + DefaultPath = "" ) // Verifies that Dashboard implements ComponentInterface. @@ -42,6 +44,38 @@ type Dashboard struct { components.Component `json:""` } +func componentName(platform cluster.Platform) string { + var name string + switch platform { + case cluster.SelfManagedRhods, cluster.ManagedRhods: + name = ComponentNameDownstream + default: + name = ComponentNameUpstream + } + + return name +} + +func (d *Dashboard) Init(ctx context.Context, platform cluster.Platform) error { + log := logf.FromContext(ctx).WithName(componentName(platform)) + + imageParamMap := map[string]string{ + "odh-dashboard-image": "RELATED_IMAGE_ODH_DASHBOARD_IMAGE", + } + DefaultPath := map[cluster.Platform]string{ + cluster.SelfManagedRhods: PathDownstream + "/onprem", + cluster.ManagedRhods: PathDownstream + "/addon", + cluster.OpenDataHub: PathUpstream, + cluster.Unknown: PathUpstream, + }[platform] + + if err := deploy.ApplyParams(DefaultPath, imageParamMap); err != nil { + log.Error(err, "failed to update image", "path", DefaultPath) + } + + return nil +} + func (d *Dashboard) OverrideManifests(ctx context.Context, platform cluster.Platform) error { // If devflags are set, update default manifests path if len(d.DevFlags.Manifests) != 0 { @@ -76,16 +110,9 @@ func (d *Dashboard) ReconcileComponent(ctx context.Context, l = d.ConfigComponentLogger(logger, ComponentNameUpstream, dscispec) } - entryPath := map[cluster.Platform]string{ - cluster.SelfManagedRhods: PathDownstream + "/onprem", - cluster.ManagedRhods: PathDownstream + "/addon", - cluster.OpenDataHub: PathUpstream, - cluster.Unknown: PathUpstream, - }[platform] - + entryPath := DefaultPath enabled := d.GetManagementState() == operatorv1.Managed monitoringEnabled := dscispec.Monitoring.ManagementState == operatorv1.Managed - imageParamMap := make(map[string]string) if enabled { // 1. cleanup OAuth client related secret and CR if dashboard is in 'installed false' status @@ -100,8 +127,6 @@ func (d *Dashboard) ReconcileComponent(ctx context.Context, if OverridePath != "" { entryPath = OverridePath } - } else { // Update image parameters if devFlags is not provided - imageParamMap["odh-dashboard-image"] = "RELATED_IMAGE_ODH_DASHBOARD_IMAGE" } // 2. platform specific RBAC @@ -122,7 +147,7 @@ func (d *Dashboard) ReconcileComponent(ctx context.Context, } // 4. update params.env regardless devFlags is provided of not - if err := deploy.ApplyParams(entryPath, imageParamMap, extraParamsMap); err != nil { + if err := deploy.ApplyParams(entryPath, nil, extraParamsMap); err != nil { return fmt.Errorf("failed to update params.env from %s : %w", entryPath, err) } } diff --git a/components/datasciencepipelines/datasciencepipelines.go b/components/datasciencepipelines/datasciencepipelines.go index 388b54bd707..3cece8a45d0 100644 --- a/components/datasciencepipelines/datasciencepipelines.go +++ b/components/datasciencepipelines/datasciencepipelines.go @@ -16,6 +16,7 @@ import ( k8serr "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/client" + logf "sigs.k8s.io/controller-runtime/pkg/log" dsciv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1" "github.com/opendatahub-io/opendatahub-operator/v2/components" @@ -41,6 +42,35 @@ type DataSciencePipelines struct { components.Component `json:""` } +func (d *DataSciencePipelines) Init(ctx context.Context, _ cluster.Platform) error { + log := logf.FromContext(ctx).WithName(ComponentName) + + var imageParamMap = map[string]string{ + // v1 + "IMAGES_APISERVER": "RELATED_IMAGE_ODH_ML_PIPELINES_API_SERVER_IMAGE", + "IMAGES_ARTIFACT": "RELATED_IMAGE_ODH_ML_PIPELINES_ARTIFACT_MANAGER_IMAGE", + "IMAGES_PERSISTENTAGENT": "RELATED_IMAGE_ODH_ML_PIPELINES_PERSISTENCEAGENT_IMAGE", + "IMAGES_SCHEDULEDWORKFLOW": "RELATED_IMAGE_ODH_ML_PIPELINES_SCHEDULEDWORKFLOW_IMAGE", + "IMAGES_CACHE": "RELATED_IMAGE_ODH_ML_PIPELINES_CACHE_IMAGE", + "IMAGES_DSPO": "RELATED_IMAGE_ODH_DATA_SCIENCE_PIPELINES_OPERATOR_CONTROLLER_IMAGE", + // v2 + "IMAGESV2_ARGO_APISERVER": "RELATED_IMAGE_ODH_ML_PIPELINES_API_SERVER_V2_IMAGE", + "IMAGESV2_ARGO_PERSISTENCEAGENT": "RELATED_IMAGE_ODH_ML_PIPELINES_PERSISTENCEAGENT_V2_IMAGE", + "IMAGESV2_ARGO_SCHEDULEDWORKFLOW": "RELATED_IMAGE_ODH_ML_PIPELINES_SCHEDULEDWORKFLOW_V2_IMAGE", + "IMAGESV2_ARGO_ARGOEXEC": "RELATED_IMAGE_ODH_DATA_SCIENCE_PIPELINES_ARGO_ARGOEXEC_IMAGE", + "IMAGESV2_ARGO_WORKFLOWCONTROLLER": "RELATED_IMAGE_ODH_DATA_SCIENCE_PIPELINES_ARGO_WORKFLOWCONTROLLER_IMAGE", + "V2_DRIVER_IMAGE": "RELATED_IMAGE_ODH_ML_PIPELINES_DRIVER_IMAGE", + "V2_LAUNCHER_IMAGE": "RELATED_IMAGE_ODH_ML_PIPELINES_LAUNCHER_IMAGE", + "IMAGESV2_ARGO_MLMDGRPC": "RELATED_IMAGE_ODH_MLMD_GRPC_SERVER_IMAGE", + } + + if err := deploy.ApplyParams(Path, imageParamMap); err != nil { + log.Error(err, "failed to update image", "path", Path) + } + + return nil +} + func (d *DataSciencePipelines) OverrideManifests(ctx context.Context, _ cluster.Platform) error { // If devflags are set, update default manifests path if len(d.DevFlags.Manifests) != 0 { @@ -72,25 +102,6 @@ func (d *DataSciencePipelines) ReconcileComponent(ctx context.Context, _ bool, ) error { l := d.ConfigComponentLogger(logger, ComponentName, dscispec) - var imageParamMap = map[string]string{ - // v1 - "IMAGES_APISERVER": "RELATED_IMAGE_ODH_ML_PIPELINES_API_SERVER_IMAGE", - "IMAGES_ARTIFACT": "RELATED_IMAGE_ODH_ML_PIPELINES_ARTIFACT_MANAGER_IMAGE", - "IMAGES_PERSISTENTAGENT": "RELATED_IMAGE_ODH_ML_PIPELINES_PERSISTENCEAGENT_IMAGE", - "IMAGES_SCHEDULEDWORKFLOW": "RELATED_IMAGE_ODH_ML_PIPELINES_SCHEDULEDWORKFLOW_IMAGE", - "IMAGES_CACHE": "RELATED_IMAGE_ODH_ML_PIPELINES_CACHE_IMAGE", - "IMAGES_DSPO": "RELATED_IMAGE_ODH_DATA_SCIENCE_PIPELINES_OPERATOR_CONTROLLER_IMAGE", - // v2 - "IMAGESV2_ARGO_APISERVER": "RELATED_IMAGE_ODH_ML_PIPELINES_API_SERVER_V2_IMAGE", - "IMAGESV2_ARGO_PERSISTENCEAGENT": "RELATED_IMAGE_ODH_ML_PIPELINES_PERSISTENCEAGENT_V2_IMAGE", - "IMAGESV2_ARGO_SCHEDULEDWORKFLOW": "RELATED_IMAGE_ODH_ML_PIPELINES_SCHEDULEDWORKFLOW_V2_IMAGE", - "IMAGESV2_ARGO_ARGOEXEC": "RELATED_IMAGE_ODH_DATA_SCIENCE_PIPELINES_ARGO_ARGOEXEC_IMAGE", - "IMAGESV2_ARGO_WORKFLOWCONTROLLER": "RELATED_IMAGE_ODH_DATA_SCIENCE_PIPELINES_ARGO_WORKFLOWCONTROLLER_IMAGE", - "V2_DRIVER_IMAGE": "RELATED_IMAGE_ODH_ML_PIPELINES_DRIVER_IMAGE", - "V2_LAUNCHER_IMAGE": "RELATED_IMAGE_ODH_ML_PIPELINES_LAUNCHER_IMAGE", - "IMAGESV2_ARGO_MLMDGRPC": "RELATED_IMAGE_ODH_MLMD_GRPC_SERVER_IMAGE", - } - enabled := d.GetManagementState() == operatorv1.Managed monitoringEnabled := dscispec.Monitoring.ManagementState == operatorv1.Managed @@ -102,12 +113,6 @@ func (d *DataSciencePipelines) ReconcileComponent(ctx context.Context, } } // skip check if the dependent operator has beeninstalled, this is done in dashboard - // Update image parameters only when we do not have customized manifests set - if (dscispec.DevFlags == nil || dscispec.DevFlags.ManifestsUri == "") && (d.DevFlags == nil || len(d.DevFlags.Manifests) == 0) { - if err := deploy.ApplyParams(Path, imageParamMap); err != nil { - return fmt.Errorf("failed to update image from %s : %w", Path, err) - } - } // Check for existing Argo Workflows if err := UnmanagedArgoWorkFlowExists(ctx, cli); err != nil { return err diff --git a/components/kserve/kserve.go b/components/kserve/kserve.go index a04bd17dd9f..53b44164b40 100644 --- a/components/kserve/kserve.go +++ b/components/kserve/kserve.go @@ -12,6 +12,7 @@ import ( operatorv1 "github.com/openshift/api/operator/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/client" + logf "sigs.k8s.io/controller-runtime/pkg/log" dsciv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1" infrav1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/infrastructure/v1" @@ -56,6 +57,22 @@ type Kserve struct { DefaultDeploymentMode DefaultDeploymentMode `json:"defaultDeploymentMode,omitempty"` } +func (k *Kserve) Init(ctx context.Context, _ cluster.Platform) error { + log := logf.FromContext(ctx).WithName(ComponentName) + + // dependentParamMap for odh-model-controller to use. + var dependentParamMap = map[string]string{ + "odh-model-controller": "RELATED_IMAGE_ODH_MODEL_CONTROLLER_IMAGE", + } + + // Update image parameters for odh-model-controller + if err := deploy.ApplyParams(DependentPath, dependentParamMap); err != nil { + log.Error(err, "failed to update image", "path", DependentPath) + } + + return nil +} + func (k *Kserve) OverrideManifests(ctx context.Context, _ cluster.Platform) error { // Download manifests if defined by devflags // Go through each manifest and set the overlays if defined @@ -98,11 +115,6 @@ func (k *Kserve) ReconcileComponent(ctx context.Context, cli client.Client, logger logr.Logger, owner metav1.Object, dscispec *dsciv1.DSCInitializationSpec, platform cluster.Platform, _ bool) error { l := k.ConfigComponentLogger(logger, ComponentName, dscispec) - // dependentParamMap for odh-model-controller to use. - var dependentParamMap = map[string]string{ - "odh-model-controller": "RELATED_IMAGE_ODH_MODEL_CONTROLLER_IMAGE", - } - enabled := k.GetManagementState() == operatorv1.Managed monitoringEnabled := dscispec.Monitoring.ManagementState == operatorv1.Managed @@ -142,12 +154,6 @@ func (k *Kserve) ReconcileComponent(ctx context.Context, cli client.Client, if err := cluster.UpdatePodSecurityRolebinding(ctx, cli, dscispec.ApplicationsNamespace, "odh-model-controller"); err != nil { return err } - // Update image parameters for odh-model-controller - if (dscispec.DevFlags == nil || dscispec.DevFlags.ManifestsUri == "") && (k.DevFlags == nil || len(k.DevFlags.Manifests) == 0) { - if err := deploy.ApplyParams(DependentPath, dependentParamMap); err != nil { - return fmt.Errorf("failed to update image %s: %w", DependentPath, err) - } - } } if err := deploy.DeployManifestsFromPath(ctx, cli, owner, DependentPath, dscispec.ApplicationsNamespace, ComponentName, enabled); err != nil { diff --git a/components/kueue/kueue.go b/components/kueue/kueue.go index 81bdbfe5638..2cc126220aa 100644 --- a/components/kueue/kueue.go +++ b/components/kueue/kueue.go @@ -10,6 +10,7 @@ import ( operatorv1 "github.com/openshift/api/operator/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/client" + logf "sigs.k8s.io/controller-runtime/pkg/log" dsciv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1" "github.com/opendatahub-io/opendatahub-operator/v2/components" @@ -31,6 +32,20 @@ type Kueue struct { components.Component `json:""` } +func (k *Kueue) Init(ctx context.Context, _ cluster.Platform) error { + log := logf.FromContext(ctx).WithName(ComponentName) + + var imageParamMap = map[string]string{ + "odh-kueue-controller-image": "RELATED_IMAGE_ODH_KUEUE_CONTROLLER_IMAGE", // new kueue image + } + + if err := deploy.ApplyParams(Path, imageParamMap); err != nil { + log.Error(err, "failed to update image", "path", Path) + } + + return nil +} + func (k *Kueue) OverrideManifests(ctx context.Context, _ cluster.Platform) error { // If devflags are set, update default manifests path if len(k.DevFlags.Manifests) != 0 { @@ -56,9 +71,6 @@ func (k *Kueue) GetComponentName() string { func (k *Kueue) ReconcileComponent(ctx context.Context, cli client.Client, logger logr.Logger, owner metav1.Object, dscispec *dsciv1.DSCInitializationSpec, platform cluster.Platform, _ bool) error { l := k.ConfigComponentLogger(logger, ComponentName, dscispec) - var imageParamMap = map[string]string{ - "odh-kueue-controller-image": "RELATED_IMAGE_ODH_KUEUE_CONTROLLER_IMAGE", // new kueue image - } enabled := k.GetManagementState() == operatorv1.Managed monitoringEnabled := dscispec.Monitoring.ManagementState == operatorv1.Managed @@ -69,11 +81,6 @@ func (k *Kueue) ReconcileComponent(ctx context.Context, cli client.Client, logge return err } } - if (dscispec.DevFlags == nil || dscispec.DevFlags.ManifestsUri == "") && (k.DevFlags == nil || len(k.DevFlags.Manifests) == 0) { - if err := deploy.ApplyParams(Path, imageParamMap); err != nil { - return fmt.Errorf("failed to update image from %s : %w", Path, err) - } - } } // Deploy Kueue Operator if err := deploy.DeployManifestsFromPath(ctx, cli, owner, Path, dscispec.ApplicationsNamespace, ComponentName, enabled); err != nil { diff --git a/components/modelmeshserving/modelmeshserving.go b/components/modelmeshserving/modelmeshserving.go index b6b067221b9..583e11964a2 100644 --- a/components/modelmeshserving/modelmeshserving.go +++ b/components/modelmeshserving/modelmeshserving.go @@ -12,6 +12,7 @@ import ( operatorv1 "github.com/openshift/api/operator/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/client" + logf "sigs.k8s.io/controller-runtime/pkg/log" dsciv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1" "github.com/opendatahub-io/opendatahub-operator/v2/components" @@ -35,6 +36,35 @@ type ModelMeshServing struct { components.Component `json:""` } +func (m *ModelMeshServing) Init(ctx context.Context, _ cluster.Platform) error { + log := logf.FromContext(ctx).WithName(ComponentName) + + var imageParamMap = map[string]string{ + "odh-mm-rest-proxy": "RELATED_IMAGE_ODH_MM_REST_PROXY_IMAGE", + "odh-modelmesh-runtime-adapter": "RELATED_IMAGE_ODH_MODELMESH_RUNTIME_ADAPTER_IMAGE", + "odh-modelmesh": "RELATED_IMAGE_ODH_MODELMESH_IMAGE", + "odh-modelmesh-controller": "RELATED_IMAGE_ODH_MODELMESH_CONTROLLER_IMAGE", + "odh-model-controller": "RELATED_IMAGE_ODH_MODEL_CONTROLLER_IMAGE", + } + + // odh-model-controller to use + var dependentImageParamMap = map[string]string{ + "odh-model-controller": "RELATED_IMAGE_ODH_MODEL_CONTROLLER_IMAGE", + } + + // Update image parameters + if err := deploy.ApplyParams(Path, imageParamMap); err != nil { + log.Error(err, "failed to update image", "path", Path) + } + + // Update image parameters for odh-model-controller + if err := deploy.ApplyParams(DependentPath, dependentImageParamMap); err != nil { + log.Error(err, "failed to update image", "path", DependentPath) + } + + return nil +} + func (m *ModelMeshServing) OverrideManifests(ctx context.Context, _ cluster.Platform) error { // Go through each manifest and set the overlays if defined for _, subcomponent := range m.DevFlags.Manifests { @@ -80,19 +110,6 @@ func (m *ModelMeshServing) ReconcileComponent(ctx context.Context, _ bool, ) error { l := m.ConfigComponentLogger(logger, ComponentName, dscispec) - var imageParamMap = map[string]string{ - "odh-mm-rest-proxy": "RELATED_IMAGE_ODH_MM_REST_PROXY_IMAGE", - "odh-modelmesh-runtime-adapter": "RELATED_IMAGE_ODH_MODELMESH_RUNTIME_ADAPTER_IMAGE", - "odh-modelmesh": "RELATED_IMAGE_ODH_MODELMESH_IMAGE", - "odh-modelmesh-controller": "RELATED_IMAGE_ODH_MODELMESH_CONTROLLER_IMAGE", - "odh-model-controller": "RELATED_IMAGE_ODH_MODEL_CONTROLLER_IMAGE", - } - - // odh-model-controller to use - var dependentImageParamMap = map[string]string{ - "odh-model-controller": "RELATED_IMAGE_ODH_MODEL_CONTROLLER_IMAGE", - } - enabled := m.GetManagementState() == operatorv1.Managed monitoringEnabled := dscispec.Monitoring.ManagementState == operatorv1.Managed @@ -112,12 +129,6 @@ func (m *ModelMeshServing) ReconcileComponent(ctx context.Context, "prometheus-custom"); err != nil { return err } - // Update image parameters - if (dscispec.DevFlags == nil || dscispec.DevFlags.ManifestsUri == "") && (m.DevFlags == nil || len(m.DevFlags.Manifests) == 0) { - if err := deploy.ApplyParams(Path, imageParamMap); err != nil { - return fmt.Errorf("failed update image from %s : %w", Path, err) - } - } } if err := deploy.DeployManifestsFromPath(ctx, cli, owner, Path, dscispec.ApplicationsNamespace, ComponentName, enabled); err != nil { @@ -130,12 +141,6 @@ func (m *ModelMeshServing) ReconcileComponent(ctx context.Context, "odh-model-controller"); err != nil { return err } - // Update image parameters for odh-model-controller - if dscispec.DevFlags == nil || dscispec.DevFlags.ManifestsUri == "" { - if err := deploy.ApplyParams(DependentPath, dependentImageParamMap); err != nil { - return err - } - } } if err := deploy.DeployManifestsFromPath(ctx, cli, owner, DependentPath, dscispec.ApplicationsNamespace, m.GetComponentName(), enabled); err != nil { // explicitly ignore error if error contains keywords "spec.selector" and "field is immutable" and return all other error. diff --git a/components/modelregistry/modelregistry.go b/components/modelregistry/modelregistry.go index f05cbdd734a..bdd4dc5ffce 100644 --- a/components/modelregistry/modelregistry.go +++ b/components/modelregistry/modelregistry.go @@ -15,6 +15,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/client" + logf "sigs.k8s.io/controller-runtime/pkg/log" dsciv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1" infrav1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/infrastructure/v1" @@ -58,6 +59,22 @@ type ModelRegistry struct { RegistriesNamespace string `json:"registriesNamespace,omitempty"` } +func (m *ModelRegistry) Init(ctx context.Context, _ cluster.Platform) error { + log := logf.FromContext(ctx).WithName(ComponentName) + + var imageParamMap = map[string]string{ + "IMAGES_MODELREGISTRY_OPERATOR": "RELATED_IMAGE_ODH_MODEL_REGISTRY_OPERATOR_IMAGE", + "IMAGES_GRPC_SERVICE": "RELATED_IMAGE_ODH_MLMD_GRPC_SERVER_IMAGE", + "IMAGES_REST_SERVICE": "RELATED_IMAGE_ODH_MODEL_REGISTRY_IMAGE", + } + + if err := deploy.ApplyParams(Path, imageParamMap); err != nil { + log.Error(err, "failed to update image", "path", Path) + } + + return nil +} + func (m *ModelRegistry) OverrideManifests(ctx context.Context, _ cluster.Platform) error { // If devflags are set, update default manifests path if len(m.DevFlags.Manifests) != 0 { @@ -83,11 +100,6 @@ func (m *ModelRegistry) GetComponentName() string { func (m *ModelRegistry) ReconcileComponent(ctx context.Context, cli client.Client, logger logr.Logger, owner metav1.Object, dscispec *dsciv1.DSCInitializationSpec, platform cluster.Platform, _ bool) error { l := m.ConfigComponentLogger(logger, ComponentName, dscispec) - var imageParamMap = map[string]string{ - "IMAGES_MODELREGISTRY_OPERATOR": "RELATED_IMAGE_ODH_MODEL_REGISTRY_OPERATOR_IMAGE", - "IMAGES_GRPC_SERVICE": "RELATED_IMAGE_ODH_MLMD_GRPC_SERVER_IMAGE", - "IMAGES_REST_SERVICE": "RELATED_IMAGE_ODH_MODEL_REGISTRY_IMAGE", - } enabled := m.GetManagementState() == operatorv1.Managed monitoringEnabled := dscispec.Monitoring.ManagementState == operatorv1.Managed @@ -108,14 +120,11 @@ func (m *ModelRegistry) ReconcileComponent(ctx context.Context, cli client.Clien } } - // Update image parameters only when we do not have customized manifests set - if (dscispec.DevFlags == nil || dscispec.DevFlags.ManifestsUri == "") && (m.DevFlags == nil || len(m.DevFlags.Manifests) == 0) { - extraParamsMap := map[string]string{ - "DEFAULT_CERT": DefaultModelRegistryCert, - } - if err := deploy.ApplyParams(Path, imageParamMap, extraParamsMap); err != nil { - return fmt.Errorf("failed to update image from %s : %w", Path, err) - } + extraParamsMap := map[string]string{ + "DEFAULT_CERT": DefaultModelRegistryCert, + } + if err := deploy.ApplyParams(Path, nil, extraParamsMap); err != nil { + return fmt.Errorf("failed to update image from %s : %w", Path, err) } // Create model registries namespace diff --git a/components/ray/ray.go b/components/ray/ray.go index c1720cfcd6c..654ebeb960f 100644 --- a/components/ray/ray.go +++ b/components/ray/ray.go @@ -12,6 +12,7 @@ import ( operatorv1 "github.com/openshift/api/operator/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/client" + logf "sigs.k8s.io/controller-runtime/pkg/log" dsciv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1" "github.com/opendatahub-io/opendatahub-operator/v2/components" @@ -33,6 +34,19 @@ type Ray struct { components.Component `json:""` } +func (r *Ray) Init(ctx context.Context, _ cluster.Platform) error { + log := logf.FromContext(ctx).WithName(ComponentName) + + var imageParamMap = map[string]string{ + "odh-kuberay-operator-controller-image": "RELATED_IMAGE_ODH_KUBERAY_OPERATOR_CONTROLLER_IMAGE", + } + if err := deploy.ApplyParams(RayPath, imageParamMap); err != nil { + log.Error(err, "failed to update image", "path", RayPath) + } + + return nil +} + func (r *Ray) OverrideManifests(ctx context.Context, _ cluster.Platform) error { // If devflags are set, update default manifests path if len(r.DevFlags.Manifests) != 0 { @@ -59,10 +73,6 @@ func (r *Ray) ReconcileComponent(ctx context.Context, cli client.Client, logger owner metav1.Object, dscispec *dsciv1.DSCInitializationSpec, platform cluster.Platform, _ bool) error { l := r.ConfigComponentLogger(logger, ComponentName, dscispec) - var imageParamMap = map[string]string{ - "odh-kuberay-operator-controller-image": "RELATED_IMAGE_ODH_KUBERAY_OPERATOR_CONTROLLER_IMAGE", - } - enabled := r.GetManagementState() == operatorv1.Managed monitoringEnabled := dscispec.Monitoring.ManagementState == operatorv1.Managed @@ -73,10 +83,8 @@ func (r *Ray) ReconcileComponent(ctx context.Context, cli client.Client, logger return err } } - if (dscispec.DevFlags == nil || dscispec.DevFlags.ManifestsUri == "") && (r.DevFlags == nil || len(r.DevFlags.Manifests) == 0) { - if err := deploy.ApplyParams(RayPath, imageParamMap, map[string]string{"namespace": dscispec.ApplicationsNamespace}); err != nil { - return fmt.Errorf("failed to update image from %s : %w", RayPath, err) - } + if err := deploy.ApplyParams(RayPath, nil, map[string]string{"namespace": dscispec.ApplicationsNamespace}); err != nil { + return fmt.Errorf("failed to update namespace from %s : %w", RayPath, err) } } // Deploy Ray Operator diff --git a/components/trainingoperator/trainingoperator.go b/components/trainingoperator/trainingoperator.go index 6ebe12f538b..a8623d89190 100644 --- a/components/trainingoperator/trainingoperator.go +++ b/components/trainingoperator/trainingoperator.go @@ -12,6 +12,7 @@ import ( operatorv1 "github.com/openshift/api/operator/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/client" + logf "sigs.k8s.io/controller-runtime/pkg/log" dsciv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1" "github.com/opendatahub-io/opendatahub-operator/v2/components" @@ -33,6 +34,20 @@ type TrainingOperator struct { components.Component `json:""` } +func (r *TrainingOperator) Init(ctx context.Context, _ cluster.Platform) error { + log := logf.FromContext(ctx).WithName(ComponentName) + + var imageParamMap = map[string]string{ + "odh-training-operator-controller-image": "RELATED_IMAGE_ODH_TRAINING_OPERATOR_IMAGE", + } + + if err := deploy.ApplyParams(TrainingOperatorPath, imageParamMap); err != nil { + log.Error(err, "failed to update image", "path", TrainingOperatorPath) + } + + return nil +} + func (r *TrainingOperator) OverrideManifests(ctx context.Context, _ cluster.Platform) error { // If devflags are set, update default manifests path if len(r.DevFlags.Manifests) != 0 { @@ -59,10 +74,6 @@ func (r *TrainingOperator) ReconcileComponent(ctx context.Context, cli client.Cl owner metav1.Object, dscispec *dsciv1.DSCInitializationSpec, platform cluster.Platform, _ bool) error { l := r.ConfigComponentLogger(logger, ComponentName, dscispec) - var imageParamMap = map[string]string{ - "odh-training-operator-controller-image": "RELATED_IMAGE_ODH_TRAINING_OPERATOR_IMAGE", - } - enabled := r.GetManagementState() == operatorv1.Managed monitoringEnabled := dscispec.Monitoring.ManagementState == operatorv1.Managed @@ -73,11 +84,6 @@ func (r *TrainingOperator) ReconcileComponent(ctx context.Context, cli client.Cl return err } } - if (dscispec.DevFlags == nil || dscispec.DevFlags.ManifestsUri == "") && (r.DevFlags == nil || len(r.DevFlags.Manifests) == 0) { - if err := deploy.ApplyParams(TrainingOperatorPath, imageParamMap); err != nil { - return err - } - } } // Deploy Training Operator if err := deploy.DeployManifestsFromPath(ctx, cli, owner, TrainingOperatorPath, dscispec.ApplicationsNamespace, ComponentName, enabled); err != nil { diff --git a/components/trustyai/trustyai.go b/components/trustyai/trustyai.go index 969e26acc54..e39b27eb7e8 100644 --- a/components/trustyai/trustyai.go +++ b/components/trustyai/trustyai.go @@ -11,6 +11,7 @@ import ( operatorv1 "github.com/openshift/api/operator/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/client" + logf "sigs.k8s.io/controller-runtime/pkg/log" dsciv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1" "github.com/opendatahub-io/opendatahub-operator/v2/components" @@ -24,6 +25,7 @@ var ( PathUpstream = deploy.DefaultManifestPath + "/" + ComponentPathName + "/overlays/odh" PathDownstream = deploy.DefaultManifestPath + "/" + ComponentPathName + "/overlays/rhoai" OverridePath = "" + DefaultPath = "" ) // Verifies that TrustyAI implements ComponentInterface. @@ -35,6 +37,27 @@ type TrustyAI struct { components.Component `json:""` } +func (t *TrustyAI) Init(ctx context.Context, platform cluster.Platform) error { + log := logf.FromContext(ctx).WithName(ComponentName) + + DefaultPath := map[cluster.Platform]string{ + cluster.SelfManagedRhods: PathDownstream, + cluster.ManagedRhods: PathDownstream, + cluster.OpenDataHub: PathUpstream, + cluster.Unknown: PathUpstream, + }[platform] + var imageParamMap = map[string]string{ + "trustyaiServiceImage": "RELATED_IMAGE_ODH_TRUSTYAI_SERVICE_IMAGE", + "trustyaiOperatorImage": "RELATED_IMAGE_ODH_TRUSTYAI_SERVICE_OPERATOR_IMAGE", + } + + if err := deploy.ApplyParams(DefaultPath, imageParamMap); err != nil { + log.Error(err, "failed to update image", "path", DefaultPath) + } + + return nil +} + func (t *TrustyAI) OverrideManifests(ctx context.Context, _ cluster.Platform) error { // If devflags are set, update default manifests path if len(t.DevFlags.Manifests) != 0 { @@ -58,21 +81,11 @@ func (t *TrustyAI) GetComponentName() string { func (t *TrustyAI) ReconcileComponent(ctx context.Context, cli client.Client, logger logr.Logger, owner metav1.Object, dscispec *dsciv1.DSCInitializationSpec, platform cluster.Platform, _ bool) error { - var imageParamMap = map[string]string{ - "trustyaiServiceImage": "RELATED_IMAGE_ODH_TRUSTYAI_SERVICE_IMAGE", - "trustyaiOperatorImage": "RELATED_IMAGE_ODH_TRUSTYAI_SERVICE_OPERATOR_IMAGE", - } - entryPath := map[cluster.Platform]string{ - cluster.SelfManagedRhods: PathDownstream, - cluster.ManagedRhods: PathDownstream, - cluster.OpenDataHub: PathUpstream, - cluster.Unknown: PathUpstream, - }[platform] - l := t.ConfigComponentLogger(logger, ComponentName, dscispec) enabled := t.GetManagementState() == operatorv1.Managed monitoringEnabled := dscispec.Monitoring.ManagementState == operatorv1.Managed + entryPath := DefaultPath if enabled { if t.DevFlags != nil { @@ -84,11 +97,6 @@ func (t *TrustyAI) ReconcileComponent(ctx context.Context, cli client.Client, lo entryPath = OverridePath } } - if (dscispec.DevFlags == nil || dscispec.DevFlags.ManifestsUri == "") && (t.DevFlags == nil || len(t.DevFlags.Manifests) == 0) { - if err := deploy.ApplyParams(entryPath, imageParamMap); err != nil { - return fmt.Errorf("failed to update image %s: %w", entryPath, err) - } - } } // Deploy TrustyAI Operator if err := deploy.DeployManifestsFromPath(ctx, cli, owner, entryPath, dscispec.ApplicationsNamespace, t.GetComponentName(), enabled); err != nil { diff --git a/components/workbenches/workbenches.go b/components/workbenches/workbenches.go index 7c9fe81beef..44898b8c81e 100644 --- a/components/workbenches/workbenches.go +++ b/components/workbenches/workbenches.go @@ -12,6 +12,7 @@ import ( operatorv1 "github.com/openshift/api/operator/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/client" + logf "sigs.k8s.io/controller-runtime/pkg/log" dsciv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1" "github.com/opendatahub-io/opendatahub-operator/v2/components" @@ -40,6 +41,26 @@ type Workbenches struct { components.Component `json:""` } +func (w *Workbenches) Init(ctx context.Context, _ cluster.Platform) error { + log := logf.FromContext(ctx).WithName(ComponentName) + + var imageParamMap = map[string]string{ + "odh-notebook-controller-image": "RELATED_IMAGE_ODH_NOTEBOOK_CONTROLLER_IMAGE", + "odh-kf-notebook-controller-image": "RELATED_IMAGE_ODH_KF_NOTEBOOK_CONTROLLER_IMAGE", + } + + // for kf-notebook-controller image + if err := deploy.ApplyParams(notebookControllerPath, imageParamMap); err != nil { + log.Error(err, "failed to update image", "path", notebookControllerPath) + } + // for odh-notebook-controller image + if err := deploy.ApplyParams(kfnotebookControllerPath, imageParamMap); err != nil { + log.Error(err, "failed to update image", "path", kfnotebookControllerPath) + } + + return nil +} + func (w *Workbenches) OverrideManifests(ctx context.Context, platform cluster.Platform) error { // Download manifests if defined by devflags // Go through each manifest and set the overlays if defined @@ -93,10 +114,6 @@ func (w *Workbenches) GetComponentName() string { func (w *Workbenches) ReconcileComponent(ctx context.Context, cli client.Client, logger logr.Logger, owner metav1.Object, dscispec *dsciv1.DSCInitializationSpec, platform cluster.Platform, _ bool) error { l := w.ConfigComponentLogger(logger, ComponentName, dscispec) - var imageParamMap = map[string]string{ - "odh-notebook-controller-image": "RELATED_IMAGE_ODH_NOTEBOOK_CONTROLLER_IMAGE", - "odh-kf-notebook-controller-image": "RELATED_IMAGE_ODH_KF_NOTEBOOK_CONTROLLER_IMAGE", - } // Set default notebooks namespace // Create rhods-notebooks namespace in managed platforms @@ -124,19 +141,6 @@ func (w *Workbenches) ReconcileComponent(ctx context.Context, cli client.Client, } } - // Update image parameters for nbc - if enabled { - if (dscispec.DevFlags == nil || dscispec.DevFlags.ManifestsUri == "") && (w.DevFlags == nil || len(w.DevFlags.Manifests) == 0) { - // for kf-notebook-controller image - if err := deploy.ApplyParams(notebookControllerPath, imageParamMap); err != nil { - return fmt.Errorf("failed to update image %s: %w", notebookControllerPath, err) - } - // for odh-notebook-controller image - if err := deploy.ApplyParams(kfnotebookControllerPath, imageParamMap); err != nil { - return fmt.Errorf("failed to update image %s: %w", kfnotebookControllerPath, err) - } - } - } if err := deploy.DeployManifestsFromPath(ctx, cli, owner, notebookControllerPath, dscispec.ApplicationsNamespace,