Skip to content

Commit

Permalink
component(dashboard): initialize images at startup, remove devflags l…
Browse files Browse the repository at this point in the history
…ogging setup
  • Loading branch information
lburgazzoli committed Oct 18, 2024
1 parent 59edbbf commit 3a8f265
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 37 deletions.
65 changes: 29 additions & 36 deletions controllers/components/dashboard/dashboard_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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,
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
9 changes: 9 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit 3a8f265

Please sign in to comment.