From 3a8f2659c4154d2d46ac4f5727159dd0ee880d63 Mon Sep 17 00:00:00 2001 From: Luca Burgazzoli Date: Fri, 18 Oct 2024 15:43:32 +0200 Subject: [PATCH] component(dashboard): initialize images at startup, remove devflags logging setup --- .../dashboard/dashboard_controller.go | 65 +++++++++---------- .../datasciencecluster_controller.go | 2 +- main.go | 9 +++ 3 files changed, 39 insertions(+), 37 deletions(-) diff --git a/controllers/components/dashboard/dashboard_controller.go b/controllers/components/dashboard/dashboard_controller.go index c16b6de0344..37c63d0fd7f 100644 --- a/controllers/components/dashboard/dashboard_controller.go +++ b/controllers/components/dashboard/dashboard_controller.go @@ -44,7 +44,6 @@ import ( odhrec "github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/reconciler" odhtypes "github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/types" "github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy" - ctrlogger "github.com/opendatahub-io/opendatahub-operator/v2/pkg/logger" "github.com/opendatahub-io/opendatahub-operator/v2/pkg/metadata/labels" ) @@ -108,7 +107,26 @@ func NewDashboardReconciler(ctx context.Context, mgr ctrl.Manager) error { return nil } -func CreateDashboardInstance(dsc *dscv1.DataScienceCluster) *componentsv1.Dashboard { +func Init(platform cluster.Platform) error { + 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 { + return fmt.Errorf("failed to update images on path %s: %w", DefaultPath, err) + } + + return nil +} + +func NewInstance(dsc *dscv1.DataScienceCluster) *componentsv1.Dashboard { return &componentsv1.Dashboard{ TypeMeta: metav1.TypeMeta{ Kind: "Dashboard", @@ -239,24 +257,16 @@ type InitializeAction struct { } func (a *InitializeAction) Execute(ctx context.Context, rr *odhtypes.ReconciliationRequest) error { - // Implement initialization logic - log := logf.FromContext(ctx).WithName(ComponentNameUpstream) - - imageParamMap := map[string]string{ - "odh-dashboard-image": "RELATED_IMAGE_ODH_DASHBOARD_IMAGE", - } - manifestMap := map[cluster.Platform]string{ - cluster.SelfManagedRhods: PathDownstream + "/onprem", - cluster.ManagedRhods: PathDownstream + "/addon", - cluster.OpenDataHub: PathUpstream, - cluster.Unknown: PathUpstream, + // 2. Append or Update variable for component to consume + extraParamsMap, err := updateKustomizeVariable(ctx, rr.Client, rr.Platform, &rr.DSCI.Spec) + if err != nil { + return errors.New("failed to set variable for extraParamsMap") } - DefaultPath = manifestMap[rr.Platform] - - rr.Manifests = manifestMap - if err := deploy.ApplyParams(DefaultPath, imageParamMap); err != nil { - log.Error(err, "failed to update image", "path", DefaultPath) + // 3. update params.env regardless devFlags is provided of not + // We need this for downstream + if err := deploy.ApplyParams(rr.Manifests[rr.Platform], nil, extraParamsMap); err != nil { + return fmt.Errorf("failed to update params.env from %s : %w", rr.Manifests[rr.Platform], err) } return nil @@ -287,11 +297,6 @@ func (a *SupportDevFlagsAction) Execute(ctx context.Context, rr *odhtypes.Reconc } } - if rr.DSCI.Spec.DevFlags != nil { - mode := rr.DSCI.Spec.DevFlags.LogMode - a.Log = ctrlogger.NewNamedLogger(logf.FromContext(ctx), ComponentName, mode) - } - return nil } @@ -343,18 +348,6 @@ func (a *DeployComponentAction) Execute(ctx context.Context, rr *odhtypes.Reconc } } - // 2. Append or Update variable for component to consume - extraParamsMap, err := updateKustomizeVariable(ctx, rr.Client, rr.Platform, &rr.DSCI.Spec) - if err != nil { - return errors.New("failed to set variable for extraParamsMap") - } - - // 3. update params.env regardless devFlags is provided of not - // We need this for downstream - if err := deploy.ApplyParams(rr.Manifests[rr.Platform], nil, extraParamsMap); err != nil { - return fmt.Errorf("failed to update params.env from %s : %w", rr.Manifests[rr.Platform], err) - } - path := rr.Manifests[rr.Platform] name := ComponentNameUpstream @@ -394,7 +387,7 @@ func (a *DeployComponentAction) Execute(ctx context.Context, rr *odhtypes.Reconc default: } - err = deploy.DeployManifestsFromPathWithLabels(ctx, rr.Client, rr.Instance, path, rr.DSCI.Spec.ApplicationsNamespace, name, true, map[string]string{ + err := deploy.DeployManifestsFromPathWithLabels(ctx, rr.Client, rr.Instance, path, rr.DSCI.Spec.ApplicationsNamespace, name, true, map[string]string{ labels.ComponentName: ComponentName, }) diff --git a/controllers/datasciencecluster/datasciencecluster_controller.go b/controllers/datasciencecluster/datasciencecluster_controller.go index 575069b53cd..8eb5bc94236 100644 --- a/controllers/datasciencecluster/datasciencecluster_controller.go +++ b/controllers/datasciencecluster/datasciencecluster_controller.go @@ -309,7 +309,7 @@ func (r *DataScienceClusterReconciler) reconcileDashboardComponent(ctx context.C } // Create the Dashboard instance - dashboard := dashboardctrl.CreateDashboardInstance(instance) + dashboard := dashboardctrl.NewInstance(instance) // Reconcile component err := r.apply(ctx, instance, dashboard) diff --git a/main.go b/main.go index f3112de7a3e..57f8635ca87 100644 --- a/main.go +++ b/main.go @@ -106,6 +106,10 @@ func init() { //nolint:gochecknoinits utilruntime.Must(operatorv1.Install(scheme)) } +func initComponents(_ context.Context, p cluster.Platform) error { + return dashboardctrl.Init(p) +} + func main() { //nolint:funlen,maintidx var metricsAddr string var enableLeaderElection bool @@ -163,6 +167,11 @@ func main() { //nolint:funlen,maintidx release := cluster.GetRelease() platform := release.Name + if err := initComponents(ctx, platform); err != nil { + setupLog.Error(err, "unable to init components") + os.Exit(1) + } + secretCache := createSecretCacheConfig(platform) deploymentCache := createDeploymentCacheConfig(platform) cacheOptions := cache.Options{