Skip to content

Commit 3b6ebe7

Browse files
authored
Merge pull request #41 from gruntwork-io/yori-sidecar
Fix sidecar and additionalpaths rendering
2 parents ed598b2 + 5843413 commit 3b6ebe7

File tree

3 files changed

+81
-4
lines changed

3 files changed

+81
-4
lines changed

charts/k8s-service/templates/deployment.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ spec:
148148
{{- end }}
149149
{{- if .Values.securityContext }}
150150
securityContext:
151-
{{ toYaml .Values.securityContext | indent 12 }}
151+
{{ toYaml .Values.securityContext | indent 12 }}
152152
{{- end}}
153153
resources:
154154
{{ toYaml .Values.containerResources | indent 12 }}
@@ -227,7 +227,7 @@ spec:
227227

228228
{{- range $key, $value := .Values.sideCarContainers }}
229229
- name: {{ $key }}
230-
{{ toYaml $value | indent 12 }}
230+
{{ toYaml $value | indent 10 }}
231231
{{- end }}
232232

233233
{{- /* START IMAGE PULL SECRETS LOGIC */ -}}

charts/k8s-service/templates/ingress.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ spec:
4646
{{- range $additionalPathsHigherPriority }}
4747
- path: {{ .path }}
4848
backend:
49-
serviceName: {{ .serviceName }}
49+
serviceName: {{ if .serviceName }}{{ .serviceName }}{{ else }}{{ $fullName }}{{ end }}
5050
servicePort: {{ .servicePort }}
5151
{{- end }}
5252
- path: {{ $ingressPath }}
@@ -56,7 +56,7 @@ spec:
5656
{{- range $additionalPaths }}
5757
- path: {{ .path }}
5858
backend:
59-
serviceName: {{ .serviceName }}
59+
serviceName: {{ if .serviceName }}{{ .serviceName }}{{ else }}{{ $fullName }}{{ end }}
6060
servicePort: {{ .servicePort }}
6161
{{- end }}
6262
{{- end }}

test/k8s_service_template_test.go

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,69 @@ func TestK8SServiceIngressAdditionalPathsHigherPriorityNoServiceName(t *testing.
454454
assert.Equal(t, secondPath.Backend.ServicePort.StrVal, "app")
455455
}
456456

457+
// Test that omitting a serviceName on additionalPaths reuses the application service name even when hosts is set
458+
func TestK8SServiceIngressWithHostsAdditionalPathsNoServiceName(t *testing.T) {
459+
t.Parallel()
460+
461+
ingress := renderK8SServiceIngressWithSetValues(
462+
t,
463+
map[string]string{
464+
"ingress.enabled": "true",
465+
"ingress.path": "/app",
466+
"ingress.servicePort": "app",
467+
"ingress.hosts[0]": "chart-example.local",
468+
"ingress.additionalPaths[0].path": "/black-hole",
469+
"ingress.additionalPaths[0].servicePort": "3000",
470+
},
471+
)
472+
pathRules := ingress.Spec.Rules[0].HTTP.Paths
473+
assert.Equal(t, len(pathRules), 2)
474+
475+
// The first path should be the main service path
476+
firstPath := pathRules[0]
477+
assert.Equal(t, firstPath.Path, "/app")
478+
assert.Equal(t, strings.ToLower(firstPath.Backend.ServiceName), "release-name-linter")
479+
assert.Equal(t, firstPath.Backend.ServicePort.StrVal, "app")
480+
481+
// The second path should be the black hole
482+
secondPath := pathRules[1]
483+
assert.Equal(t, secondPath.Path, "/black-hole")
484+
assert.Equal(t, strings.ToLower(secondPath.Backend.ServiceName), "release-name-linter")
485+
assert.Equal(t, secondPath.Backend.ServicePort.IntVal, int32(3000))
486+
}
487+
488+
// Test that omitting a serviceName on additionalPathsHigherPriority reuses the application service name even when hosts
489+
// is set
490+
func TestK8SServiceIngressWithHostsAdditionalPathsHigherPriorityNoServiceName(t *testing.T) {
491+
t.Parallel()
492+
493+
ingress := renderK8SServiceIngressWithSetValues(
494+
t,
495+
map[string]string{
496+
"ingress.enabled": "true",
497+
"ingress.path": "/app",
498+
"ingress.servicePort": "app",
499+
"ingress.hosts[0]": "chart-example.local",
500+
"ingress.additionalPathsHigherPriority[0].path": "/black-hole",
501+
"ingress.additionalPathsHigherPriority[0].servicePort": "3000",
502+
},
503+
)
504+
pathRules := ingress.Spec.Rules[0].HTTP.Paths
505+
assert.Equal(t, len(pathRules), 2)
506+
507+
// The first path should be the black hole
508+
firstPath := pathRules[0]
509+
assert.Equal(t, firstPath.Path, "/black-hole")
510+
assert.Equal(t, strings.ToLower(firstPath.Backend.ServiceName), "release-name-linter")
511+
assert.Equal(t, firstPath.Backend.ServicePort.IntVal, int32(3000))
512+
513+
// The second path should be the main service path
514+
secondPath := pathRules[1]
515+
assert.Equal(t, secondPath.Path, "/app")
516+
assert.Equal(t, strings.ToLower(secondPath.Backend.ServiceName), "release-name-linter")
517+
assert.Equal(t, secondPath.Backend.ServicePort.StrVal, "app")
518+
}
519+
457520
// Test rendering Managed Certificate
458521
func TestK8SServiceManagedCertDomainNameAndName(t *testing.T) {
459522
t.Parallel()
@@ -612,3 +675,17 @@ func TestK8SServiceIngressMultiCert(t *testing.T) {
612675
assert.Equal(t, secondTlsHosts[0], "chart1-example-tls-host")
613676
assert.Equal(t, secondTlsHosts[1], "chart1-example-tls-host2")
614677
}
678+
679+
func TestK8SServiceSideCarContainersRendersCorrectly(t *testing.T) {
680+
t.Parallel()
681+
deployment := renderK8SServiceDeploymentWithSetValues(
682+
t,
683+
map[string]string{
684+
"sideCarContainers.datadog.image": "datadog/agent:latest",
685+
},
686+
)
687+
renderedContainers := deployment.Spec.Template.Spec.Containers
688+
require.Equal(t, len(renderedContainers), 2)
689+
sideCarContainer := renderedContainers[1]
690+
assert.Equal(t, sideCarContainer.Image, "datadog/agent:latest")
691+
}

0 commit comments

Comments
 (0)