From 268899efa6aa58483ed5fbca1412803e78194bb6 Mon Sep 17 00:00:00 2001 From: Anatolii Bazko Date: Fri, 9 Apr 2021 10:33:15 +0300 Subject: [PATCH] Fix getting exposure strategy in case of k8s (#766) * Fix getting exposure strategy in case of k8s Signed-off-by: Anatolii Bazko --- pkg/controller/che/che_controller.go | 2 +- pkg/deploy/expose/expose.go | 2 +- pkg/deploy/gateway/gateway.go | 2 +- pkg/deploy/ingress.go | 2 +- pkg/deploy/server/che_configmap.go | 2 +- pkg/deploy/server/che_configmap_test.go | 20 ++++++++++++++++++++ 6 files changed, 25 insertions(+), 5 deletions(-) diff --git a/pkg/controller/che/che_controller.go b/pkg/controller/che/che_controller.go index 29558acf4..cd0b8b137 100644 --- a/pkg/controller/che/che_controller.go +++ b/pkg/controller/che/che_controller.go @@ -994,7 +994,7 @@ func getDefaultCheHost(deployContext *deploy.DeployContext) (string, error) { } func getServerExposingServiceName(cr *orgv1.CheCluster) string { - if util.GetValue(cr.Spec.Server.ServerExposureStrategy, deploy.DefaultServerExposureStrategy) == "single-host" && deploy.GetSingleHostExposureType(cr) == "gateway" { + if util.GetServerExposureStrategy(cr) == "single-host" && deploy.GetSingleHostExposureType(cr) == "gateway" { return gateway.GatewayServiceName } return deploy.CheServiceName diff --git a/pkg/deploy/expose/expose.go b/pkg/deploy/expose/expose.go index 487082c71..196d369cc 100644 --- a/pkg/deploy/expose/expose.go +++ b/pkg/deploy/expose/expose.go @@ -28,7 +28,7 @@ func Expose( routeCustomSettings orgv1.RouteCustomSettings, ingressCustomSettings orgv1.IngressCustomSettings, component string) (endpont string, done bool, err error) { - exposureStrategy := util.GetValue(deployContext.CheCluster.Spec.Server.ServerExposureStrategy, deploy.DefaultServerExposureStrategy) + exposureStrategy := util.GetServerExposureStrategy(deployContext.CheCluster) var domain string var endpoint string var pathPrefix string diff --git a/pkg/deploy/gateway/gateway.go b/pkg/deploy/gateway/gateway.go index fef5874f6..941891d27 100644 --- a/pkg/deploy/gateway/gateway.go +++ b/pkg/deploy/gateway/gateway.go @@ -54,7 +54,7 @@ var ( // SyncGatewayToCluster installs or deletes the gateway based on the custom resource configuration func SyncGatewayToCluster(deployContext *deploy.DeployContext) error { - if util.GetValue(deployContext.CheCluster.Spec.Server.ServerExposureStrategy, deploy.DefaultServerExposureStrategy) == "single-host" && + if util.GetServerExposureStrategy(deployContext.CheCluster) == "single-host" && (deploy.GetSingleHostExposureType(deployContext.CheCluster) == "gateway") { return syncAll(deployContext) } diff --git a/pkg/deploy/ingress.go b/pkg/deploy/ingress.go index 89dfdb3ce..e59bed084 100644 --- a/pkg/deploy/ingress.go +++ b/pkg/deploy/ingress.go @@ -55,7 +55,7 @@ func GetIngressSpec( component string) *v1beta1.Ingress { tlsSupport := deployContext.CheCluster.Spec.Server.TlsSupport - ingressStrategy := util.GetValue(deployContext.CheCluster.Spec.Server.ServerExposureStrategy, DefaultServerExposureStrategy) + ingressStrategy := util.GetServerExposureStrategy(deployContext.CheCluster) ingressDomain := deployContext.CheCluster.Spec.K8s.IngressDomain ingressClass := util.GetValue(deployContext.CheCluster.Spec.K8s.IngressClass, DefaultIngressClass) labels := GetLabels(deployContext.CheCluster, component) diff --git a/pkg/deploy/server/che_configmap.go b/pkg/deploy/server/che_configmap.go index cdda6e8a6..51a1419fc 100644 --- a/pkg/deploy/server/che_configmap.go +++ b/pkg/deploy/server/che_configmap.go @@ -158,7 +158,7 @@ func GetCheConfigMapData(deployContext *deploy.DeployContext) (cheEnv map[string chePostgresDb := util.GetValue(deployContext.CheCluster.Spec.Database.ChePostgresDb, deploy.DefaultChePostgresDb) keycloakRealm := util.GetValue(deployContext.CheCluster.Spec.Auth.IdentityProviderRealm, cheFlavor) keycloakClientId := util.GetValue(deployContext.CheCluster.Spec.Auth.IdentityProviderClientId, cheFlavor+"-public") - ingressStrategy := util.GetValue(deployContext.CheCluster.Spec.Server.ServerExposureStrategy, deploy.DefaultServerExposureStrategy) + ingressStrategy := util.GetServerExposureStrategy(deployContext.CheCluster) ingressClass := util.GetValue(deployContext.CheCluster.Spec.K8s.IngressClass, deploy.DefaultIngressClass) devfileRegistryURL := deployContext.CheCluster.Status.DevfileRegistryURL pluginRegistryURL := deployContext.CheCluster.Status.PluginRegistryURL diff --git a/pkg/deploy/server/che_configmap_test.go b/pkg/deploy/server/che_configmap_test.go index 89557b739..999c234ae 100644 --- a/pkg/deploy/server/che_configmap_test.go +++ b/pkg/deploy/server/che_configmap_test.go @@ -482,6 +482,26 @@ func TestShouldSetUpCorrectlyInternalDevfileRegistryServiceURL(t *testing.T) { "CHE_WORKSPACE_DEVFILE__REGISTRY__INTERNAL__URL": "http://devfile-registry.eclipse-che.svc:8080", }, }, + { + name: "Kubernetes strategy should be set correctly", + cheCluster: &orgv1.CheCluster{ + TypeMeta: metav1.TypeMeta{ + Kind: "CheCluster", + APIVersion: "org.eclipse.che/v1", + }, + ObjectMeta: metav1.ObjectMeta{ + Namespace: "eclipse-che", + }, + Spec: orgv1.CheClusterSpec{ + K8s: orgv1.CheClusterSpecK8SOnly{ + IngressStrategy: "single-host", + }, + }, + }, + expectedData: map[string]string{ + "CHE_INFRA_KUBERNETES_SERVER__STRATEGY": "single-host", + }, + }, } for _, testCase := range testCases {