Skip to content

Commit

Permalink
Add consolelink for new operator only on cloudserver cluster
Browse files Browse the repository at this point in the history
- Move from util to common for ReplaceStringsInFile

Signed-off-by: Wen Zhou <wenzhou@redhat.com>
  • Loading branch information
zdtsw committed Jul 31, 2023
1 parent 193932e commit 80c69bb
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion components/dashboard/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ package dashboard

import (
"fmt"

"context"
"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"
routev1 "github.com/openshift/api/route/v1"
apierrs "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"strings"
)

const (
Expand All @@ -17,6 +22,7 @@ const (
PathISVAddOn = deploy.DefaultManifestPath + "/" + ComponentName + "/overlays/apps-addon"
PathOVMS = deploy.DefaultManifestPath + "/" + ComponentName + "/modelserving"
PathODHDashboardConfig = deploy.DefaultManifestPath + "/" + ComponentName + "/odhdashboardconfig"
PathConsoleLink = deploy.DefaultManifestPath + "/" + ComponentName + "/consolelink"
)

var imageParamMap = map[string]string{
Expand Down Expand Up @@ -129,11 +135,38 @@ func (d *Dashboard) ReconcileComponent(owner metav1.Object, cli client.Client, s
if err != nil {
return fmt.Errorf("failed to set dashboard ISV from %s: %v", PathISVAddOn, err)
}
// ConsoleLink handling
consoleRoute := &routev1.Route{}
err = cli.Get(context.TODO(), client.ObjectKey{Name: "console", Namespace: "openshift-console"}, consoleRoute)
if err != nil && !apierrs.IsNotFound(err) {
return fmt.Errorf("Error getting console route URL : %v", err)
}
domainIndex := strings.Index(consoleRoute.Spec.Host, ".")
consolelinkDomain := consoleRoute.Spec.Host[domainIndex+1:]
err = common.ReplaceStringsInFile(PathConsoleLink, map[string]string{
"<rhods-dashboard-url>": "https://rhods-dashboard-" + namespace + consolelinkDomain,
})
if err != nil {
return fmt.Errorf("Error replacing with correct dashboard url for ConsoleLink: %v", err)
}
err = deploy.DeployManifestsFromPath(owner, cli, ComponentName,
PathConsoleLink,
namespace,
scheme, enabled)
if err != nil {
return fmt.Errorf("failed to set dashboard consolelink from %s", PathConsoleLink)
}
err = deploy.DeployManifestsFromPath(owner, cli, ComponentName,
PathConsoleLink,
namespace,
scheme, enabled)
if err != nil {
return fmt.Errorf("failed to set dashboard consolelink from %s", PathConsoleLink)
}
return err
default:
return nil
}

}

func (in *Dashboard) DeepCopyInto(out *Dashboard) {
Expand Down

0 comments on commit 80c69bb

Please sign in to comment.