From 87812cd7f83acd1d0e8ecc2c359c217a7cd0f160 Mon Sep 17 00:00:00 2001 From: Yauheni Kaliuta Date: Thu, 12 Sep 2024 12:51:34 +0300 Subject: [PATCH 1/2] components, main: add Component Init method Add Init() method to the Component interface and call it from main on startup. Will be used to move startup-time code from ReconcileComponent (like adjusting params.env). Signed-off-by: Yauheni Kaliuta --- components/component.go | 5 +++++ main.go | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/components/component.go b/components/component.go index 7fe17d6c8c8..c43cef7ac92 100644 --- a/components/component.go +++ b/components/component.go @@ -38,6 +38,10 @@ type Component struct { DevFlags *DevFlags `json:"devFlags,omitempty"` } +func (c *Component) Init(_ context.Context, _ cluster.Platform) error { + return nil +} + func (c *Component) GetManagementState() operatorv1.ManagementState { return c.ManagementState } @@ -77,6 +81,7 @@ type ManifestsConfig struct { } type ComponentInterface interface { + Init(ctx context.Context, platform cluster.Platform) error ReconcileComponent(ctx context.Context, cli client.Client, logger logr.Logger, owner metav1.Object, DSCISpec *dsciv1.DSCInitializationSpec, platform cluster.Platform, currentComponentStatus bool) error Cleanup(ctx context.Context, cli client.Client, owner metav1.Object, DSCISpec *dsciv1.DSCInitializationSpec) error diff --git a/main.go b/main.go index 9e0aa48908c..62c31edec0b 100644 --- a/main.go +++ b/main.go @@ -21,6 +21,7 @@ import ( "flag" "os" + "github.com/hashicorp/go-multierror" addonv1alpha1 "github.com/openshift/addon-operator/apis/addons/v1alpha1" ocappsv1 "github.com/openshift/api/apps/v1" //nolint:importas //reason: conflicts with appsv1 "k8s.io/api/apps/v1" buildv1 "github.com/openshift/api/build/v1" @@ -102,6 +103,22 @@ func init() { //nolint:gochecknoinits utilruntime.Must(operatorv1.Install(scheme)) } +func initComponents(ctx context.Context, p cluster.Platform) error { + var errs *multierror.Error + var dummyDSC = &dscv1.DataScienceCluster{} + + components, err := dummyDSC.GetComponents() + if err != nil { + return err + } + + for _, c := range components { + errs = multierror.Append(errs, c.Init(ctx, p)) + } + + return errs.ErrorOrNil() +} + func main() { //nolint:funlen,maintidx var metricsAddr string var enableLeaderElection bool @@ -323,6 +340,10 @@ func main() { //nolint:funlen,maintidx setupLog.Error(err, "unable to set up ready check") os.Exit(1) } + if err := initComponents(ctx, platform); err != nil { + setupLog.Error(err, "unable to init components") + os.Exit(1) + } setupLog.Info("starting manager") if err := mgr.Start(ctx); err != nil { From 2cb26e6d5b42610dde00a81b239acc0a6f560bf7 Mon Sep 17 00:00:00 2001 From: Yauheni Kaliuta Date: Mon, 19 Aug 2024 14:50:45 +0300 Subject: [PATCH 2/2] 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 | 27 ++++++--- components/dashboard/dashboard.go | 35 ++++++++---- .../datasciencepipelines.go | 55 ++++++++++--------- components/kserve/kserve.go | 28 ++++++---- components/kueue/kueue.go | 24 +++++--- .../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 | 39 +++++++------ 11 files changed, 232 insertions(+), 154 deletions(-) diff --git a/components/codeflare/codeflare.go b/components/codeflare/codeflare.go index 758b18d84dd..5e731c28ba4 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 { @@ -64,10 +79,6 @@ func (c *CodeFlare) ReconcileComponent(ctx context.Context, dscispec *dsciv1.DSCInitializationSpec, platform cluster.Platform, _ bool) error { - 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 @@ -89,11 +100,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 7ab0e73d2d1..d2ed096b3bd 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,26 @@ type Dashboard struct { components.Component `json:""` } +func (d *Dashboard) Init(ctx context.Context, platform cluster.Platform) error { + log := logf.FromContext(ctx).WithName(ComponentNameUpstream) + + 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 { @@ -68,16 +90,9 @@ func (d *Dashboard) ReconcileComponent(ctx context.Context, platform cluster.Platform, currentComponentExist bool, ) error { - 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 @@ -92,8 +107,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 @@ -114,7 +127,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 f7e1289b10f..f0066a6c544 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 { @@ -71,25 +101,6 @@ func (d *DataSciencePipelines) ReconcileComponent(ctx context.Context, platform cluster.Platform, _ bool, ) error { - 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 @@ -101,12 +112,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 03dd94a7e5d..85b739285ea 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 @@ -96,11 +113,6 @@ func (k *Kserve) GetComponentName() string { func (k *Kserve) ReconcileComponent(ctx context.Context, cli client.Client, l logr.Logger, owner metav1.Object, dscispec *dsciv1.DSCInitializationSpec, platform cluster.Platform, _ bool) error { - // 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 @@ -140,12 +152,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 0d15ae2b6d3..ec609317092 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 { @@ -55,10 +70,6 @@ func (k *Kueue) GetComponentName() string { func (k *Kueue) ReconcileComponent(ctx context.Context, cli client.Client, l logr.Logger, owner metav1.Object, dscispec *dsciv1.DSCInitializationSpec, platform cluster.Platform, _ bool) error { - 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 if enabled { @@ -68,11 +79,6 @@ func (k *Kueue) ReconcileComponent(ctx context.Context, cli client.Client, l log 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 9e343d1a9ce..cb1d07b7838 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 { @@ -79,19 +109,6 @@ func (m *ModelMeshServing) ReconcileComponent(ctx context.Context, platform cluster.Platform, _ bool, ) error { - 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 @@ -111,12 +128,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 { @@ -129,12 +140,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 c58f6bb15dc..dbf577ec8f8 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 { @@ -82,11 +99,6 @@ func (m *ModelRegistry) GetComponentName() string { func (m *ModelRegistry) ReconcileComponent(ctx context.Context, cli client.Client, l logr.Logger, owner metav1.Object, dscispec *dsciv1.DSCInitializationSpec, platform cluster.Platform, _ bool) error { - 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 @@ -107,14 +119,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 dd0dd18ed95..c8fa30edbd4 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 { @@ -57,10 +71,6 @@ func (r *Ray) GetComponentName() string { func (r *Ray) ReconcileComponent(ctx context.Context, cli client.Client, l logr.Logger, owner metav1.Object, dscispec *dsciv1.DSCInitializationSpec, platform cluster.Platform, _ bool) error { - 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 @@ -71,10 +81,8 @@ func (r *Ray) ReconcileComponent(ctx context.Context, cli client.Client, l logr. 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 1e1de97679c..a6a7c8f87e7 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 { @@ -57,10 +72,6 @@ func (r *TrainingOperator) GetComponentName() string { func (r *TrainingOperator) ReconcileComponent(ctx context.Context, cli client.Client, l logr.Logger, owner metav1.Object, dscispec *dsciv1.DSCInitializationSpec, platform cluster.Platform, _ bool) error { - 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 @@ -71,11 +82,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 049b63b1d6c..45a211e79c0 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,19 +81,9 @@ func (t *TrustyAI) GetComponentName() string { func (t *TrustyAI) ReconcileComponent(ctx context.Context, cli client.Client, l 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] - enabled := t.GetManagementState() == operatorv1.Managed monitoringEnabled := dscispec.Monitoring.ManagementState == operatorv1.Managed + entryPath := DefaultPath if enabled { if t.DevFlags != nil { @@ -82,11 +95,6 @@ func (t *TrustyAI) ReconcileComponent(ctx context.Context, cli client.Client, l 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 3570cf096ac..c11f1e24297 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 @@ -92,11 +113,6 @@ func (w *Workbenches) GetComponentName() string { func (w *Workbenches) ReconcileComponent(ctx context.Context, cli client.Client, l logr.Logger, owner metav1.Object, dscispec *dsciv1.DSCInitializationSpec, platform cluster.Platform, _ bool) error { - 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 enabled := w.GetManagementState() == operatorv1.Managed @@ -123,19 +139,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,