Skip to content

Commit

Permalink
Add ODHDashboardconfig in dasboard component
Browse files Browse the repository at this point in the history
  • Loading branch information
VaishnaviHire committed Jul 30, 2023
1 parent 7177253 commit 2a8757d
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 17 deletions.
61 changes: 44 additions & 17 deletions components/dashboard/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package dashboard

import (
"fmt"

"github.com/opendatahub-io/opendatahub-operator/v2/components"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/common"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy"
Expand All @@ -12,11 +11,12 @@ import (
)

const (
ComponentName = "odh-dashboard"
Path = deploy.DefaultManifestPath + "/" + ComponentName + "/base"
PathISVSM = deploy.DefaultManifestPath + "/" + ComponentName + "/overlays/apps-onpre"
PathISVAddOn = deploy.DefaultManifestPath + "/" + ComponentName + "/overlays/apps-addon"
PathOVMS = deploy.DefaultManifestPath + "/" + ComponentName + "/modelserving"
ComponentName = "odh-dashboard"
Path = deploy.DefaultManifestPath + "/" + ComponentName + "/base"
PathISVSM = deploy.DefaultManifestPath + "/" + ComponentName + "/overlays/apps-onpre"
PathISVAddOn = deploy.DefaultManifestPath + "/" + ComponentName + "/overlays/apps-addon"
PathOVMS = deploy.DefaultManifestPath + "/" + ComponentName + "/modelserving"
PathODHDashboardConfig = deploy.DefaultManifestPath + "/" + ComponentName + "/odhdashboardconfig"
)

var imageParamMap = map[string]string{
Expand Down Expand Up @@ -59,11 +59,49 @@ func (d *Dashboard) ReconcileComponent(owner metav1.Object, cli client.Client, s
}
}

// Apply RHODS specific configs
if platform != deploy.OpenDataHub {
// Replace admin group
if platform == deploy.SelfManagedRhods {
err = common.ReplaceStringsInFile(PathODHDashboardConfig+"/odhdashboardconfig.yaml", map[string]string{
"<admin_groups>": "rhods-admins",
})
if err != nil {
return err
}
} else {
err = common.ReplaceStringsInFile(PathODHDashboardConfig+"/odhdashboardconfig.yaml", map[string]string{
"<admin_groups>": "dedicated-admins",
})
if err != nil {
return err
}
}
// Create ODHDashboardConfig if it doesn't exist already
err = deploy.DeployManifestsFromPath(owner, cli, ComponentName,
PathODHDashboardConfig,
namespace,
scheme, enabled)
if err != nil {
return fmt.Errorf("failed to set dashboard config from %s: %v", PathODHDashboardConfig, err)
}

// Apply modelserving config
err = deploy.DeployManifestsFromPath(owner, cli, ComponentName,
PathOVMS,
namespace,
scheme, enabled)
if err != nil {
return fmt.Errorf("failed to set dashboard OVMS from %s: %v", PathOVMS, err)
}
}

// Update image parameters
if err := deploy.ApplyImageParams(Path, imageParamMap); err != nil {
return err
}

// Deploy odh-dashboard manifests
err = deploy.DeployManifestsFromPath(owner, cli, ComponentName,
Path,
namespace,
Expand All @@ -72,17 +110,6 @@ func (d *Dashboard) ReconcileComponent(owner metav1.Object, cli client.Client, s
return err
}

// OVMS
if platform, _ := deploy.GetPlatform(cli); platform != deploy.OpenDataHub {
err = deploy.DeployManifestsFromPath(owner, cli, ComponentName,
PathOVMS,
namespace,
scheme, enabled)
if err != nil {
return fmt.Errorf("failed to set dashboard OVMS from %s: %v", PathOVMS, err)
}
}

// ISV handling
switch platform {
case deploy.SelfManagedRhods:
Expand Down
25 changes: 25 additions & 0 deletions pkg/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package common

import (
"context"
"fmt"
"io/ioutil"
authv1 "k8s.io/api/rbac/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
"strings"
)

func UpdatePodSecurityRolebinding(cli client.Client, serviceAccountsList []string, namespace string) error {
Expand Down Expand Up @@ -35,3 +38,25 @@ func subjectExistInRoleBinding(subjectList []authv1.Subject, serviceAccountName,
}
return false
}

func ReplaceStringsInFile(fileName string, replacements map[string]string) error {
// Read the contents of the file
fileContent, err := ioutil.ReadFile(fileName)
if err != nil {
return fmt.Errorf("failed to read file: %v", err)
}

// Replace all occurrences of the strings in the map
newContent := string(fileContent)
for string1, string2 := range replacements {
newContent = strings.ReplaceAll(newContent, string1, string2)
}

// Write the modified content back to the file
err = ioutil.WriteFile(fileName, []byte(newContent), 0)
if err != nil {
return fmt.Errorf("failed to write to file: %v", err)
}

return nil
}
6 changes: 6 additions & 0 deletions pkg/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ func manageResource(owner metav1.Object, ctx context.Context, cli client.Client,
return cli.Create(ctx, obj)
}

// Exception: ODHDashboardConfig should not be updated even with upgrades
// TODO: Move this out when we have dashboard-controller
if found.GetKind() == "OdhDashboardConfig" {
// Do nothing, return
return nil
}
// Perform server-side apply
data, err := json.Marshal(obj)
if err != nil {
Expand Down

0 comments on commit 2a8757d

Please sign in to comment.