diff --git a/pkg/apis/org/conversion.go b/pkg/apis/org/conversion.go index 4b0b3d9ac..fa3e9be23 100644 --- a/pkg/apis/org/conversion.go +++ b/pkg/apis/org/conversion.go @@ -55,6 +55,7 @@ func V1ToV2alpha1(v1 *v1.CheCluster, v2 *v2alpha1.CheCluster) error { v1ToV2alpha1_GatewayImage(v1, v2) v1ToV2alpha1_GatewayConfigurerImage(v1, v2) v1ToV2alpha1_GatewayTlsSecretName(v1, v2) + v1toV2alpha1_GatewayConfigLabels(v1, v2) v1ToV2alpha1_WorkspaceDomainEndpointsBaseDomain(v1, v2) v1ToV2alpha1_WorkspaceDomainEndpointsTlsSecretName(v1, v2) v1ToV2alpha1_K8sIngressAnnotations(v1, v2) @@ -91,6 +92,7 @@ func V2alpha1ToV1(v2 *v2alpha1.CheCluster, v1Obj *v1.CheCluster) error { v2alpha1ToV1_GatewayImage(v1Obj, v2) v2alpha1ToV1_GatewayConfigurerImage(v1Obj, v2) v2alpha1ToV1_GatewayTlsSecretName(v1Obj, v2) + v2alpha1ToV1_GatewayConfigLabels(v1Obj, v2) v2alpha1ToV1_WorkspaceDomainEndpointsBaseDomain(v1Obj, v2) v2alpha1ToV1_WorkspaceDomainEndpointsTlsSecretName(v1Obj, v2) v2alpha1ToV1_K8sIngressAnnotations(v1Obj, v2) @@ -151,6 +153,10 @@ func v1ToV2alpha1_GatewayTlsSecretName(v1 *v1.CheCluster, v2 *v2alpha1.CheCluste v2.Spec.Gateway.TlsSecretName = v1.Spec.Server.CheHostTLSSecret } +func v1toV2alpha1_GatewayConfigLabels(v1 *v1.CheCluster, v2 *v2alpha1.CheCluster) { + v2.Spec.Gateway.ConfigLabels = v1.Spec.Server.SingleHostGatewayConfigMapLabels +} + func v1ToV2alpha1_K8sIngressAnnotations(v1 *v1.CheCluster, v2 *v2alpha1.CheCluster) { // The only property in v1 spec that boils down to the ingress annotations is the K8s.IngressClass if v1.Spec.K8s.IngressClass != "" && v1.Spec.K8s.IngressClass != defaultV2alpha1IngressClass { @@ -269,6 +275,10 @@ func v2alpha1ToV1_GatewayTlsSecretName(v1 *v1.CheCluster, v2 *v2alpha1.CheCluste v1.Spec.Server.CheHostTLSSecret = v2.Spec.Gateway.TlsSecretName } +func v2alpha1ToV1_GatewayConfigLabels(v1 *v1.CheCluster, v2 *v2alpha1.CheCluster) { + v1.Spec.Server.SingleHostGatewayConfigMapLabels = v2.Spec.Gateway.ConfigLabels +} + func v2alpha1ToV1_K8sIngressAnnotations(v1 *v1.CheCluster, v2 *v2alpha1.CheCluster) { ingressClass := v2.Spec.K8s.IngressAnnotations["kubernetes.io/ingress.class"] if ingressClass == "" { diff --git a/pkg/apis/org/conversion_test.go b/pkg/apis/org/conversion_test.go index 3126087b6..4c6d1394e 100644 --- a/pkg/apis/org/conversion_test.go +++ b/pkg/apis/org/conversion_test.go @@ -11,6 +11,7 @@ import ( "github.com/eclipse-che/che-operator/pkg/util" "github.com/google/go-cmp/cmp" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/labels" "k8s.io/utils/pointer" "sigs.k8s.io/yaml" ) @@ -52,6 +53,10 @@ func TestV1ToV2alpha1(t *testing.T) { CheImage: "teh-che-severe", SingleHostGatewayImage: "single-host-image-of-the-year", CheHostTLSSecret: "cheSecret", + SingleHostGatewayConfigMapLabels: labels.Set{ + "a": "b", + "c": "d", + }, CustomCheProperties: map[string]string{ "CHE_INFRA_OPENSHIFT_ROUTE_HOST_DOMAIN__SUFFIX": "routeDomain", }, @@ -217,6 +222,18 @@ func TestV1ToV2alpha1(t *testing.T) { t.Errorf("Unexpected TlsSecretName") } }) + + t.Run("GatewayConfigLabels", func(t *testing.T) { + v2 := &v2alpha1.CheCluster{} + err := V1ToV2alpha1(&v1Obj, v2) + if err != nil { + t.Error(err) + } + + if !reflect.DeepEqual(v2.Spec.Gateway.ConfigLabels, v1Obj.Spec.Server.SingleHostGatewayConfigMapLabels) { + t.Errorf("Unexpected Spec.Gateway.ConfigLabels: %v", cmp.Diff(v1Obj.Spec.Server.SingleHostGatewayConfigMapLabels, v2.Spec.Gateway.ConfigLabels)) + } + }) } func TestV2alpha1ToV1(t *testing.T) { @@ -240,6 +257,9 @@ func TestV2alpha1ToV1(t *testing.T) { Image: "gateway-image", ConfigurerImage: "configurer-image", TlsSecretName: "superSecret", + ConfigLabels: labels.Set{ + "a": "b", + }, }, K8s: v2alpha1.CheClusterSpecK8s{ IngressAnnotations: map[string]string{ @@ -399,6 +419,18 @@ func TestV2alpha1ToV1(t *testing.T) { t.Errorf("Unexpected TlsSecretName: %s", v1.Spec.Server.CheHostTLSSecret) } }) + + t.Run("GatewayConfigLabels", func(t *testing.T) { + v1 := &v1.CheCluster{} + err := V2alpha1ToV1(&v2Obj, v1) + if err != nil { + t.Error(err) + } + + if !reflect.DeepEqual(v1.Spec.Server.SingleHostGatewayConfigMapLabels, v2Obj.Spec.Gateway.ConfigLabels) { + t.Errorf("Unexpected SingleHostGatewayConfigMapLabels: %s", v1.Spec.Server.SingleHostGatewayConfigMapLabels) + } + }) } func TestExposureStrategyConversions(t *testing.T) { @@ -612,6 +644,9 @@ func TestFullCircleV1(t *testing.T) { CheImage: "teh-che-severe", SingleHostGatewayImage: "single-host-image-of-the-year", CheHostTLSSecret: "cheSecret", + SingleHostGatewayConfigMapLabels: labels.Set{ + "a": "b", + }, CustomCheProperties: map[string]string{ "CHE_INFRA_OPENSHIFT_ROUTE_HOST_DOMAIN__SUFFIX": "routeDomain", }, @@ -654,6 +689,9 @@ func TestFullCircleV2(t *testing.T) { Image: "gateway-image", ConfigurerImage: "configurer-image", TlsSecretName: "superSecret", + ConfigLabels: labels.Set{ + "a": "b", + }, }, K8s: v2alpha1.CheClusterSpecK8s{ IngressAnnotations: map[string]string{ @@ -700,13 +738,3 @@ func onFakeKubernetes(f func()) { util.IsOpenShift = origOpenshift util.IsOpenShift4 = origOpenshift4 } - -func toString(b *bool) string { - if b == nil { - return "nil" - } else if *b { - return "true" - } else { - return "false" - } -} diff --git a/pkg/apis/org/v2alpha1/checluster.go b/pkg/apis/org/v2alpha1/checluster.go index b4ad95ffa..3f4e00b9e 100644 --- a/pkg/apis/org/v2alpha1/checluster.go +++ b/pkg/apis/org/v2alpha1/checluster.go @@ -14,6 +14,7 @@ package v2alpha1 import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/labels" ) // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! @@ -104,6 +105,11 @@ type CheGatewaySpec struct { // it is taken from the `RELATED_IMAGE_gateway_configurer` environment variable of the operator // deployment/pod. If not defined there, it defaults to a hardcoded value. ConfigurerImage string `json:"configurerImage,omitempty"` + + // ConfigLabels are labels that are put on the gateway configuration configmaps so that they are picked up + // by the gateway configurer. The default value are labels: app=che,component=che-gateway-config + // +optional + ConfigLabels labels.Set `json:"configLabels,omitempty"` } // CheClusterSpecK8s contains the configuration options specific to Kubernetes only.