Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

component(dashboard): initialize images at startup, remove devflags logging setup #17

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to remove contextual logger as it is done now?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mh, were we supposed to ignore the error and just log it ? right now it would cause the operator to fail to start

Copy link

@ykaliuta ykaliuta Oct 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mh, were we supposed to ignore the error and just log it ? right now it would cause the operator to fail to start

I'm talking about fmt.Printf Oops, it's return of 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