From 53354c9004f5e2821b6bb66cc2bce15f8eeb10fb Mon Sep 17 00:00:00 2001 From: Anatolii Bazko Date: Wed, 7 Sep 2022 17:53:44 +0300 Subject: [PATCH] =?UTF-8?q?chore:=20make=20Eclipse=20Che=20compatible=20wi?= =?UTF-8?q?th=20OCP=204.12=20instance=20without=20the=E2=80=A6=20(#1514)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: make Eclipse Che compatible with OCP 4.12 instance without the Console Signed-off-by: Anatolii Bazko --- pkg/deploy/consolelink/consolelink.go | 3 +-- pkg/deploy/dashboard/dashboard_deployment_test.go | 9 +++++++++ pkg/deploy/dashboard/deployment_dashboard.go | 10 ++++++---- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/pkg/deploy/consolelink/consolelink.go b/pkg/deploy/consolelink/consolelink.go index 33b651b9f..c5e97347f 100644 --- a/pkg/deploy/consolelink/consolelink.go +++ b/pkg/deploy/consolelink/consolelink.go @@ -14,7 +14,6 @@ package consolelink import ( "fmt" - "github.com/devfile/devworkspace-operator/pkg/infrastructure" "github.com/eclipse-che/che-operator/pkg/common/chetypes" defaults "github.com/eclipse-che/che-operator/pkg/common/operator-defaults" "github.com/eclipse-che/che-operator/pkg/common/utils" @@ -46,7 +45,7 @@ func NewConsoleLinkReconciler() *ConsoleLinkReconciler { } func (c *ConsoleLinkReconciler) Reconcile(ctx *chetypes.DeployContext) (reconcile.Result, bool, error) { - if !infrastructure.IsOpenShift() || !utils.IsK8SResourceServed(ctx.ClusterAPI.DiscoveryClient, ConsoleLinksResourceName) { + if !utils.IsK8SResourceServed(ctx.ClusterAPI.DiscoveryClient, ConsoleLinksResourceName) { logrus.Debug("Console link won't be created. ConsoleLinks is not supported by kubernetes cluster.") return reconcile.Result{}, true, nil } diff --git a/pkg/deploy/dashboard/dashboard_deployment_test.go b/pkg/deploy/dashboard/dashboard_deployment_test.go index d68d49b11..6c3dc20d4 100644 --- a/pkg/deploy/dashboard/dashboard_deployment_test.go +++ b/pkg/deploy/dashboard/dashboard_deployment_test.go @@ -15,6 +15,8 @@ package dashboard import ( "os" + fakeDiscovery "k8s.io/client-go/discovery/fake" + "k8s.io/apimachinery/pkg/api/resource" "github.com/devfile/devworkspace-operator/pkg/infrastructure" @@ -236,6 +238,13 @@ func TestDashboardDeploymentEnvVars(t *testing.T) { t.Run(testCase.name, func(t *testing.T) { logf.SetLogger(zap.New(zap.WriteTo(os.Stdout), zap.UseDevMode(true))) ctx := test.GetDeployContext(testCase.cheCluster, testCase.initObjects) + ctx.ClusterAPI.DiscoveryClient.(*fakeDiscovery.FakeDiscovery).Fake.Resources = []*metav1.APIResourceList{ + { + APIResources: []metav1.APIResource{ + {Name: ConsoleLinksResourceName}, + }, + }, + } dashboard := NewDashboardReconciler() deployment, err := dashboard.getDashboardDeploymentSpec(ctx) diff --git a/pkg/deploy/dashboard/deployment_dashboard.go b/pkg/deploy/dashboard/deployment_dashboard.go index fe5383add..3f56f34c2 100644 --- a/pkg/deploy/dashboard/deployment_dashboard.go +++ b/pkg/deploy/dashboard/deployment_dashboard.go @@ -16,7 +16,6 @@ import ( "context" "fmt" - "github.com/devfile/devworkspace-operator/pkg/infrastructure" "github.com/eclipse-che/che-operator/pkg/common/chetypes" "github.com/eclipse-che/che-operator/pkg/common/constants" defaults "github.com/eclipse-che/che-operator/pkg/common/operator-defaults" @@ -32,8 +31,11 @@ import ( "k8s.io/apimachinery/pkg/util/intstr" ) -const CHE_SELF_SIGNED_MOUNT_PATH = "/public-certs/che-self-signed" -const CHE_CUSTOM_CERTS_MOUNT_PATH = "/public-certs/custom" +const ( + CHE_SELF_SIGNED_MOUNT_PATH = "/public-certs/che-self-signed" + CHE_CUSTOM_CERTS_MOUNT_PATH = "/public-certs/custom" + ConsoleLinksResourceName = "consolelinks" +) func (d *DashboardReconciler) getDashboardDeploymentSpec(ctx *chetypes.DeployContext) (*appsv1.Deployment, error) { var volumes []corev1.Volume @@ -73,7 +75,7 @@ func (d *DashboardReconciler) getDashboardDeploymentSpec(ctx *chetypes.DeployCon Value: fmt.Sprintf("http://%s.%s.svc:8080/api", deploy.CheServiceName, ctx.CheCluster.Namespace)}, ) - if infrastructure.IsOpenShift() { + if utils.IsK8SResourceServed(ctx.ClusterAPI.DiscoveryClient, ConsoleLinksResourceName) { envVars = append(envVars, corev1.EnvVar{ Name: "OPENSHIFT_CONSOLE_URL",