Skip to content

Commit

Permalink
update: remove unnecessary param from ApplyParams() (opendatahub-io#1180
Browse files Browse the repository at this point in the history
)

- extraParamsMaps is generic to use

Signed-off-by: Wen Zhou <[email protected]>
  • Loading branch information
zdtsw authored Aug 16, 2024
1 parent db144ed commit d84cd33
Show file tree
Hide file tree
Showing 12 changed files with 15 additions and 24 deletions.
3 changes: 1 addition & 2 deletions components/codeflare/codeflare.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ func (c *CodeFlare) ReconcileComponent(ctx context.Context,
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
"namespace": dscispec.ApplicationsNamespace,
}

enabled := c.GetManagementState() == operatorv1.Managed
Expand All @@ -93,7 +92,7 @@ func (c *CodeFlare) ReconcileComponent(ctx context.Context,

// 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, true); err != nil {
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)
}
}
Expand Down
2 changes: 1 addition & 1 deletion components/dashboard/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (d *Dashboard) ReconcileComponent(ctx context.Context,
}

// 4. update params.env regardless devFlags is provided of not
if err := deploy.ApplyParams(entryPath, imageParamMap, false, extraParamsMap); err != nil {
if err := deploy.ApplyParams(entryPath, imageParamMap, extraParamsMap); err != nil {
return fmt.Errorf("failed to update params.env from %s : %w", entryPath, err)
}
}
Expand Down
2 changes: 1 addition & 1 deletion components/datasciencepipelines/datasciencepipelines.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ 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, false); err != nil {
if err := deploy.ApplyParams(Path, imageParamMap); err != nil {
return fmt.Errorf("failed to update image from %s : %w", Path, err)
}
}
Expand Down
2 changes: 1 addition & 1 deletion components/kserve/kserve.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (k *Kserve) ReconcileComponent(ctx context.Context, cli client.Client,
}
// 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, false); err != nil {
if err := deploy.ApplyParams(DependentPath, dependentParamMap); err != nil {
return fmt.Errorf("failed to update image %s: %w", DependentPath, err)
}
}
Expand Down
2 changes: 1 addition & 1 deletion components/kueue/kueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (k *Kueue) ReconcileComponent(ctx context.Context, cli client.Client, logge
}
}
if (dscispec.DevFlags == nil || dscispec.DevFlags.ManifestsUri == "") && (k.DevFlags == nil || len(k.DevFlags.Manifests) == 0) {
if err := deploy.ApplyParams(Path, imageParamMap, true); err != nil {
if err := deploy.ApplyParams(Path, imageParamMap); err != nil {
return fmt.Errorf("failed to update image from %s : %w", Path, err)
}
}
Expand Down
4 changes: 2 additions & 2 deletions components/modelmeshserving/modelmeshserving.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (m *ModelMeshServing) ReconcileComponent(ctx context.Context,
}
// Update image parameters
if (dscispec.DevFlags == nil || dscispec.DevFlags.ManifestsUri == "") && (m.DevFlags == nil || len(m.DevFlags.Manifests) == 0) {
if err := deploy.ApplyParams(Path, imageParamMap, false); err != nil {
if err := deploy.ApplyParams(Path, imageParamMap); err != nil {
return fmt.Errorf("failed update image from %s : %w", Path, err)
}
}
Expand All @@ -132,7 +132,7 @@ func (m *ModelMeshServing) ReconcileComponent(ctx context.Context,
}
// Update image parameters for odh-model-controller
if dscispec.DevFlags == nil || dscispec.DevFlags.ManifestsUri == "" {
if err := deploy.ApplyParams(DependentPath, dependentImageParamMap, false); err != nil {
if err := deploy.ApplyParams(DependentPath, dependentImageParamMap); err != nil {
return err
}
}
Expand Down
2 changes: 1 addition & 1 deletion components/modelregistry/modelregistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ 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) {
if err := deploy.ApplyParams(Path, imageParamMap, false); err != nil {
if err := deploy.ApplyParams(Path, imageParamMap); err != nil {
return fmt.Errorf("failed to update image from %s : %w", Path, err)
}
}
Expand Down
3 changes: 1 addition & 2 deletions components/ray/ray.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ func (r *Ray) ReconcileComponent(ctx context.Context, cli client.Client, logger

var imageParamMap = map[string]string{
"odh-kuberay-operator-controller-image": "RELATED_IMAGE_ODH_KUBERAY_OPERATOR_CONTROLLER_IMAGE",
"namespace": dscispec.ApplicationsNamespace,
}

enabled := r.GetManagementState() == operatorv1.Managed
Expand All @@ -75,7 +74,7 @@ func (r *Ray) ReconcileComponent(ctx context.Context, cli client.Client, logger
}
}
if (dscispec.DevFlags == nil || dscispec.DevFlags.ManifestsUri == "") && (r.DevFlags == nil || len(r.DevFlags.Manifests) == 0) {
if err := deploy.ApplyParams(RayPath, imageParamMap, true); err != nil {
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)
}
}
Expand Down
3 changes: 1 addition & 2 deletions components/trainingoperator/trainingoperator.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ func (r *TrainingOperator) ReconcileComponent(ctx context.Context, cli client.Cl

var imageParamMap = map[string]string{
"odh-training-operator-controller-image": "RELATED_IMAGE_ODH_TRAINING_OPERATOR_IMAGE",
"namespace": dscispec.ApplicationsNamespace,
}

enabled := r.GetManagementState() == operatorv1.Managed
Expand All @@ -75,7 +74,7 @@ func (r *TrainingOperator) ReconcileComponent(ctx context.Context, cli client.Cl
}
}
if (dscispec.DevFlags == nil || dscispec.DevFlags.ManifestsUri == "") && (r.DevFlags == nil || len(r.DevFlags.Manifests) == 0) {
if err := deploy.ApplyParams(TrainingOperatorPath, imageParamMap, true); err != nil {
if err := deploy.ApplyParams(TrainingOperatorPath, imageParamMap); err != nil {
return err
}
}
Expand Down
2 changes: 1 addition & 1 deletion components/trustyai/trustyai.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (t *TrustyAI) ReconcileComponent(ctx context.Context, cli client.Client, lo
}
}
if (dscispec.DevFlags == nil || dscispec.DevFlags.ManifestsUri == "") && (t.DevFlags == nil || len(t.DevFlags.Manifests) == 0) {
if err := deploy.ApplyParams(Path, imageParamMap, false); err != nil {
if err := deploy.ApplyParams(Path, imageParamMap); err != nil {
return fmt.Errorf("failed to update image %s: %w", Path, err)
}
}
Expand Down
4 changes: 2 additions & 2 deletions components/workbenches/workbenches.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ func (w *Workbenches) ReconcileComponent(ctx context.Context, cli client.Client,
if (dscispec.DevFlags == nil || dscispec.DevFlags.ManifestsUri == "") && (w.DevFlags == nil || len(w.DevFlags.Manifests) == 0) {
if platform == cluster.ManagedRhods || platform == cluster.SelfManagedRhods {
// for kf-notebook-controller image
if err := deploy.ApplyParams(notebookControllerPath, imageParamMap, false); err != nil {
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, false); err != nil {
if err := deploy.ApplyParams(kfnotebookControllerPath, imageParamMap); err != nil {
return fmt.Errorf("failed to update image %s: %w", kfnotebookControllerPath, err)
}
}
Expand Down
10 changes: 2 additions & 8 deletions pkg/deploy/envParams.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ priority of image values (from high to low):
- image values set in manifests params.env if manifestsURI is set
- RELATED_IMAGE_* values from CSV (if it is set)
- image values set in manifests params.env if manifestsURI is not set.
parameter isUpdateNamespace is used to set if should update namespace with DSCI CR's applicationnamespace.
extraParamsMaps is used to set extra parameters which are not carried from ENV variable. this can be passed per component.
*/
func ApplyParams(componentPath string, imageParamsMap map[string]string, isUpdateNamespace bool, extraParamsMaps ...map[string]string) error {
func ApplyParams(componentPath string, imageParamsMap map[string]string, extraParamsMaps ...map[string]string) error {
paramsFile := filepath.Join(componentPath, "params.env")
// Require params.env at the root folder
paramsEnv, err := os.Open(paramsFile)
Expand Down Expand Up @@ -54,12 +53,7 @@ func ApplyParams(componentPath string, imageParamsMap map[string]string, isUpdat
}
}

// 2. Update namespace variable with applicationNamepsace
if isUpdateNamespace {
paramsEnvMap["namespace"] = imageParamsMap["namespace"]
}

// 3. Update other fileds with extraParamsMap which are not carried from component
// 2. Update other fileds with extraParamsMap which are not carried from component
for _, extraParamsMap := range extraParamsMaps {
for eKey, eValue := range extraParamsMap {
paramsEnvMap[eKey] = eValue
Expand Down

0 comments on commit d84cd33

Please sign in to comment.