From eda263119a04fdc5f358a56e548cc4aaac04521c Mon Sep 17 00:00:00 2001 From: Daniel Rodriguez Date: Mon, 24 Jun 2024 12:21:07 -0400 Subject: [PATCH] backport unit tests to alpha --- .../test/unit/console/deployment_test.go | 31 ++++++++++++++++++ .../test/unit/identity/deployment_test.go | 30 +++++++++++++++++ .../test/unit/operate/deployment_test.go | 30 +++++++++++++++++ .../test/unit/optimize/deployment_test.go | 30 +++++++++++++++++ .../test/unit/tasklist/deployment_test.go | 30 +++++++++++++++++ .../web-modeler/deployment_restapi_test.go | 32 +++++++++++++++++++ .../web-modeler/deployment_webapp_test.go | 32 +++++++++++++++++++ .../web-modeler/deployment_websockets_test.go | 32 +++++++++++++++++++ .../unit/zeebe-gateway/deployment_test.go | 30 +++++++++++++++++ .../test/unit/zeebe/statefulset_test.go | 30 +++++++++++++++++ 10 files changed, 307 insertions(+) diff --git a/charts/camunda-platform-alpha/test/unit/console/deployment_test.go b/charts/camunda-platform-alpha/test/unit/console/deployment_test.go index 3f2b3c7ad9..f6e50dfb0d 100644 --- a/charts/camunda-platform-alpha/test/unit/console/deployment_test.go +++ b/charts/camunda-platform-alpha/test/unit/console/deployment_test.go @@ -744,3 +744,34 @@ func (s *deploymentTemplateTest) TestInitContainers() { s.Require().Contains(podContainers, expectedContainer) } +func (s *deploymentTemplateTest) TestSetDnsPolicyAndDnsConfig() { + // given + options := &helm.Options{ + SetValues: map[string]string{ + "console.enabled": "true", + "console.dnsPolicy": "ClusterFirst", + "console.dnsConfig.nameservers[0]": "8.8.8.8", + "console.dnsConfig.searches[0]": "example.com", + }, + KubectlOptions: k8s.NewKubectlOptions("", "", s.namespace), + } + + // when + output := helm.RenderTemplate(s.T(), options, s.chartPath, s.release, s.templates) + var deployment appsv1.Deployment + helm.UnmarshalK8SYaml(s.T(), output, &deployment) + + // then + // Check if dnsPolicy is set + require.NotEmpty(s.T(), deployment.Spec.Template.Spec.DNSPolicy, "dnsPolicy should not be empty") + + // Check if dnsConfig is set + require.NotNil(s.T(), deployment.Spec.Template.Spec.DNSConfig, "dnsConfig should not be nil") + + expectedDNSConfig := &corev1.PodDNSConfig{ + Nameservers: []string{"8.8.8.8"}, + Searches: []string{"example.com"}, + } + + require.Equal(s.T(), expectedDNSConfig, deployment.Spec.Template.Spec.DNSConfig, "dnsConfig should match the expected configuration") +} diff --git a/charts/camunda-platform-alpha/test/unit/identity/deployment_test.go b/charts/camunda-platform-alpha/test/unit/identity/deployment_test.go index c4f8dbe3f8..5e224585d2 100644 --- a/charts/camunda-platform-alpha/test/unit/identity/deployment_test.go +++ b/charts/camunda-platform-alpha/test/unit/identity/deployment_test.go @@ -1081,3 +1081,33 @@ func (s *deploymentTemplateTest) TestContainerShouldSetExternalDatabaseExistingS }, }) } +func (s *deploymentTemplateTest) TestSetDnsPolicyAndDnsConfig() { + // given + options := &helm.Options{ + SetValues: map[string]string{ + "identity.dnsPolicy": "ClusterFirst", + "identity.dnsConfig.nameservers[0]": "8.8.8.8", + "identity.dnsConfig.searches[0]": "example.com", + }, + KubectlOptions: k8s.NewKubectlOptions("", "", s.namespace), + } + + // when + output := helm.RenderTemplate(s.T(), options, s.chartPath, s.release, s.templates) + var deployment appsv1.Deployment + helm.UnmarshalK8SYaml(s.T(), output, &deployment) + + // then + // Check if dnsPolicy is set + require.NotEmpty(s.T(), deployment.Spec.Template.Spec.DNSPolicy, "dnsPolicy should not be empty") + + // Check if dnsConfig is set + require.NotNil(s.T(), deployment.Spec.Template.Spec.DNSConfig, "dnsConfig should not be nil") + + expectedDNSConfig := &corev1.PodDNSConfig{ + Nameservers: []string{"8.8.8.8"}, + Searches: []string{"example.com"}, + } + + require.Equal(s.T(), expectedDNSConfig, deployment.Spec.Template.Spec.DNSConfig, "dnsConfig should match the expected configuration") +} diff --git a/charts/camunda-platform-alpha/test/unit/operate/deployment_test.go b/charts/camunda-platform-alpha/test/unit/operate/deployment_test.go index 33103b606a..6540752aa0 100644 --- a/charts/camunda-platform-alpha/test/unit/operate/deployment_test.go +++ b/charts/camunda-platform-alpha/test/unit/operate/deployment_test.go @@ -981,3 +981,33 @@ func (s *deploymentTemplateTest) TestOperateSetsElasticsearchPasswordIfProvidedB s.Require().Equal(camundaOperateElasticPassword.ValueFrom.SecretKeyRef.Name, "supersecret") s.Require().Equal(camundaOperateZeebeElasticPassword.ValueFrom.SecretKeyRef.Name, "supersecret") } +func (s *deploymentTemplateTest) TestSetDnsPolicyAndDnsConfig() { + // given + options := &helm.Options{ + SetValues: map[string]string{ + "operate.dnsPolicy": "ClusterFirst", + "operate.dnsConfig.nameservers[0]": "8.8.8.8", + "operate.dnsConfig.searches[0]": "example.com", + }, + KubectlOptions: k8s.NewKubectlOptions("", "", s.namespace), + } + + // when + output := helm.RenderTemplate(s.T(), options, s.chartPath, s.release, s.templates) + var deployment appsv1.Deployment + helm.UnmarshalK8SYaml(s.T(), output, &deployment) + + // then + // Check if dnsPolicy is set + require.NotEmpty(s.T(), deployment.Spec.Template.Spec.DNSPolicy, "dnsPolicy should not be empty") + + // Check if dnsConfig is set + require.NotNil(s.T(), deployment.Spec.Template.Spec.DNSConfig, "dnsConfig should not be nil") + + expectedDNSConfig := &corev1.PodDNSConfig{ + Nameservers: []string{"8.8.8.8"}, + Searches: []string{"example.com"}, + } + + require.Equal(s.T(), expectedDNSConfig, deployment.Spec.Template.Spec.DNSConfig, "dnsConfig should match the expected configuration") +} diff --git a/charts/camunda-platform-alpha/test/unit/optimize/deployment_test.go b/charts/camunda-platform-alpha/test/unit/optimize/deployment_test.go index c3aaf6fcfc..cf6bc71428 100644 --- a/charts/camunda-platform-alpha/test/unit/optimize/deployment_test.go +++ b/charts/camunda-platform-alpha/test/unit/optimize/deployment_test.go @@ -898,3 +898,33 @@ func (s *deploymentTemplateTest) TestOptimizeWithLog4j2Configuration() { s.Require().Equal("environment-config", volume.Name) s.Require().Equal("camunda-platform-test-optimize-configuration", volume.ConfigMap.Name) } +func (s *deploymentTemplateTest) TestSetDnsPolicyAndDnsConfig() { + // given + options := &helm.Options{ + SetValues: map[string]string{ + "optimize.dnsPolicy": "ClusterFirst", + "optimize.dnsConfig.nameservers[0]": "8.8.8.8", + "optimize.dnsConfig.searches[0]": "example.com", + }, + KubectlOptions: k8s.NewKubectlOptions("", "", s.namespace), + } + + // when + output := helm.RenderTemplate(s.T(), options, s.chartPath, s.release, s.templates) + var deployment appsv1.Deployment + helm.UnmarshalK8SYaml(s.T(), output, &deployment) + + // then + // Check if dnsPolicy is set + require.NotEmpty(s.T(), deployment.Spec.Template.Spec.DNSPolicy, "dnsPolicy should not be empty") + + // Check if dnsConfig is set + require.NotNil(s.T(), deployment.Spec.Template.Spec.DNSConfig, "dnsConfig should not be nil") + + expectedDNSConfig := &corev1.PodDNSConfig{ + Nameservers: []string{"8.8.8.8"}, + Searches: []string{"example.com"}, + } + + require.Equal(s.T(), expectedDNSConfig, deployment.Spec.Template.Spec.DNSConfig, "dnsConfig should match the expected configuration") +} diff --git a/charts/camunda-platform-alpha/test/unit/tasklist/deployment_test.go b/charts/camunda-platform-alpha/test/unit/tasklist/deployment_test.go index 3d2feee291..d9b510b4e1 100644 --- a/charts/camunda-platform-alpha/test/unit/tasklist/deployment_test.go +++ b/charts/camunda-platform-alpha/test/unit/tasklist/deployment_test.go @@ -919,3 +919,33 @@ func (s *deploymentTemplateTest) TestTasklistWithLog4j2Configuration() { s.Require().Equal("config", volume.Name) s.Require().Equal("camunda-platform-test-tasklist-configuration", volume.ConfigMap.Name) } +func (s *deploymentTemplateTest) TestSetDnsPolicyAndDnsConfig() { + // given + options := &helm.Options{ + SetValues: map[string]string{ + "tasklist.dnsPolicy": "ClusterFirst", + "tasklist.dnsConfig.nameservers[0]": "8.8.8.8", + "tasklist.dnsConfig.searches[0]": "example.com", + }, + KubectlOptions: k8s.NewKubectlOptions("", "", s.namespace), + } + + // when + output := helm.RenderTemplate(s.T(), options, s.chartPath, s.release, s.templates) + var deployment appsv1.Deployment + helm.UnmarshalK8SYaml(s.T(), output, &deployment) + + // then + // Check if dnsPolicy is set + require.NotEmpty(s.T(), deployment.Spec.Template.Spec.DNSPolicy, "dnsPolicy should not be empty") + + // Check if dnsConfig is set + require.NotNil(s.T(), deployment.Spec.Template.Spec.DNSConfig, "dnsConfig should not be nil") + + expectedDNSConfig := &corev1.PodDNSConfig{ + Nameservers: []string{"8.8.8.8"}, + Searches: []string{"example.com"}, + } + + require.Equal(s.T(), expectedDNSConfig, deployment.Spec.Template.Spec.DNSConfig, "dnsConfig should match the expected configuration") +} diff --git a/charts/camunda-platform-alpha/test/unit/web-modeler/deployment_restapi_test.go b/charts/camunda-platform-alpha/test/unit/web-modeler/deployment_restapi_test.go index 5a494a1119..4152fe54d0 100644 --- a/charts/camunda-platform-alpha/test/unit/web-modeler/deployment_restapi_test.go +++ b/charts/camunda-platform-alpha/test/unit/web-modeler/deployment_restapi_test.go @@ -509,3 +509,35 @@ func (s *restapiDeploymentTemplateTest) TestContainerSetInitContainer() { s.Require().Contains(podContainers, expectedContainer) } +func (s *restapiDeploymentTemplateTest) TestSetDnsPolicyAndDnsConfig() { + // given + options := &helm.Options{ + SetValues: map[string]string{ + "webModeler.enabled": "true", + "webModeler.restapi.mail.fromAddress": "example@example.com", + "webModeler.restapi.dnsPolicy": "ClusterFirst", + "webModeler.restapi.dnsConfig.nameservers[0]": "8.8.8.8", + "webModeler.restapi.dnsConfig.searches[0]": "example.com", + }, + KubectlOptions: k8s.NewKubectlOptions("", "", s.namespace), + } + + // when + output := helm.RenderTemplate(s.T(), options, s.chartPath, s.release, s.templates) + var deployment appsv1.Deployment + helm.UnmarshalK8SYaml(s.T(), output, &deployment) + + // then + // Check if dnsPolicy is set + require.NotEmpty(s.T(), deployment.Spec.Template.Spec.DNSPolicy, "dnsPolicy should not be empty") + + // Check if dnsConfig is set + require.NotNil(s.T(), deployment.Spec.Template.Spec.DNSConfig, "dnsConfig should not be nil") + + expectedDNSConfig := &corev1.PodDNSConfig{ + Nameservers: []string{"8.8.8.8"}, + Searches: []string{"example.com"}, + } + + require.Equal(s.T(), expectedDNSConfig, deployment.Spec.Template.Spec.DNSConfig, "dnsConfig should match the expected configuration") +} diff --git a/charts/camunda-platform-alpha/test/unit/web-modeler/deployment_webapp_test.go b/charts/camunda-platform-alpha/test/unit/web-modeler/deployment_webapp_test.go index 29e922c741..e7ef0b8dfc 100644 --- a/charts/camunda-platform-alpha/test/unit/web-modeler/deployment_webapp_test.go +++ b/charts/camunda-platform-alpha/test/unit/web-modeler/deployment_webapp_test.go @@ -220,3 +220,35 @@ func (s *webappDeploymentTemplateTest) TestContainerSetInitContainer() { s.Require().Contains(podContainers, expectedContainer) } +func (s *webappDeploymentTemplateTest) TestSetDnsPolicyAndDnsConfig() { + // given + options := &helm.Options{ + SetValues: map[string]string{ + "webModeler.enabled": "true", + "webModeler.restapi.mail.fromAddress": "example@example.com", + "webModeler.webapp.dnsPolicy": "ClusterFirst", + "webModeler.webapp.dnsConfig.nameservers[0]": "8.8.8.8", + "webModeler.webapp.dnsConfig.searches[0]": "example.com", + }, + KubectlOptions: k8s.NewKubectlOptions("", "", s.namespace), + } + + // when + output := helm.RenderTemplate(s.T(), options, s.chartPath, s.release, s.templates) + var deployment appsv1.Deployment + helm.UnmarshalK8SYaml(s.T(), output, &deployment) + + // then + // Check if dnsPolicy is set + require.NotEmpty(s.T(), deployment.Spec.Template.Spec.DNSPolicy, "dnsPolicy should not be empty") + + // Check if dnsConfig is set + require.NotNil(s.T(), deployment.Spec.Template.Spec.DNSConfig, "dnsConfig should not be nil") + + expectedDNSConfig := &corev1.PodDNSConfig{ + Nameservers: []string{"8.8.8.8"}, + Searches: []string{"example.com"}, + } + + require.Equal(s.T(), expectedDNSConfig, deployment.Spec.Template.Spec.DNSConfig, "dnsConfig should match the expected configuration") +} diff --git a/charts/camunda-platform-alpha/test/unit/web-modeler/deployment_websockets_test.go b/charts/camunda-platform-alpha/test/unit/web-modeler/deployment_websockets_test.go index cc7756b3fc..2882433b21 100644 --- a/charts/camunda-platform-alpha/test/unit/web-modeler/deployment_websockets_test.go +++ b/charts/camunda-platform-alpha/test/unit/web-modeler/deployment_websockets_test.go @@ -207,3 +207,35 @@ func (s *websocketsDeploymentTemplateTest) TestContainerSetInitContainer() { s.Require().Contains(podContainers, expectedContainer) } +func (s *websocketsDeploymentTemplateTest) TestSetDnsPolicyAndDnsConfig() { + // given + options := &helm.Options{ + SetValues: map[string]string{ + "webModeler.enabled": "true", + "webModeler.restapi.mail.fromAddress": "example@example.com", + "webModeler.websockets.dnsPolicy": "ClusterFirst", + "webModeler.websockets.dnsConfig.nameservers[0]": "8.8.8.8", + "webModeler.websockets.dnsConfig.searches[0]": "example.com", + }, + KubectlOptions: k8s.NewKubectlOptions("", "", s.namespace), + } + + // when + output := helm.RenderTemplate(s.T(), options, s.chartPath, s.release, s.templates) + var deployment appsv1.Deployment + helm.UnmarshalK8SYaml(s.T(), output, &deployment) + + // then + // Check if dnsPolicy is set + require.NotEmpty(s.T(), deployment.Spec.Template.Spec.DNSPolicy, "dnsPolicy should not be empty") + + // Check if dnsConfig is set + require.NotNil(s.T(), deployment.Spec.Template.Spec.DNSConfig, "dnsConfig should not be nil") + + expectedDNSConfig := &corev1.PodDNSConfig{ + Nameservers: []string{"8.8.8.8"}, + Searches: []string{"example.com"}, + } + + require.Equal(s.T(), expectedDNSConfig, deployment.Spec.Template.Spec.DNSConfig, "dnsConfig should match the expected configuration") +} diff --git a/charts/camunda-platform-alpha/test/unit/zeebe-gateway/deployment_test.go b/charts/camunda-platform-alpha/test/unit/zeebe-gateway/deployment_test.go index 89067415de..983baf81f8 100644 --- a/charts/camunda-platform-alpha/test/unit/zeebe-gateway/deployment_test.go +++ b/charts/camunda-platform-alpha/test/unit/zeebe-gateway/deployment_test.go @@ -796,3 +796,33 @@ func (s *deploymentTemplateTest) TestContainerSetSidecar() { s.Require().Contains(podContainers, expectedContainer) } +func (s *deploymentTemplateTest) TestSetDnsPolicyAndDnsConfig() { + // given + options := &helm.Options{ + SetValues: map[string]string{ + "zeebeGateway.dnsPolicy": "ClusterFirst", + "zeebeGateway.dnsConfig.nameservers[0]": "8.8.8.8", + "zeebeGateway.dnsConfig.searches[0]": "example.com", + }, + KubectlOptions: k8s.NewKubectlOptions("", "", s.namespace), + } + + // when + output := helm.RenderTemplate(s.T(), options, s.chartPath, s.release, s.templates) + var deployment appsv1.Deployment + helm.UnmarshalK8SYaml(s.T(), output, &deployment) + + // then + // Check if dnsPolicy is set + require.NotEmpty(s.T(), deployment.Spec.Template.Spec.DNSPolicy, "dnsPolicy should not be empty") + + // Check if dnsConfig is set + require.NotNil(s.T(), deployment.Spec.Template.Spec.DNSConfig, "dnsConfig should not be nil") + + expectedDNSConfig := &corev1.PodDNSConfig{ + Nameservers: []string{"8.8.8.8"}, + Searches: []string{"example.com"}, + } + + require.Equal(s.T(), expectedDNSConfig, deployment.Spec.Template.Spec.DNSConfig, "dnsConfig should match the expected configuration") +} diff --git a/charts/camunda-platform-alpha/test/unit/zeebe/statefulset_test.go b/charts/camunda-platform-alpha/test/unit/zeebe/statefulset_test.go index 6f9ddfeb19..d3f6ea4eef 100644 --- a/charts/camunda-platform-alpha/test/unit/zeebe/statefulset_test.go +++ b/charts/camunda-platform-alpha/test/unit/zeebe/statefulset_test.go @@ -913,3 +913,33 @@ func (s *statefulSetTest) TestContainerSetSidecar() { s.Require().Contains(podContainers, expectedContainer) } +func (s *statefulSetTest) TestSetDnsPolicyAndDnsConfig() { + // given + options := &helm.Options{ + SetValues: map[string]string{ + "zeebe.dnsPolicy": "ClusterFirst", + "zeebe.dnsConfig.nameservers[0]": "8.8.8.8", + "zeebe.dnsConfig.searches[0]": "example.com", + }, + KubectlOptions: k8s.NewKubectlOptions("", "", s.namespace), + } + + // when + output := helm.RenderTemplate(s.T(), options, s.chartPath, s.release, s.templates) + var statefulSet appsv1.StatefulSet + helm.UnmarshalK8SYaml(s.T(), output, &statefulSet) + + // then + // Check if dnsPolicy is set + require.NotEmpty(s.T(), statefulSet.Spec.Template.Spec.DNSPolicy, "dnsPolicy should not be empty") + + // Check if dnsConfig is set + require.NotNil(s.T(), statefulSet.Spec.Template.Spec.DNSConfig, "dnsConfig should not be nil") + + expectedDNSConfig := &corev1.PodDNSConfig{ + Nameservers: []string{"8.8.8.8"}, + Searches: []string{"example.com"}, + } + + require.Equal(s.T(), expectedDNSConfig, statefulSet.Spec.Template.Spec.DNSConfig, "dnsConfig should match the expected configuration") +}