Skip to content

Commit

Permalink
fix: ingress annotation when single-host and gateway exposure (#1200)
Browse files Browse the repository at this point in the history
* fix: ingress annotation when single-host and gateway exposure

Signed-off-by: disaster37 <linuxworkgroup@hotmail.com>
Signed-off-by: Anatolii Bazko <abazko@redhat.com>
  • Loading branch information
disaster37 committed Dec 17, 2021
1 parent f0bb5ae commit 7f8b40d
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 4 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ require (
github.com/openshift/api v3.9.1-0.20190924102528-32369d4db2ad+incompatible
github.com/operator-framework/api v0.10.0
github.com/operator-framework/operator-lifecycle-manager v0.18.1
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.7.0
github.com/stretchr/testify v1.7.0
go.uber.org/zap v1.18.1
Expand Down
149 changes: 148 additions & 1 deletion pkg/deploy/ingres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func TestIngressSpec(t *testing.T) {
servicePort int
ingressCustomSettings orgv1.IngressCustomSettings
expectedIngress *networking.Ingress
cheCluster *orgv1.CheCluster
}
cheFlavor := getDefaultFromEnv("CHE_FLAVOR")
cheCluster := &orgv1.CheCluster{
Expand All @@ -46,6 +47,17 @@ func TestIngressSpec(t *testing.T) {
Name: cheFlavor,
},
}
cheClusterWithGatewaySingleHostExposure := &orgv1.CheCluster{
ObjectMeta: metav1.ObjectMeta{
Namespace: "eclipse-che",
Name: cheFlavor,
},
Spec: orgv1.CheClusterSpec{
K8s: orgv1.CheClusterSpecK8SOnly{
SingleHostExposureType: GatewaySingleHostExposureType,
},
},
}

testCases := []testCase{
{
Expand All @@ -60,6 +72,140 @@ func TestIngressSpec(t *testing.T) {
Labels: "type=default",
Annotations: map[string]string{"annotation-key": "annotation-value"},
},
cheCluster: cheCluster,
expectedIngress: &networking.Ingress{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Namespace: "eclipse-che",
Labels: map[string]string{
"type": "default",
"app.kubernetes.io/component": DefaultCheFlavor(cheCluster),
"app.kubernetes.io/instance": DefaultCheFlavor(cheCluster),
"app.kubernetes.io/part-of": "che.eclipse.org",
"app.kubernetes.io/managed-by": DefaultCheFlavor(cheCluster) + "-operator",
"app.kubernetes.io/name": DefaultCheFlavor(cheCluster),
},
Annotations: map[string]string{
"che.eclipse.org/managed-annotations-digest": "0000",
"kubernetes.io/ingress.class": "nginx",
"nginx.ingress.kubernetes.io/proxy-connect-timeout": "3600",
"nginx.ingress.kubernetes.io/proxy-read-timeout": "3600",
"nginx.ingress.kubernetes.io/ssl-redirect": "false",
"nginx.ingress.kubernetes.io/proxy-buffer-size": "16k",
"nginx.org/websocket-services": "che-host",
"annotation-key": "annotation-value",
},
},
TypeMeta: metav1.TypeMeta{
Kind: "Ingress",
APIVersion: networking.SchemeGroupVersion.String(),
},
Spec: networking.IngressSpec{
Rules: []networking.IngressRule{
{
Host: "test-host",
IngressRuleValue: networking.IngressRuleValue{
HTTP: &networking.HTTPIngressRuleValue{
Paths: []networking.HTTPIngressPath{
{
Backend: networking.IngressBackend{
Service: &networking.IngressServiceBackend{
Name: "che-host",
Port: networking.ServiceBackendPort{
Number: 8080,
},
},
},
Path: "/",
PathType: (*networking.PathType)(pointer.StringPtr(string(networking.PathTypeImplementationSpecific))),
},
},
},
},
},
},
},
},
},
{
name: "Test custom host",
ingressName: "test",
ingressComponent: DefaultCheFlavor(cheClusterWithGatewaySingleHostExposure),
ingressHost: "test-host",
ingressPath: "",
serviceName: "che-host",
servicePort: 8080,
ingressCustomSettings: orgv1.IngressCustomSettings{
Labels: "type=default",
Annotations: map[string]string{"annotation-key": "annotation-value"},
},
cheCluster: cheClusterWithGatewaySingleHostExposure,
expectedIngress: &networking.Ingress{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Namespace: "eclipse-che",
Labels: map[string]string{
"type": "default",
"app.kubernetes.io/component": DefaultCheFlavor(cheCluster),
"app.kubernetes.io/instance": DefaultCheFlavor(cheCluster),
"app.kubernetes.io/part-of": "che.eclipse.org",
"app.kubernetes.io/managed-by": DefaultCheFlavor(cheCluster) + "-operator",
"app.kubernetes.io/name": DefaultCheFlavor(cheCluster),
},
Annotations: map[string]string{
"che.eclipse.org/managed-annotations-digest": "0000",
"kubernetes.io/ingress.class": "nginx",
"nginx.ingress.kubernetes.io/proxy-connect-timeout": "3600",
"nginx.ingress.kubernetes.io/proxy-read-timeout": "3600",
"nginx.ingress.kubernetes.io/proxy-buffer-size": "16k",
"nginx.ingress.kubernetes.io/ssl-redirect": "false",
"nginx.org/websocket-services": "che-host",
"annotation-key": "annotation-value",
},
},
TypeMeta: metav1.TypeMeta{
Kind: "Ingress",
APIVersion: networking.SchemeGroupVersion.String(),
},
Spec: networking.IngressSpec{
Rules: []networking.IngressRule{
{
Host: "test-host",
IngressRuleValue: networking.IngressRuleValue{
HTTP: &networking.HTTPIngressRuleValue{
Paths: []networking.HTTPIngressPath{
{
Backend: networking.IngressBackend{
Service: &networking.IngressServiceBackend{
Name: "che-host",
Port: networking.ServiceBackendPort{
Number: 8080,
},
},
},
Path: "/",
PathType: (*networking.PathType)(pointer.StringPtr(string(networking.PathTypeImplementationSpecific))),
},
},
},
},
},
},
},
},
},
{
name: "Test custom host",
ingressName: "test",
ingressComponent: DefaultCheFlavor(cheClusterWithGatewaySingleHostExposure),
ingressHost: "test-host",
ingressPath: "",
serviceName: "che-host",
servicePort: 8080,
ingressCustomSettings: orgv1.IngressCustomSettings{
Labels: "type=default",
Annotations: map[string]string{"annotation-key": "annotation-value"},
},
expectedIngress: &networking.Ingress{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Expand All @@ -77,6 +223,7 @@ func TestIngressSpec(t *testing.T) {
"kubernetes.io/ingress.class": "nginx",
"nginx.ingress.kubernetes.io/proxy-connect-timeout": "3600",
"nginx.ingress.kubernetes.io/proxy-read-timeout": "3600",
"nginx.ingress.kubernetes.io/proxy-buffer-size": "16k",
"nginx.ingress.kubernetes.io/ssl-redirect": "false",
"nginx.org/websocket-services": "che-host",
"annotation-key": "annotation-value",
Expand Down Expand Up @@ -117,7 +264,7 @@ func TestIngressSpec(t *testing.T) {

for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
deployContext := GetTestDeployContext(cheCluster, []runtime.Object{})
deployContext := GetTestDeployContext(testCase.cheCluster, []runtime.Object{})

_, actualIngress := GetIngressSpec(deployContext,
testCase.ingressName,
Expand Down
3 changes: 2 additions & 1 deletion pkg/deploy/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func GetIngressSpec(
cheFlavor := DefaultCheFlavor(deployContext.CheCluster)
tlsSupport := deployContext.CheCluster.Spec.Server.TlsSupport
ingressStrategy := util.GetServerExposureStrategy(deployContext.CheCluster)
exposureType := GetSingleHostExposureType(deployContext.CheCluster)
ingressDomain := deployContext.CheCluster.Spec.K8s.IngressDomain
tlsSecretName := deployContext.CheCluster.Spec.K8s.TlsSecretName
ingressClass := util.GetValue(deployContext.CheCluster.Spec.K8s.IngressClass, DefaultIngressClass)
Expand Down Expand Up @@ -105,7 +106,7 @@ func GetIngressSpec(
annotations["nginx.ingress.kubernetes.io/rewrite-target"] = "/$1"
}
// Set bigger proxy buffer size to prevent 502 auth error.
if component == IdentityProviderName {
if component == IdentityProviderName || exposureType == GatewaySingleHostExposureType {
annotations["nginx.ingress.kubernetes.io/proxy-buffer-size"] = "16k"
}
for k, v := range ingressCustomSettings.Annotations {
Expand Down
1 change: 0 additions & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ github.com/operator-framework/operator-registry/pkg/api
github.com/operator-framework/operator-registry/pkg/image
github.com/operator-framework/operator-registry/pkg/registry
# github.com/pkg/errors v0.9.1 => github.com/pkg/errors v0.0.0-20200114194744-614d223910a1
## explicit
github.com/pkg/errors
# github.com/pmezard/go-difflib v1.0.0 => github.com/pmezard/go-difflib v1.0.0
github.com/pmezard/go-difflib/difflib
Expand Down

0 comments on commit 7f8b40d

Please sign in to comment.