feat: propagate openshift console URL to dashboard
parent
d104845f89
commit
d0e16a3443
|
|
@ -355,6 +355,14 @@ rules:
|
|||
- kubernetesimagepullers
|
||||
verbs:
|
||||
- '*'
|
||||
- apiGroups:
|
||||
- config.openshift.io
|
||||
resources:
|
||||
- consoles
|
||||
resourcesNames:
|
||||
- cluster
|
||||
verbs:
|
||||
- get
|
||||
### CHE-OPERATOR ROLES ONLY: END
|
||||
# devworkspace-controller-view-workspaces.ClusterRole.yaml
|
||||
- apiGroups:
|
||||
|
|
|
|||
|
|
@ -9,11 +9,14 @@
|
|||
// Contributors:
|
||||
// Red Hat, Inc. - initial API and implementation
|
||||
//
|
||||
|
||||
package dashboard
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
ctrl "sigs.k8s.io/controller-runtime"
|
||||
|
||||
"github.com/eclipse-che/che-operator/pkg/deploy"
|
||||
"github.com/eclipse-che/che-operator/pkg/deploy/expose"
|
||||
"github.com/eclipse-che/che-operator/pkg/deploy/gateway"
|
||||
|
|
@ -26,6 +29,10 @@ const (
|
|||
exposePath = "/dashboard/"
|
||||
)
|
||||
|
||||
var (
|
||||
log = ctrl.Log.WithName("dashboard")
|
||||
)
|
||||
|
||||
type Dashboard struct {
|
||||
deployContext *deploy.DeployContext
|
||||
component string
|
||||
|
|
|
|||
|
|
@ -9,11 +9,14 @@
|
|||
// Contributors:
|
||||
// Red Hat, Inc. - initial API and implementation
|
||||
//
|
||||
|
||||
package dashboard
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
configv1 "github.com/openshift/api/config/v1"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
|
||||
|
|
@ -49,11 +52,13 @@ func TestDashboardDeploymentSecurityContext(t *testing.T) {
|
|||
},
|
||||
},
|
||||
ClusterAPI: deploy.ClusterAPI{
|
||||
Client: cli,
|
||||
Scheme: scheme.Scheme,
|
||||
Client: cli,
|
||||
NonCachedClient: cli,
|
||||
Scheme: scheme.Scheme,
|
||||
},
|
||||
Proxy: &deploy.Proxy{},
|
||||
}
|
||||
deployContext.ClusterAPI.Scheme.AddKnownTypes(configv1.SchemeGroupVersion, &configv1.Console{})
|
||||
|
||||
dashboard := NewDashboard(deployContext)
|
||||
deployment, err := dashboard.getDashboardDeploymentSpec()
|
||||
|
|
@ -122,11 +127,13 @@ func TestDashboardDeploymentResources(t *testing.T) {
|
|||
deployContext := &deploy.DeployContext{
|
||||
CheCluster: testCase.cheCluster,
|
||||
ClusterAPI: deploy.ClusterAPI{
|
||||
Client: cli,
|
||||
Scheme: scheme.Scheme,
|
||||
Client: cli,
|
||||
NonCachedClient: cli,
|
||||
Scheme: scheme.Scheme,
|
||||
},
|
||||
Proxy: &deploy.Proxy{},
|
||||
}
|
||||
deployContext.ClusterAPI.Scheme.AddKnownTypes(configv1.SchemeGroupVersion, &configv1.Console{})
|
||||
|
||||
dashboard := NewDashboard(deployContext)
|
||||
deployment, err := dashboard.getDashboardDeploymentSpec()
|
||||
|
|
@ -171,6 +178,9 @@ func TestDashboardDeploymentEnvVars(t *testing.T) {
|
|||
Name: "CHE_INTERNAL_URL",
|
||||
Value: "http://che-host.eclipse-che.svc:8080/api",
|
||||
},
|
||||
{
|
||||
Name: "OPENSHIFT_CONSOLE_URL",
|
||||
},
|
||||
},
|
||||
cheCluster: &orgv1.CheCluster{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
|
|
@ -195,6 +205,9 @@ func TestDashboardDeploymentEnvVars(t *testing.T) {
|
|||
Name: "CHE_URL",
|
||||
Value: "http://che.com",
|
||||
},
|
||||
{
|
||||
Name: "OPENSHIFT_CONSOLE_URL",
|
||||
},
|
||||
// the following are not provisioned: CHE_INTERNAL_URL
|
||||
},
|
||||
cheCluster: &orgv1.CheCluster{
|
||||
|
|
@ -209,6 +222,48 @@ func TestDashboardDeploymentEnvVars(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Test provisioning OpenShift Console URL",
|
||||
initObjects: []runtime.Object{
|
||||
&configv1.Console{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "cluster",
|
||||
Namespace: "openshift-console",
|
||||
},
|
||||
Status: configv1.ConsoleStatus{
|
||||
ConsoleURL: "https://console-openshift-console.apps.my-host/",
|
||||
},
|
||||
},
|
||||
},
|
||||
envVars: []corev1.EnvVar{
|
||||
{
|
||||
Name: "CHE_HOST",
|
||||
Value: "http://che.com",
|
||||
},
|
||||
{
|
||||
Name: "CHE_URL",
|
||||
Value: "http://che.com",
|
||||
},
|
||||
{
|
||||
Name: "CHE_INTERNAL_URL",
|
||||
Value: "http://che-host.eclipse-che.svc:8080/api",
|
||||
},
|
||||
{
|
||||
Name: "OPENSHIFT_CONSOLE_URL",
|
||||
Value: "https://console-openshift-console.apps.my-host/",
|
||||
},
|
||||
},
|
||||
cheCluster: &orgv1.CheCluster{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Namespace: "eclipse-che",
|
||||
},
|
||||
Spec: orgv1.CheClusterSpec{
|
||||
Server: orgv1.CheClusterSpecServer{
|
||||
CheHost: "che.com",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
|
|
@ -221,11 +276,13 @@ func TestDashboardDeploymentEnvVars(t *testing.T) {
|
|||
deployContext := &deploy.DeployContext{
|
||||
CheCluster: testCase.cheCluster,
|
||||
ClusterAPI: deploy.ClusterAPI{
|
||||
Client: cli,
|
||||
Scheme: scheme.Scheme,
|
||||
Client: cli,
|
||||
NonCachedClient: cli,
|
||||
Scheme: scheme.Scheme,
|
||||
},
|
||||
Proxy: &deploy.Proxy{},
|
||||
}
|
||||
deployContext.ClusterAPI.Scheme.AddKnownTypes(configv1.SchemeGroupVersion, &configv1.Console{})
|
||||
|
||||
dashboard := NewDashboard(deployContext)
|
||||
deployment, err := dashboard.getDashboardDeploymentSpec()
|
||||
|
|
@ -337,8 +394,9 @@ func TestDashboardDeploymentVolumes(t *testing.T) {
|
|||
deployContext := &deploy.DeployContext{
|
||||
CheCluster: testCase.cheCluster,
|
||||
ClusterAPI: deploy.ClusterAPI{
|
||||
Client: cli,
|
||||
Scheme: scheme.Scheme,
|
||||
Client: cli,
|
||||
NonCachedClient: cli,
|
||||
Scheme: scheme.Scheme,
|
||||
},
|
||||
Proxy: &deploy.Proxy{},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
// Contributors:
|
||||
// Red Hat, Inc. - initial API and implementation
|
||||
//
|
||||
|
||||
package dashboard
|
||||
|
||||
import (
|
||||
|
|
|
|||
|
|
@ -9,12 +9,17 @@
|
|||
// Contributors:
|
||||
// Red Hat, Inc. - initial API and implementation
|
||||
//
|
||||
|
||||
package dashboard
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
configv1 "github.com/openshift/api/config/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
|
||||
"github.com/eclipse-che/che-operator/pkg/deploy"
|
||||
"github.com/eclipse-che/che-operator/pkg/util"
|
||||
appsv1 "k8s.io/api/apps/v1"
|
||||
|
|
@ -60,6 +65,13 @@ func (d *Dashboard) getDashboardDeploymentSpec() (*appsv1.Deployment, error) {
|
|||
)
|
||||
}
|
||||
|
||||
if util.IsOpenShift {
|
||||
envVars = append(envVars,
|
||||
corev1.EnvVar{
|
||||
Name: "OPENSHIFT_CONSOLE_URL",
|
||||
Value: d.evaluateOpenShiftConsoleURL()})
|
||||
}
|
||||
|
||||
terminationGracePeriodSeconds := int64(30)
|
||||
labels, labelsSelector := deploy.GetLabelsAndSelector(d.deployContext.CheCluster, d.component)
|
||||
|
||||
|
|
@ -186,6 +198,22 @@ func (d *Dashboard) getDashboardDeploymentSpec() (*appsv1.Deployment, error) {
|
|||
return deployment, nil
|
||||
}
|
||||
|
||||
func (d *Dashboard) evaluateOpenShiftConsoleURL() string {
|
||||
console := &configv1.Console{}
|
||||
|
||||
err := d.deployContext.ClusterAPI.NonCachedClient.Get(context.TODO(), types.NamespacedName{
|
||||
Name: "cluster",
|
||||
Namespace: "openshift-console",
|
||||
}, console)
|
||||
|
||||
if err != nil {
|
||||
// if error happen don't fail deployment but try again on the next reconcile loop
|
||||
log.Error(err, "failed to get OpenShift Console Custom Resource to evaluate URL")
|
||||
return ""
|
||||
}
|
||||
return console.Status.ConsoleURL
|
||||
}
|
||||
|
||||
func (d *Dashboard) provisionCheSelfSignedCA(volumes []corev1.Volume, volumeMounts []corev1.VolumeMount) ([]corev1.Volume, []corev1.VolumeMount) {
|
||||
cheSelfSigned := corev1.Volume{
|
||||
Name: "che-self-signed-ca",
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
// Contributors:
|
||||
// Red Hat, Inc. - initial API and implementation
|
||||
//
|
||||
|
||||
package dashboard
|
||||
|
||||
import "github.com/eclipse-che/che-operator/pkg/deploy"
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
// Contributors:
|
||||
// Red Hat, Inc. - initial API and implementation
|
||||
//
|
||||
|
||||
package dashboard
|
||||
|
||||
import (
|
||||
|
|
|
|||
Loading…
Reference in New Issue