Skip to content

Commit

Permalink
refactor: dashboard with new manifests structure
Browse files Browse the repository at this point in the history
- also update the method parameters
- and some cleanup functions

Signed-off-by: Wen Zhou <[email protected]>
  • Loading branch information
zdtsw committed Jun 19, 2024
1 parent 7bf56a4 commit fe3e4b0
Show file tree
Hide file tree
Showing 14 changed files with 97 additions and 115 deletions.
2 changes: 1 addition & 1 deletion components/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ can be found [here](https://github.com/opendatahub-io/opendatahub-operator/tree/
Cleanup(cli client.Client, DSCISpec *dsciv1.DSCInitializationSpec) error
GetComponentName() string
GetManagementState() operatorv1.ManagementState
OverrideManifests(platform string) error
OverrideManifests(platform cluster.Platform) error
UpdatePrometheusConfig(cli client.Client, enable bool, component string) error
ConfigComponentLogger(logger logr.Logger, component string, dscispec *dsciv1.DSCInitializationSpec) logr.Logger
}
Expand Down
4 changes: 2 additions & 2 deletions components/codeflare/codeflare.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type CodeFlare struct {
components.Component `json:""`
}

func (c *CodeFlare) OverrideManifests(_ string) error {
func (c *CodeFlare) OverrideManifests(_ cluster.Platform) error {
// If devflags are set, update default manifests path
if len(c.DevFlags.Manifests) != 0 {
manifestConfig := c.DevFlags.Manifests[0]
Expand Down Expand Up @@ -76,7 +76,7 @@ func (c *CodeFlare) ReconcileComponent(ctx context.Context,
if enabled {
if c.DevFlags != nil {
// Download manifests and update paths
if err := c.OverrideManifests(string(platform)); err != nil {
if err := c.OverrideManifests(platform); err != nil {
return err
}
}
Expand Down
2 changes: 1 addition & 1 deletion components/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ type ComponentInterface interface {
Cleanup(cli client.Client, DSCISpec *dsciv1.DSCInitializationSpec) error
GetComponentName() string
GetManagementState() operatorv1.ManagementState
OverrideManifests(platform string) error
OverrideManifests(platform cluster.Platform) error
UpdatePrometheusConfig(cli client.Client, enable bool, component string) error
ConfigComponentLogger(logger logr.Logger, component string, dscispec *dsciv1.DSCInitializationSpec) logr.Logger
}
Expand Down
164 changes: 73 additions & 91 deletions components/dashboard/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,20 @@ import (
)

var (
ComponentName = "dashboard"
Path = deploy.DefaultManifestPath + "/" + ComponentName + "/base" // ODH
PathISV = deploy.DefaultManifestPath + "/" + ComponentName + "/apps" // ODH APPS
PathCRDs = deploy.DefaultManifestPath + "/" + ComponentName + "/crd" // ODH + RHOAI
PathConsoleLink = deploy.DefaultManifestPath + "/" + ComponentName + "/consolelink" // ODH consolelink

ComponentNameSupported = "rhods-dashboard"
PathSupported = deploy.DefaultManifestPath + "/" + ComponentName + "/overlays/rhoai" // RHOAI
PathISVSM = deploy.DefaultManifestPath + "/" + ComponentName + "/overlays/apps/apps-onprem" // RHOAI APPS
PathISVAddOn = deploy.DefaultManifestPath + "/" + ComponentName + "/overlays/apps/apps-addon" // RHOAI APPS
PathConsoleLinkSupported = deploy.DefaultManifestPath + "/" + ComponentName + "/overlays/consolelink" // RHOAI
PathODHDashboardConfig = deploy.DefaultManifestPath + "/" + ComponentName + "/overlays/odhdashboardconfig" // RHOAI odhdashboardconfig

NameConsoleLink = "console"
NamespaceConsoleLink = "openshift-console"
ConsoleLinkName = "console"
ConsoleLinkNS = "openshift-console"

ComponentNameUpstream = "dashboard"
PathUpstream = deploy.DefaultManifestPath + "/" + ComponentNameUpstream + "/odh"
ConsoleLinkPathUpstream = PathUpstream + "/consolelink"

ComponentNameDownstream = "rhods-dashboard"
PathDownstream = deploy.DefaultManifestPath + "/" + ComponentNameUpstream + "/rhoai"
PathSelfDownstream = PathDownstream + "/onprem"
PathManagedDownstream = PathDownstream + "/addon"
ConsoleLinkPathDownstream = PathDownstream + "/shared/consolelink"
PathSupported = PathDownstream + "/shared/base" // params.env
PathODHDashboardConfig = PathDownstream + "/shared/odhdashboardconfig" // RHOAI odhdashboardconfig
)

// Verifies that Dashboard implements ComponentInterface.
Expand All @@ -51,34 +50,41 @@ type Dashboard struct {
components.Component `json:""`
}

func (d *Dashboard) OverrideManifests(platform string) error {
// If devflags are set, update default manifests path
func (d *Dashboard) OverrideManifests(platform cluster.Platform) error {
if len(d.DevFlags.Manifests) != 0 {
ComponentName := ComponentNameUpstream
manifestConfig := d.DevFlags.Manifests[0]

if err := deploy.DownloadManifests(ComponentName, manifestConfig); err != nil {
return err
}
// If overlay is defined, update paths
if platform == string(cluster.ManagedRhods) || platform == string(cluster.SelfManagedRhods) {
defaultKustomizePath := "overlays/rhoai"
switch platform {
case cluster.SelfManagedRhods:
defaultKustomizePath := "rhoai/onprem"
if manifestConfig.SourcePath != "" {
defaultKustomizePath = manifestConfig.SourcePath
}
PathSupported = filepath.Join(deploy.DefaultManifestPath, ComponentName, defaultKustomizePath)
} else {
defaultKustomizePath := "base"
PathSelfDownstream = filepath.Join(deploy.DefaultManifestPath, ComponentName, defaultKustomizePath)
case cluster.ManagedRhods:
defaultKustomizePath := "rhoai/addon"
if manifestConfig.SourcePath != "" {
defaultKustomizePath = manifestConfig.SourcePath
}
PathManagedDownstream = filepath.Join(deploy.DefaultManifestPath, ComponentName, defaultKustomizePath)
default:
defaultKustomizePath := "odh"
if manifestConfig.SourcePath != "" {
defaultKustomizePath = manifestConfig.SourcePath
}
Path = filepath.Join(deploy.DefaultManifestPath, ComponentName, defaultKustomizePath)
PathUpstream = filepath.Join(deploy.DefaultManifestPath, ComponentName, defaultKustomizePath)
}
}

return nil
}

func (d *Dashboard) GetComponentName() string {
return ComponentName
return ComponentNameUpstream
}

//nolint:gocyclo
Expand All @@ -93,9 +99,9 @@ func (d *Dashboard) ReconcileComponent(ctx context.Context,
var l logr.Logger

if platform == cluster.SelfManagedRhods || platform == cluster.ManagedRhods {
l = d.ConfigComponentLogger(logger, ComponentNameSupported, dscispec)
l = d.ConfigComponentLogger(logger, ComponentNameDownstream, dscispec)
} else {
l = d.ConfigComponentLogger(logger, ComponentName, dscispec)
l = d.ConfigComponentLogger(logger, ComponentNameUpstream, dscispec)
}

var imageParamMap = map[string]string{
Expand All @@ -113,16 +119,12 @@ func (d *Dashboard) ReconcileComponent(ctx context.Context,
}
if d.DevFlags != nil {
// Download manifests and update paths
if err := d.OverrideManifests(string(platform)); err != nil {
if err := d.OverrideManifests(platform); err != nil {
return err
}
}
// 1. Deploy CRDs
if err := d.deployCRDsForPlatform(cli, owner, dscispec.ApplicationsNamespace, platform); err != nil {
return fmt.Errorf("failed to deploy Dashboard CRD: %w", err)
}

// 2. platform specific RBAC
// platform specific RBAC
if platform == cluster.OpenDataHub || platform == "" {
err := cluster.UpdatePodSecurityRolebinding(ctx, cli, dscispec.ApplicationsNamespace, "odh-dashboard")
if err != nil {
Expand Down Expand Up @@ -153,32 +155,41 @@ func (d *Dashboard) ReconcileComponent(ctx context.Context,
if err := cluster.CreateSecret(ctx, cli, "anaconda-ce-access", dscispec.ApplicationsNamespace); err != nil {
return fmt.Errorf("failed to create access-secret for anaconda: %w", err)
}
// overlay which including ../../base + anaconda-ce-validator
if err := deploy.DeployManifestsFromPath(cli, owner, PathSupported, dscispec.ApplicationsNamespace, ComponentNameSupported, enabled); err != nil {
return fmt.Errorf("failed to apply manifests from %s: %w", PathSupported, err)
}

// Apply RHOAI specific configs, e.g anaconda screct and cronjob and ISV
if err := d.applyRHOAISpecificConfigs(cli, owner, dscispec.ApplicationsNamespace, platform); err != nil {
return err
// Deploy RHOAI manifests

PathDownstream := PathSelfDownstream
if platform == cluster.ManagedRhods {
PathDownstream = PathManagedDownstream
}
// only update RHOAI specific configs
if enabled {
if err := d.updateRHOAISpecificConfigs(platform); err != nil {
return err
}
}
// consolelink
if err := d.deployConsoleLink(ctx, cli, owner, platform, dscispec.ApplicationsNamespace, ComponentNameSupported); err != nil {
// only config consolelink
if err := d.configConsoleLink(ctx, cli, platform, dscispec.ApplicationsNamespace, ComponentNameDownstream); err != nil {
return err
}

if err := deploy.DeployManifestsFromPath(cli, owner, PathDownstream, dscispec.ApplicationsNamespace, ComponentNameDownstream, enabled); err != nil {
return fmt.Errorf("failed to apply manifests from %s: %w", PathDownstream, err)
}

l.Info("apply manifests done")

// CloudService Monitoring handling
if platform == cluster.ManagedRhods {
if enabled {
// first check if the service is up, so prometheus won't fire alerts when it is just startup
if err := cluster.WaitForDeploymentAvailable(ctx, cli, ComponentNameSupported, dscispec.ApplicationsNamespace, 20, 3); err != nil {
return fmt.Errorf("deployment for %s is not ready to server: %w", ComponentName, err)
if err := cluster.WaitForDeploymentAvailable(ctx, cli, ComponentNameDownstream, dscispec.ApplicationsNamespace, 20, 3); err != nil {
return fmt.Errorf("deployment for %s is not ready to server: %w", ComponentNameDownstream, err)
}
l.Info("deployment is done, updating monitoring rules")
}

if err := d.UpdatePrometheusConfig(cli, enabled && monitoringEnabled, ComponentNameSupported); err != nil {
if err := d.UpdatePrometheusConfig(cli, enabled && monitoringEnabled, ComponentNameDownstream); err != nil {
return err
}
if err := deploy.DeployManifestsFromPath(cli, owner,
Expand All @@ -191,81 +202,57 @@ func (d *Dashboard) ReconcileComponent(ctx context.Context,
}
return nil
default:
// base
if err := deploy.DeployManifestsFromPath(cli, owner, Path, dscispec.ApplicationsNamespace, ComponentName, enabled); err != nil {
return err
}
// ISV
if err := deploy.DeployManifestsFromPath(cli, owner, PathISV, dscispec.ApplicationsNamespace, ComponentName, enabled); err != nil {

// only update consolelink
if err := d.configConsoleLink(ctx, cli, platform, dscispec.ApplicationsNamespace, ComponentNameUpstream); err != nil {
return err
}
// consolelink
if err := d.deployConsoleLink(ctx, cli, owner, platform, dscispec.ApplicationsNamespace, ComponentName); err != nil {
// Deploy ODH manifests
if err := deploy.DeployManifestsFromPath(cli, owner, PathUpstream, dscispec.ApplicationsNamespace, ComponentNameUpstream, enabled); err != nil {
return err
}

l.Info("apply manifests done")
return nil
}
}

func (d *Dashboard) deployCRDsForPlatform(cli client.Client, owner metav1.Object, namespace string, platform cluster.Platform) error {
componentName := ComponentName
if platform == cluster.SelfManagedRhods || platform == cluster.ManagedRhods {
componentName = ComponentNameSupported
}
// we only deploy CRD, we do not remove CRD
return deploy.DeployManifestsFromPath(cli, owner, PathCRDs, namespace, componentName, true)
}

func (d *Dashboard) applyRHOAISpecificConfigs(cli client.Client, owner metav1.Object, namespace string, platform cluster.Platform) error {
enabled := d.ManagementState == operatorv1.Managed

func (d *Dashboard) updateRHOAISpecificConfigs(platform cluster.Platform) error {
// set proper group name
dashboardConfig := filepath.Join(PathODHDashboardConfig, "odhdashboardconfig.yaml")
adminGroups := map[cluster.Platform]string{
cluster.SelfManagedRhods: "rhods-admins",
cluster.ManagedRhods: "dedicated-admins",
}[platform]

if err := common.ReplaceStringsInFile(dashboardConfig, map[string]string{"<admin_groups>": adminGroups}); err != nil {
return err
}
if err := deploy.DeployManifestsFromPath(cli, owner, PathODHDashboardConfig, namespace, ComponentNameSupported, enabled); err != nil {
return fmt.Errorf("failed to create OdhDashboardConfig from %s: %w", PathODHDashboardConfig, err)
}
// ISV
path := PathISVSM
if platform == cluster.ManagedRhods {
path = PathISVAddOn
}
if err := deploy.DeployManifestsFromPath(cli, owner, path, namespace, ComponentNameSupported, enabled); err != nil {
return fmt.Errorf("failed to set dashboard ISV from %s : %w", Path, err)
}
return nil
err := common.ReplaceStringsInFile(dashboardConfig, map[string]string{"<admin_groups>": adminGroups})
return err
}

func (d *Dashboard) deployConsoleLink(ctx context.Context, cli client.Client, owner metav1.Object, platform cluster.Platform, namespace, componentName string) error {
func (d *Dashboard) configConsoleLink(ctx context.Context, cli client.Client, platform cluster.Platform, namespace, componentName string) error {
var manifestsPath, sectionTitle, routeName string
switch platform {
case cluster.SelfManagedRhods:
sectionTitle = "OpenShift Self Managed Services"
manifestsPath = PathConsoleLinkSupported
manifestsPath = ConsoleLinkPathDownstream
routeName = componentName

case cluster.ManagedRhods:
sectionTitle = "OpenShift Managed Services"
manifestsPath = PathConsoleLinkSupported
manifestsPath = ConsoleLinkPathDownstream
routeName = componentName

default:
sectionTitle = "OpenShift Open Data Hub"
manifestsPath = PathConsoleLink
manifestsPath = ConsoleLinkPathUpstream
routeName = "odh-dashboard"
}

pathConsoleLink := filepath.Join(manifestsPath, "consolelink.yaml")

consoleRoute := &routev1.Route{}
if err := cli.Get(ctx, client.ObjectKey{Name: NameConsoleLink, Namespace: NamespaceConsoleLink}, consoleRoute); err != nil {
return fmt.Errorf("error getting console route URL %s : %w", NameConsoleLink, err)
if err := cli.Get(ctx, client.ObjectKey{Name: ConsoleLinkName, Namespace: ConsoleLinkNS}, consoleRoute); err != nil {
return fmt.Errorf("error getting console route URL %s : %w", ConsoleLinkName, err)
}

domainIndex := strings.Index(consoleRoute.Spec.Host, ".")
Expand All @@ -277,11 +264,6 @@ func (d *Dashboard) deployConsoleLink(ctx context.Context, cli client.Client, ow
return fmt.Errorf("error replacing with correct dashboard URL for consolelink : %w", err)
}

enabled := d.ManagementState == operatorv1.Managed
if err := deploy.DeployManifestsFromPath(cli, owner, PathConsoleLink, namespace, componentName, enabled); err != nil {
return fmt.Errorf("failed to set dashboard consolelink %s : %w", pathConsoleLink, err)
}

return nil
}

Expand Down
4 changes: 2 additions & 2 deletions components/datasciencepipelines/datasciencepipelines.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type DataSciencePipelines struct {
components.Component `json:""`
}

func (d *DataSciencePipelines) OverrideManifests(_ string) error {
func (d *DataSciencePipelines) OverrideManifests(_ cluster.Platform) error {
// If devflags are set, update default manifests path
if len(d.DevFlags.Manifests) != 0 {
manifestConfig := d.DevFlags.Manifests[0]
Expand Down Expand Up @@ -94,7 +94,7 @@ func (d *DataSciencePipelines) ReconcileComponent(ctx context.Context,
if enabled {
if d.DevFlags != nil {
// Download manifests and update paths
if err := d.OverrideManifests(string(platform)); err != nil {
if err := d.OverrideManifests(platform); err != nil {
return err
}
}
Expand Down
4 changes: 2 additions & 2 deletions components/kserve/kserve.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type Kserve struct {
DefaultDeploymentMode DefaultDeploymentMode `json:"defaultDeploymentMode,omitempty"`
}

func (k *Kserve) OverrideManifests(_ string) error {
func (k *Kserve) OverrideManifests(_ cluster.Platform) error {
// Download manifests if defined by devflags
// Go through each manifest and set the overlays if defined
for _, subcomponent := range k.DevFlags.Manifests {
Expand Down Expand Up @@ -119,7 +119,7 @@ func (k *Kserve) ReconcileComponent(ctx context.Context, cli client.Client,
}
if k.DevFlags != nil {
// Download manifests and update paths
if err := k.OverrideManifests(string(platform)); err != nil {
if err := k.OverrideManifests(platform); err != nil {
return err
}
}
Expand Down
4 changes: 2 additions & 2 deletions components/kueue/kueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type Kueue struct {
components.Component `json:""`
}

func (k *Kueue) OverrideManifests(_ string) error {
func (k *Kueue) OverrideManifests(_ cluster.Platform) error {
// If devflags are set, update default manifests path
if len(k.DevFlags.Manifests) != 0 {
manifestConfig := k.DevFlags.Manifests[0]
Expand Down Expand Up @@ -65,7 +65,7 @@ func (k *Kueue) ReconcileComponent(ctx context.Context, cli client.Client, logge
if enabled {
if k.DevFlags != nil {
// Download manifests and update paths
if err := k.OverrideManifests(string(platform)); err != nil {
if err := k.OverrideManifests(platform); err != nil {
return 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 @@ -35,7 +35,7 @@ type ModelMeshServing struct {
components.Component `json:""`
}

func (m *ModelMeshServing) OverrideManifests(_ string) error {
func (m *ModelMeshServing) OverrideManifests(_ cluster.Platform) error {
// Go through each manifest and set the overlays if defined
for _, subcomponent := range m.DevFlags.Manifests {
if strings.Contains(subcomponent.URI, DependentComponentName) {
Expand Down Expand Up @@ -100,7 +100,7 @@ func (m *ModelMeshServing) ReconcileComponent(ctx context.Context,
if enabled {
if m.DevFlags != nil {
// Download manifests and update paths
if err := m.OverrideManifests(string(platform)); err != nil {
if err := m.OverrideManifests(platform); err != nil {
return err
}
}
Expand Down
Loading

0 comments on commit fe3e4b0

Please sign in to comment.