From cea92d092ac330493147536e27f3edeb465ffe75 Mon Sep 17 00:00:00 2001 From: Bastian Hofmann Date: Thu, 5 Oct 2023 16:36:52 +0200 Subject: [PATCH] Make ingressClassName configurable (#86) * Make ingressClassName configurable Fixes https://github.com/qdrant/qdrant-helm/issues/84 * Fix CI * Fix CI * Fix CI --- Makefile | 4 ++ charts/qdrant/templates/ingress.yaml | 3 ++ charts/qdrant/values.yaml | 1 + test/qdrant_annotations_test.go | 28 +++++++++++ test/qdrant_ingress_test.go | 71 ++++++++++++++++++++++++++++ 5 files changed, 107 insertions(+) create mode 100644 test/qdrant_ingress_test.go diff --git a/Makefile b/Makefile index cc9a582..2e9dd68 100644 --- a/Makefile +++ b/Makefile @@ -6,3 +6,7 @@ test-unit: test-integration: bats test/integration --verbose-run --show-output-of-passing-tests + +test-unit-lint: + gofmt -w -s ./test + golangci-lint run ./test \ No newline at end of file diff --git a/charts/qdrant/templates/ingress.yaml b/charts/qdrant/templates/ingress.yaml index 21ec14c..47d769c 100644 --- a/charts/qdrant/templates/ingress.yaml +++ b/charts/qdrant/templates/ingress.yaml @@ -13,6 +13,9 @@ metadata: {{- toYaml . | nindent 4 }} {{- end }} spec: + {{- if .Values.ingress.ingressClassName }} + ingressClassName: {{ .Values.ingress.ingressClassName }} + {{- end }} {{- with .Values.ingress.hosts }} rules: {{- range . }} diff --git a/charts/qdrant/values.yaml b/charts/qdrant/values.yaml index 5f51114..356e288 100644 --- a/charts/qdrant/values.yaml +++ b/charts/qdrant/values.yaml @@ -39,6 +39,7 @@ service: ingress: enabled: false + ingressClassName: "" additionalLabels: {} annotations: {} # kubernetes.io/ingress.class: alb diff --git a/test/qdrant_annotations_test.go b/test/qdrant_annotations_test.go index 28baff2..1557db5 100644 --- a/test/qdrant_annotations_test.go +++ b/test/qdrant_annotations_test.go @@ -11,6 +11,7 @@ import ( "github.com/gruntwork-io/terratest/modules/random" "github.com/stretchr/testify/require" appsv1 "k8s.io/api/apps/v1" + networkingv1 "k8s.io/api/networking/v1" ) func TestPvcAnnotations(t *testing.T) { @@ -38,3 +39,30 @@ func TestPvcAnnotations(t *testing.T) { require.Contains(t, statefulSet.Spec.VolumeClaimTemplates[0].ObjectMeta.Annotations, "test") require.Equal(t, statefulSet.Spec.VolumeClaimTemplates[0].ObjectMeta.Annotations["test"], "value") } + +func TestIngressAnnotations(t *testing.T) { + t.Parallel() + + helmChartPath, err := filepath.Abs("../charts/qdrant") + releaseName := "qdrant" + require.NoError(t, err) + + namespaceName := "qdrant-" + strings.ToLower(random.UniqueId()) + logger.Log(t, "Namespace: %s\n", namespaceName) + + options := &helm.Options{ + SetJsonValues: map[string]string{ + "ingress.enabled": `true`, + "ingress.annotations": `{"test": "value"}`, + }, + KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName), + } + + output := helm.RenderTemplate(t, options, helmChartPath, releaseName, []string{"templates/ingress.yaml"}) + + var ingress networkingv1.Ingress + helm.UnmarshalK8SYaml(t, output, &ingress) + + require.Contains(t, ingress.ObjectMeta.Annotations, "test") + require.Equal(t, ingress.ObjectMeta.Annotations["test"], "value") +} diff --git a/test/qdrant_ingress_test.go b/test/qdrant_ingress_test.go new file mode 100644 index 0000000..bcfca5a --- /dev/null +++ b/test/qdrant_ingress_test.go @@ -0,0 +1,71 @@ +package test + +import ( + "github.com/gruntwork-io/terratest/modules/helm" + "github.com/gruntwork-io/terratest/modules/k8s" + "github.com/gruntwork-io/terratest/modules/logger" + "github.com/gruntwork-io/terratest/modules/random" + "github.com/stretchr/testify/require" + networkingv1 "k8s.io/api/networking/v1" + "path/filepath" + "strings" + "testing" +) + +func TestIngressWithIngressClassName(t *testing.T) { + t.Parallel() + + helmChartPath, err := filepath.Abs("../charts/qdrant") + releaseName := "qdrant" + require.NoError(t, err) + + namespaceName := "qdrant-" + strings.ToLower(random.UniqueId()) + logger.Log(t, "Namespace: %s\n", namespaceName) + + options := &helm.Options{ + SetJsonValues: map[string]string{ + "ingress.enabled": `true`, + "ingress.ingressClassName": `"nginx"`, + }, + KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName), + } + + output := helm.RenderTemplate(t, options, helmChartPath, releaseName, []string{"templates/ingress.yaml"}) + + var ingress networkingv1.Ingress + helm.UnmarshalK8SYaml(t, output, &ingress) + + require.Equal(t, "nginx", *ingress.Spec.IngressClassName) +} + +func TestIngressWithTls(t *testing.T) { + t.Parallel() + + helmChartPath, err := filepath.Abs("../charts/qdrant") + releaseName := "qdrant" + require.NoError(t, err) + + namespaceName := "qdrant-" + strings.ToLower(random.UniqueId()) + logger.Log(t, "Namespace: %s\n", namespaceName) + + options := &helm.Options{ + SetJsonValues: map[string]string{ + "ingress.enabled": `true`, + "ingress.hosts": `[{"host":"test.qdrant.local","paths":[{"path":"/","pathType":"Prefix","servicePort": 6333}]}]`, + "ingress.tls": `[{"hosts":["test.qdrant.local"],"secretName":"test-secret"}]`, + }, + KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName), + } + + output := helm.RenderTemplate(t, options, helmChartPath, releaseName, []string{"templates/ingress.yaml"}) + + var ingress networkingv1.Ingress + helm.UnmarshalK8SYaml(t, output, &ingress) + + require.Equal(t, "test.qdrant.local", ingress.Spec.Rules[0].Host) + require.Equal(t, "/", ingress.Spec.Rules[0].HTTP.Paths[0].Path) + require.Equal(t, networkingv1.PathType("Prefix"), *ingress.Spec.Rules[0].HTTP.Paths[0].PathType) + require.Equal(t, int32(6333), ingress.Spec.Rules[0].HTTP.Paths[0].Backend.Service.Port.Number) + require.Equal(t, "test.qdrant.local", ingress.Spec.TLS[0].Hosts[0]) + require.Equal(t, "test-secret", ingress.Spec.TLS[0].SecretName) +}