From b5feb52494c10643f1cbd81787c861232aff7383 Mon Sep 17 00:00:00 2001 From: Flavius Lacatusu Date: Wed, 19 May 2021 15:43:39 +0200 Subject: [PATCH 1/2] Fix dashboard component names depending on che flavor Signed-off-by: Flavius Lacatusu --- pkg/controller/che/che_controller.go | 2 +- pkg/deploy/dashboard/dashboard.go | 11 ++++----- pkg/deploy/dashboard/dashboard_test.go | 6 ++--- pkg/deploy/dashboard/deployment_dashboard.go | 24 ++++++++++---------- pkg/deploy/defaults.go | 10 ++++++++ 5 files changed, 30 insertions(+), 23 deletions(-) diff --git a/pkg/controller/che/che_controller.go b/pkg/controller/che/che_controller.go index 35768af46..d278a0b3d 100644 --- a/pkg/controller/che/che_controller.go +++ b/pkg/controller/che/che_controller.go @@ -803,7 +803,7 @@ func (r *ReconcileChe) Reconcile(request reconcile.Request) (reconcile.Result, e done, err = d.SyncAll() if !done { if err != nil { - logrus.Errorf("Error provisioning '%s' to cluster: %v", dashboard.DashboardComponent, err) + logrus.Errorf("Error provisioning '%s' to cluster: %v", deploy.DefaultDashboardComponent(instance), err) } return reconcile.Result{}, err } diff --git a/pkg/deploy/dashboard/dashboard.go b/pkg/deploy/dashboard/dashboard.go index 0461b316b..36ca7d3c9 100644 --- a/pkg/deploy/dashboard/dashboard.go +++ b/pkg/deploy/dashboard/dashboard.go @@ -16,30 +16,27 @@ import ( "github.com/eclipse-che/che-operator/pkg/deploy/expose" ) -const ( - // DashboardComponent which is supposed to be used for the naming related objects - DashboardComponent = "che-dashboard" -) - type Dashboard struct { deployContext *deploy.DeployContext + component string } func NewDashboard(deployContext *deploy.DeployContext) *Dashboard { return &Dashboard{ deployContext: deployContext, + component: deploy.DefaultDashboardComponent(deployContext.CheCluster), } } func (d *Dashboard) SyncAll() (done bool, err error) { // Create a new dashboard service - done, err = deploy.SyncServiceToCluster(d.deployContext, DashboardComponent, []string{"http"}, []int32{8080}, DashboardComponent) + done, err = deploy.SyncServiceToCluster(d.deployContext, d.component, []string{"http"}, []int32{8080}, d.component) if !done { return false, err } // Expose dashboard service with route or ingress - _, done, err = expose.ExposeWithHostPath(d.deployContext, DashboardComponent, d.deployContext.CheCluster.Spec.Server.CheHost, + _, done, err = expose.ExposeWithHostPath(d.deployContext, d.component, d.deployContext.CheCluster.Spec.Server.CheHost, "/dashboard", d.deployContext.CheCluster.Spec.Server.CheServerRoute, d.deployContext.CheCluster.Spec.Server.CheServerIngress, diff --git a/pkg/deploy/dashboard/dashboard_test.go b/pkg/deploy/dashboard/dashboard_test.go index 315ab8cbf..6af94ff8b 100644 --- a/pkg/deploy/dashboard/dashboard_test.go +++ b/pkg/deploy/dashboard/dashboard_test.go @@ -60,21 +60,21 @@ func TestDashboardAll(t *testing.T) { // check service service := &corev1.Service{} - err = cli.Get(context.TODO(), types.NamespacedName{Name: DashboardComponent, Namespace: "eclipse-che"}, service) + err = cli.Get(context.TODO(), types.NamespacedName{Name: deploy.CheDashboardComponent, Namespace: "eclipse-che"}, service) if err != nil { t.Fatalf("Service not found: %v", err) } // check endpoint route := &routev1.Route{} - err = cli.Get(context.TODO(), types.NamespacedName{Name: DashboardComponent, Namespace: "eclipse-che"}, route) + err = cli.Get(context.TODO(), types.NamespacedName{Name: deploy.CheDashboardComponent, Namespace: "eclipse-che"}, route) if err != nil { t.Fatalf("Route not found: %v", err) } // check deployment deployment := &appsv1.Deployment{} - err = cli.Get(context.TODO(), types.NamespacedName{Name: DashboardComponent, Namespace: "eclipse-che"}, deployment) + err = cli.Get(context.TODO(), types.NamespacedName{Name: deploy.CheDashboardComponent, Namespace: "eclipse-che"}, deployment) if err != nil { t.Fatalf("Deployment not found: %v", err) } diff --git a/pkg/deploy/dashboard/deployment_dashboard.go b/pkg/deploy/dashboard/deployment_dashboard.go index 55a9cc906..3e82a742f 100644 --- a/pkg/deploy/dashboard/deployment_dashboard.go +++ b/pkg/deploy/dashboard/deployment_dashboard.go @@ -22,12 +22,12 @@ import ( "k8s.io/apimachinery/pkg/util/intstr" ) -func (p *Dashboard) getDashboardDeploymentSpec() (*appsv1.Deployment, error) { +func (d *Dashboard) getDashboardDeploymentSpec() (*appsv1.Deployment, error) { terminationGracePeriodSeconds := int64(30) - labels, labelsSelector := deploy.GetLabelsAndSelector(p.deployContext.CheCluster, DashboardComponent) + labels, labelsSelector := deploy.GetLabelsAndSelector(d.deployContext.CheCluster, d.component) - dashboardImageAndTag := util.GetValue(p.deployContext.CheCluster.Spec.Server.DashboardImage, deploy.DefaultDashboardImage(p.deployContext.CheCluster)) - pullPolicy := corev1.PullPolicy(util.GetValue(p.deployContext.CheCluster.Spec.Server.DashboardImagePullPolicy, deploy.DefaultPullPolicyFromDockerImage(dashboardImageAndTag))) + dashboardImageAndTag := util.GetValue(d.deployContext.CheCluster.Spec.Server.DashboardImage, deploy.DefaultDashboardImage(d.deployContext.CheCluster)) + pullPolicy := corev1.PullPolicy(util.GetValue(d.deployContext.CheCluster.Spec.Server.DashboardImagePullPolicy, deploy.DefaultPullPolicyFromDockerImage(dashboardImageAndTag))) deployment := &appsv1.Deployment{ TypeMeta: metav1.TypeMeta{ @@ -35,8 +35,8 @@ func (p *Dashboard) getDashboardDeploymentSpec() (*appsv1.Deployment, error) { APIVersion: "apps/v1", }, ObjectMeta: metav1.ObjectMeta{ - Name: DashboardComponent, - Namespace: p.deployContext.CheCluster.Namespace, + Name: d.component, + Namespace: d.deployContext.CheCluster.Namespace, Labels: labels, }, Spec: appsv1.DeploymentSpec{ @@ -64,18 +64,18 @@ func (p *Dashboard) getDashboardDeploymentSpec() (*appsv1.Deployment, error) { Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{ corev1.ResourceMemory: util.GetResourceQuantity( - p.deployContext.CheCluster.Spec.Server.DashboardMemoryRequest, + d.deployContext.CheCluster.Spec.Server.DashboardMemoryRequest, deploy.DefaultDashboardMemoryRequest), corev1.ResourceCPU: util.GetResourceQuantity( - p.deployContext.CheCluster.Spec.Server.DashboardCpuRequest, + d.deployContext.CheCluster.Spec.Server.DashboardCpuRequest, deploy.DefaultDashboardCpuRequest), }, Limits: corev1.ResourceList{ corev1.ResourceMemory: util.GetResourceQuantity( - p.deployContext.CheCluster.Spec.Server.DashboardMemoryLimit, + d.deployContext.CheCluster.Spec.Server.DashboardMemoryLimit, deploy.DefaultDashboardMemoryLimit), corev1.ResourceCPU: util.GetResourceQuantity( - p.deployContext.CheCluster.Spec.Server.DashboardCpuLimit, + d.deployContext.CheCluster.Spec.Server.DashboardCpuLimit, deploy.DefaultDashboardCpuLimit), }, }, @@ -128,11 +128,11 @@ func (p *Dashboard) getDashboardDeploymentSpec() (*appsv1.Deployment, error) { } if !util.IsOpenShift { - runAsUser, err := strconv.ParseInt(util.GetValue(p.deployContext.CheCluster.Spec.K8s.SecurityContextRunAsUser, deploy.DefaultSecurityContextRunAsUser), 10, 64) + runAsUser, err := strconv.ParseInt(util.GetValue(d.deployContext.CheCluster.Spec.K8s.SecurityContextRunAsUser, deploy.DefaultSecurityContextRunAsUser), 10, 64) if err != nil { return nil, err } - fsGroup, err := strconv.ParseInt(util.GetValue(p.deployContext.CheCluster.Spec.K8s.SecurityContextFsGroup, deploy.DefaultSecurityContextFsGroup), 10, 64) + fsGroup, err := strconv.ParseInt(util.GetValue(d.deployContext.CheCluster.Spec.K8s.SecurityContextFsGroup, deploy.DefaultSecurityContextFsGroup), 10, 64) if err != nil { return nil, err } diff --git a/pkg/deploy/defaults.go b/pkg/deploy/defaults.go index 660f22421..e188a78db 100644 --- a/pkg/deploy/defaults.go +++ b/pkg/deploy/defaults.go @@ -154,6 +154,9 @@ const ( BitBucketOAuthConfigMountPath = "/che-conf/oauth/bitbucket" BitBucketOAuthConfigPrivateKey = "private.key" BitBucketOAuthConfigConsumerKey = "consumer.key" + + CodeReadyDashboardComponent = "codeready-dashboard" + CheDashboardComponent = "che-dashboard" ) func InitDefaults(defaultsPath string) { @@ -236,6 +239,13 @@ func DefaultCheFlavor(cr *orgv1.CheCluster) string { return util.GetValue(cr.Spec.Server.CheFlavor, getDefaultFromEnv("CHE_FLAVOR")) } +func DefaultDashboardComponent(cr *orgv1.CheCluster) string { + if DefaultCheFlavor(cr) == "codeready" { + return CodeReadyDashboardComponent + } + return CheDashboardComponent +} + func DefaultConsoleLinkName() string { return getDefaultFromEnv("CONSOLE_LINK_NAME") } From 2905b674e92c06cb087adf79ff788e050d1bbd4a Mon Sep 17 00:00:00 2001 From: Flavius Lacatusu Date: Thu, 20 May 2021 09:34:26 +0200 Subject: [PATCH 2/2] Minor fixes Signed-off-by: Flavius Lacatusu --- pkg/controller/che/che_controller.go | 2 +- pkg/deploy/dashboard/dashboard.go | 6 +++++- pkg/deploy/dashboard/dashboard_test.go | 6 +++--- pkg/deploy/dashboard/deployment_dashboard.go | 2 +- pkg/deploy/defaults.go | 10 ---------- 5 files changed, 10 insertions(+), 16 deletions(-) diff --git a/pkg/controller/che/che_controller.go b/pkg/controller/che/che_controller.go index d278a0b3d..270dbc9e4 100644 --- a/pkg/controller/che/che_controller.go +++ b/pkg/controller/che/che_controller.go @@ -803,7 +803,7 @@ func (r *ReconcileChe) Reconcile(request reconcile.Request) (reconcile.Result, e done, err = d.SyncAll() if !done { if err != nil { - logrus.Errorf("Error provisioning '%s' to cluster: %v", deploy.DefaultDashboardComponent(instance), err) + logrus.Errorf("Error provisioning '%s' to cluster: %v", d.GetComponentName(), err) } return reconcile.Result{}, err } diff --git a/pkg/deploy/dashboard/dashboard.go b/pkg/deploy/dashboard/dashboard.go index 36ca7d3c9..c9d32ea70 100644 --- a/pkg/deploy/dashboard/dashboard.go +++ b/pkg/deploy/dashboard/dashboard.go @@ -24,7 +24,7 @@ type Dashboard struct { func NewDashboard(deployContext *deploy.DeployContext) *Dashboard { return &Dashboard{ deployContext: deployContext, - component: deploy.DefaultDashboardComponent(deployContext.CheCluster), + component: deploy.DefaultCheFlavor(deployContext.CheCluster) + "-dashboard", } } @@ -52,3 +52,7 @@ func (d *Dashboard) SyncAll() (done bool, err error) { } return deploy.SyncDeploymentSpecToCluster(d.deployContext, spec, deploy.DefaultDeploymentDiffOpts) } + +func (d *Dashboard) GetComponentName() string { + return d.component +} diff --git a/pkg/deploy/dashboard/dashboard_test.go b/pkg/deploy/dashboard/dashboard_test.go index 6af94ff8b..809cb44c1 100644 --- a/pkg/deploy/dashboard/dashboard_test.go +++ b/pkg/deploy/dashboard/dashboard_test.go @@ -60,21 +60,21 @@ func TestDashboardAll(t *testing.T) { // check service service := &corev1.Service{} - err = cli.Get(context.TODO(), types.NamespacedName{Name: deploy.CheDashboardComponent, Namespace: "eclipse-che"}, service) + err = cli.Get(context.TODO(), types.NamespacedName{Name: dashboard.component, Namespace: "eclipse-che"}, service) if err != nil { t.Fatalf("Service not found: %v", err) } // check endpoint route := &routev1.Route{} - err = cli.Get(context.TODO(), types.NamespacedName{Name: deploy.CheDashboardComponent, Namespace: "eclipse-che"}, route) + err = cli.Get(context.TODO(), types.NamespacedName{Name: dashboard.component, Namespace: "eclipse-che"}, route) if err != nil { t.Fatalf("Route not found: %v", err) } // check deployment deployment := &appsv1.Deployment{} - err = cli.Get(context.TODO(), types.NamespacedName{Name: deploy.CheDashboardComponent, Namespace: "eclipse-che"}, deployment) + err = cli.Get(context.TODO(), types.NamespacedName{Name: dashboard.component, Namespace: "eclipse-che"}, deployment) if err != nil { t.Fatalf("Deployment not found: %v", err) } diff --git a/pkg/deploy/dashboard/deployment_dashboard.go b/pkg/deploy/dashboard/deployment_dashboard.go index 3e82a742f..f28ffff38 100644 --- a/pkg/deploy/dashboard/deployment_dashboard.go +++ b/pkg/deploy/dashboard/deployment_dashboard.go @@ -51,7 +51,7 @@ func (d *Dashboard) getDashboardDeploymentSpec() (*appsv1.Deployment, error) { Spec: corev1.PodSpec{ Containers: []corev1.Container{ { - Name: "dashboard", + Name: d.component, ImagePullPolicy: pullPolicy, Image: dashboardImageAndTag, Ports: []corev1.ContainerPort{ diff --git a/pkg/deploy/defaults.go b/pkg/deploy/defaults.go index e188a78db..660f22421 100644 --- a/pkg/deploy/defaults.go +++ b/pkg/deploy/defaults.go @@ -154,9 +154,6 @@ const ( BitBucketOAuthConfigMountPath = "/che-conf/oauth/bitbucket" BitBucketOAuthConfigPrivateKey = "private.key" BitBucketOAuthConfigConsumerKey = "consumer.key" - - CodeReadyDashboardComponent = "codeready-dashboard" - CheDashboardComponent = "che-dashboard" ) func InitDefaults(defaultsPath string) { @@ -239,13 +236,6 @@ func DefaultCheFlavor(cr *orgv1.CheCluster) string { return util.GetValue(cr.Spec.Server.CheFlavor, getDefaultFromEnv("CHE_FLAVOR")) } -func DefaultDashboardComponent(cr *orgv1.CheCluster) string { - if DefaultCheFlavor(cr) == "codeready" { - return CodeReadyDashboardComponent - } - return CheDashboardComponent -} - func DefaultConsoleLinkName() string { return getDefaultFromEnv("CONSOLE_LINK_NAME") }