feat: Add support for configuring the labels for gateway configmaps (#860)

Add support for configuring the labels using which the gateway configmaps
are identified to v2alpha1.

Co-authored-by: Anatolii Bazko <abazko@redhat.com>
pull/869/head
Lukas Krejci 2021-06-11 08:14:11 +02:00 committed by GitHub
parent 6a8ae2a197
commit af0d7c83b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 10 deletions

View File

@ -55,6 +55,7 @@ func V1ToV2alpha1(v1 *v1.CheCluster, v2 *v2alpha1.CheCluster) error {
v1ToV2alpha1_GatewayImage(v1, v2) v1ToV2alpha1_GatewayImage(v1, v2)
v1ToV2alpha1_GatewayConfigurerImage(v1, v2) v1ToV2alpha1_GatewayConfigurerImage(v1, v2)
v1ToV2alpha1_GatewayTlsSecretName(v1, v2) v1ToV2alpha1_GatewayTlsSecretName(v1, v2)
v1toV2alpha1_GatewayConfigLabels(v1, v2)
v1ToV2alpha1_WorkspaceDomainEndpointsBaseDomain(v1, v2) v1ToV2alpha1_WorkspaceDomainEndpointsBaseDomain(v1, v2)
v1ToV2alpha1_WorkspaceDomainEndpointsTlsSecretName(v1, v2) v1ToV2alpha1_WorkspaceDomainEndpointsTlsSecretName(v1, v2)
v1ToV2alpha1_K8sIngressAnnotations(v1, v2) v1ToV2alpha1_K8sIngressAnnotations(v1, v2)
@ -91,6 +92,7 @@ func V2alpha1ToV1(v2 *v2alpha1.CheCluster, v1Obj *v1.CheCluster) error {
v2alpha1ToV1_GatewayImage(v1Obj, v2) v2alpha1ToV1_GatewayImage(v1Obj, v2)
v2alpha1ToV1_GatewayConfigurerImage(v1Obj, v2) v2alpha1ToV1_GatewayConfigurerImage(v1Obj, v2)
v2alpha1ToV1_GatewayTlsSecretName(v1Obj, v2) v2alpha1ToV1_GatewayTlsSecretName(v1Obj, v2)
v2alpha1ToV1_GatewayConfigLabels(v1Obj, v2)
v2alpha1ToV1_WorkspaceDomainEndpointsBaseDomain(v1Obj, v2) v2alpha1ToV1_WorkspaceDomainEndpointsBaseDomain(v1Obj, v2)
v2alpha1ToV1_WorkspaceDomainEndpointsTlsSecretName(v1Obj, v2) v2alpha1ToV1_WorkspaceDomainEndpointsTlsSecretName(v1Obj, v2)
v2alpha1ToV1_K8sIngressAnnotations(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 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) { 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 // 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 { 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 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) { func v2alpha1ToV1_K8sIngressAnnotations(v1 *v1.CheCluster, v2 *v2alpha1.CheCluster) {
ingressClass := v2.Spec.K8s.IngressAnnotations["kubernetes.io/ingress.class"] ingressClass := v2.Spec.K8s.IngressAnnotations["kubernetes.io/ingress.class"]
if ingressClass == "" { if ingressClass == "" {

View File

@ -11,6 +11,7 @@ import (
"github.com/eclipse-che/che-operator/pkg/util" "github.com/eclipse-che/che-operator/pkg/util"
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/utils/pointer" "k8s.io/utils/pointer"
"sigs.k8s.io/yaml" "sigs.k8s.io/yaml"
) )
@ -52,6 +53,10 @@ func TestV1ToV2alpha1(t *testing.T) {
CheImage: "teh-che-severe", CheImage: "teh-che-severe",
SingleHostGatewayImage: "single-host-image-of-the-year", SingleHostGatewayImage: "single-host-image-of-the-year",
CheHostTLSSecret: "cheSecret", CheHostTLSSecret: "cheSecret",
SingleHostGatewayConfigMapLabels: labels.Set{
"a": "b",
"c": "d",
},
CustomCheProperties: map[string]string{ CustomCheProperties: map[string]string{
"CHE_INFRA_OPENSHIFT_ROUTE_HOST_DOMAIN__SUFFIX": "routeDomain", "CHE_INFRA_OPENSHIFT_ROUTE_HOST_DOMAIN__SUFFIX": "routeDomain",
}, },
@ -217,6 +222,18 @@ func TestV1ToV2alpha1(t *testing.T) {
t.Errorf("Unexpected TlsSecretName") 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) { func TestV2alpha1ToV1(t *testing.T) {
@ -240,6 +257,9 @@ func TestV2alpha1ToV1(t *testing.T) {
Image: "gateway-image", Image: "gateway-image",
ConfigurerImage: "configurer-image", ConfigurerImage: "configurer-image",
TlsSecretName: "superSecret", TlsSecretName: "superSecret",
ConfigLabels: labels.Set{
"a": "b",
},
}, },
K8s: v2alpha1.CheClusterSpecK8s{ K8s: v2alpha1.CheClusterSpecK8s{
IngressAnnotations: map[string]string{ IngressAnnotations: map[string]string{
@ -399,6 +419,18 @@ func TestV2alpha1ToV1(t *testing.T) {
t.Errorf("Unexpected TlsSecretName: %s", v1.Spec.Server.CheHostTLSSecret) 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) { func TestExposureStrategyConversions(t *testing.T) {
@ -612,6 +644,9 @@ func TestFullCircleV1(t *testing.T) {
CheImage: "teh-che-severe", CheImage: "teh-che-severe",
SingleHostGatewayImage: "single-host-image-of-the-year", SingleHostGatewayImage: "single-host-image-of-the-year",
CheHostTLSSecret: "cheSecret", CheHostTLSSecret: "cheSecret",
SingleHostGatewayConfigMapLabels: labels.Set{
"a": "b",
},
CustomCheProperties: map[string]string{ CustomCheProperties: map[string]string{
"CHE_INFRA_OPENSHIFT_ROUTE_HOST_DOMAIN__SUFFIX": "routeDomain", "CHE_INFRA_OPENSHIFT_ROUTE_HOST_DOMAIN__SUFFIX": "routeDomain",
}, },
@ -654,6 +689,9 @@ func TestFullCircleV2(t *testing.T) {
Image: "gateway-image", Image: "gateway-image",
ConfigurerImage: "configurer-image", ConfigurerImage: "configurer-image",
TlsSecretName: "superSecret", TlsSecretName: "superSecret",
ConfigLabels: labels.Set{
"a": "b",
},
}, },
K8s: v2alpha1.CheClusterSpecK8s{ K8s: v2alpha1.CheClusterSpecK8s{
IngressAnnotations: map[string]string{ IngressAnnotations: map[string]string{
@ -700,13 +738,3 @@ func onFakeKubernetes(f func()) {
util.IsOpenShift = origOpenshift util.IsOpenShift = origOpenshift
util.IsOpenShift4 = origOpenshift4 util.IsOpenShift4 = origOpenshift4
} }
func toString(b *bool) string {
if b == nil {
return "nil"
} else if *b {
return "true"
} else {
return "false"
}
}

View File

@ -14,6 +14,7 @@ package v2alpha1
import ( import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 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 // 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. // deployment/pod. If not defined there, it defaults to a hardcoded value.
ConfigurerImage string `json:"configurerImage,omitempty"` 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. // CheClusterSpecK8s contains the configuration options specific to Kubernetes only.