Skip to content

Commit

Permalink
feat: support dnsPolicy and dnsConfig for all components (#2009)
Browse files Browse the repository at this point in the history
* add dnsPolicy and dnsConfig to deployments and statefulsets

* add dnsPolicy and dnsConfig in values for each component

* add fix webmodeler name for params

* update README

* fixed empty space inside brackets

* fixed dnsPolicy with empty string and dnsConfig with empty object

* add unit test for console,connectors,identity,operate,optimze,tasklist

* add unit test for zeebe and webmodeler

* port to alpha

* update README

* fix unit test for console

* add missing unit test for zeebe-gateway deployment in latest

* backport unit tests to alpha
  • Loading branch information
drodriguez-305 authored Jun 24, 2024
1 parent be4abe7 commit 31b7c4f
Show file tree
Hide file tree
Showing 46 changed files with 886 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ spec:
{{- .Values.connectors.extraVolumes | toYaml | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "connectors.serviceAccountName" . }}
{{- if .Values.connectors.dnsConfig }}
dnsConfig: {{- toYaml .Values.connectors.dnsConfig | nindent 8 }}
{{- end }}
{{- if .Values.connectors.dnsPolicy }}
dnsPolicy: {{ .Values.connectors.dnsPolicy | quote }}
{{- end }}
{{- if .Values.connectors.podSecurityContext }}
securityContext: {{- toYaml .Values.connectors.podSecurityContext | nindent 8 }}
{{- end }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ spec:
initContainers:
{{- tpl (.Values.console.initContainers | default list | toYaml | nindent 8) $ }}
serviceAccountName: {{ include "console.serviceAccountName" . }}
{{- if .Values.console.dnsConfig }}
dnsConfig: {{- toYaml .Values.console.dnsConfig | nindent 8 }}
{{- end }}
{{- if .Values.console.dnsPolicy }}
dnsPolicy: {{ .Values.console.dnsPolicy | quote }}
{{- end }}
securityContext:
{{- toYaml .Values.console.podSecurityContext | nindent 8 }}
containers:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,12 @@ spec:
{{- .Values.identity.extraVolumes | toYaml | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "identity.serviceAccountName" . }}
{{- if .Values.identity.dnsConfig }}
dnsConfig: {{- toYaml .Values.identity.dnsConfig | nindent 8 }}
{{- end }}
{{- if .Values.identity.dnsPolicy }}
dnsPolicy: {{ .Values.identity.dnsPolicy | quote }}
{{- end }}
{{- if .Values.identity.podSecurityContext }}
securityContext: {{- toYaml .Values.identity.podSecurityContext | nindent 8 }}
{{- end }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,12 @@ spec:
{{- .Values.operate.extraVolumes | toYaml | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "operate.serviceAccountName" . }}
{{- if .Values.operate.dnsConfig }}
dnsConfig: {{- toYaml .Values.operate.dnsConfig | nindent 8 }}
{{- end }}
{{- if .Values.operate.dnsPolicy }}
dnsPolicy: {{ .Values.operate.dnsPolicy | quote }}
{{- end }}
{{- if .Values.operate.podSecurityContext }}
securityContext: {{- toYaml .Values.operate.podSecurityContext | nindent 8 }}
{{- end }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,12 @@ spec:
{{- .Values.optimize.extraVolumes | toYaml | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "optimize.serviceAccountName" . }}
{{- if .Values.optimize.dnsConfig }}
dnsConfig: {{- toYaml .Values.optimize.dnsConfig | nindent 8 }}
{{- end }}
{{- if .Values.optimize.dnsPolicy }}
dnsPolicy: {{ .Values.optimize.dnsPolicy | quote }}
{{- end }}
{{- if .Values.optimize.podSecurityContext }}
securityContext: {{- toYaml .Values.optimize.podSecurityContext | nindent 8 }}
{{- end }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,12 @@ spec:
{{- .Values.tasklist.extraVolumes | toYaml | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "tasklist.serviceAccountName" . }}
{{- if .Values.tasklist.dnsConfig }}
dnsConfig: {{- toYaml .Values.tasklist.dnsConfig | nindent 8 }}
{{- end }}
{{- if .Values.tasklist.dnsPolicy }}
dnsPolicy: {{ .Values.tasklist.dnsPolicy | quote }}
{{- end }}
{{- if .Values.tasklist.podSecurityContext }}
securityContext: {{- toYaml .Values.tasklist.podSecurityContext | nindent 8 }}
{{- end }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ spec:
{{- .Values.webModeler.restapi.extraVolumes | toYaml | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "webModeler.serviceAccountName" . }}
{{- if .Values.webModeler.restapi.dnsConfig }}
dnsConfig: {{- toYaml .Values.webModeler.restapi.dnsConfig | nindent 8 }}
{{- end }}
{{- if .Values.webModeler.restapi.dnsPolicy }}
dnsPolicy: {{ .Values.webModeler.restapi.dnsPolicy | quote }}
{{- end }}
{{- if .Values.webModeler.restapi.podSecurityContext }}
securityContext: {{- toYaml .Values.webModeler.restapi.podSecurityContext | nindent 8 }}
{{- end }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ spec:
{{- .Values.webModeler.webapp.extraVolumes | toYaml | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "webModeler.serviceAccountName" . }}
{{- if .Values.webModeler.webapp.dnsConfig }}
dnsConfig: {{- toYaml .Values.webModeler.webapp.dnsConfig | nindent 8 }}
{{- end }}
{{- if .Values.webModeler.webapp.dnsPolicy }}
dnsPolicy: {{ .Values.webModeler.webapp.dnsPolicy | quote }}
{{- end }}
{{- if .Values.webModeler.webapp.podSecurityContext }}
securityContext: {{- toYaml .Values.webModeler.webapp.podSecurityContext | nindent 8 }}
{{- end }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ spec:
{{- .Values.webModeler.websockets.extraVolumes | toYaml | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "webModeler.serviceAccountName" . }}
{{- if .Values.webModeler.websockets.dnsConfig }}
dnsConfig: {{- toYaml .Values.webModeler.websockets.dnsConfig | nindent 8 }}
{{- end }}
{{- if .Values.webModeler.websockets.dnsPolicy }}
dnsPolicy: {{ .Values.webModeler.websockets.dnsPolicy | quote }}
{{- end }}
{{- if .Values.webModeler.websockets.podSecurityContext }}
securityContext: {{- toYaml .Values.webModeler.websockets.podSecurityContext | nindent 8 }}
{{- end }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ spec:
{{- .Values.zeebeGateway.extraVolumes | toYaml | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "zeebe.serviceAccountName.gateway" . }}
{{- if .Values.zeebeGateway.dnsConfig }}
dnsConfig: {{- toYaml .Values.zeebeGateway.dnsConfig | nindent 8 }}
{{- end }}
{{- if .Values.zeebeGateway.dnsPolicy }}
dnsPolicy: {{ .Values.zeebeGateway.dnsPolicy | quote }}
{{- end }}
{{- if .Values.zeebeGateway.podSecurityContext }}
securityContext: {{- toYaml .Values.zeebeGateway.podSecurityContext | nindent 8 }}
{{- end }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,12 @@ spec:
{{ .Values.zeebe.extraVolumes | toYaml | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "zeebe.serviceAccountName.broker" . }}
{{- if .Values.zeebe.dnsConfig }}
dnsConfig: {{- toYaml .Values.zeebe.dnsConfig | nindent 8 }}
{{- end }}
{{- if .Values.zeebe.dnsPolicy }}
dnsPolicy: {{ .Values.zeebe.dnsPolicy | quote }}
{{- end }}
{{- if .Values.zeebe.podSecurityContext }}
securityContext: {{- toYaml .Values.zeebe.podSecurityContext | nindent 8 }}
{{- end }}
Expand Down
31 changes: 31 additions & 0 deletions charts/camunda-platform-alpha/test/unit/console/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
30 changes: 30 additions & 0 deletions charts/camunda-platform-alpha/test/unit/operate/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Original file line number Diff line number Diff line change
Expand Up @@ -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": "[email protected]",
"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")
}
Original file line number Diff line number Diff line change
Expand Up @@ -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": "[email protected]",
"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")
}
Loading

0 comments on commit 31b7c4f

Please sign in to comment.