Skip to content

Commit 613f67e

Browse files
authored
fix: port naming/app protocol tls.enabled (#90)
- Add template for platform port name and use in deployment & service. - Update appProtocol template to use https when tls.enabled Fixes Istio TLS Passthrough scenario where appProtocol override does not appear to work; so uses port naming instead : https://istio.io/latest/docs/ops/configuration/traffic-management/protocol-selection/
1 parent 6829c87 commit 613f67e

File tree

4 files changed

+43
-14
lines changed

4 files changed

+43
-14
lines changed

charts/platform/templates/_helpers.tpl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,17 @@ This takes an array of three values:
132132
{{- end -}}
133133
{{- end -}}
134134

135-
{{- define "determine.appProtocol" -}}
135+
{{- define "platform.portName" -}}
136136
{{- if .Values.server.tls.enabled -}}
137+
https
138+
{{- else -}}
137139
http2
140+
{{- end -}}
141+
{{- end -}}
142+
143+
{{- define "determine.appProtocol" -}}
144+
{{- if .Values.server.tls.enabled -}}
145+
https
138146
{{- else -}}
139147
{{- if (include "isOpenshift" .) -}}
140148
h2c

charts/platform/templates/deployment.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,20 @@ spec:
4747
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
4848
imagePullPolicy: {{ .Values.image.pullPolicy }}
4949
ports:
50-
- name: http2
50+
- name: {{ include "platform.portName" . }}
5151
containerPort: {{ .Values.server.port }}
5252
protocol: TCP
5353
{{ if not .Values.server.disableHealthChecks }}
5454
livenessProbe:
5555
httpGet:
5656
scheme: {{ if .Values.server.tls.enabled }}HTTPS{{ else }}HTTP{{ end }}
5757
path: /healthz
58-
port: http2
58+
port: {{ include "platform.portName" . }}
5959
readinessProbe:
6060
httpGet:
6161
scheme: {{ if .Values.server.tls.enabled }}HTTPS{{ else }}HTTP{{ end }}
6262
path: /healthz?service=all
63-
port: http2
63+
port: {{ include "platform.portName" . }}
6464
{{ end }}
6565
resources:
6666
{{- toYaml .Values.resources | nindent 12 }}

charts/platform/templates/service.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ spec:
1010
type: {{ .Values.service.type }}
1111
ports:
1212
- port: {{ .Values.service.port }}
13-
targetPort: http2
13+
targetPort: {{ include "platform.portName" . }}
1414
appProtocol: {{ include "determine.appProtocol" . }}
1515
protocol: TCP
16-
name: http2
16+
name: {{ include "platform.portName" . }}
1717
selector:
1818
{{- include "chart.selectorLabels" . | nindent 4 }}

tests/chart_platform_template_test.go

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
package test
22

33
import (
4-
"path/filepath"
5-
"strings"
6-
"testing"
7-
84
"github.com/gruntwork-io/terratest/modules/helm"
95
"github.com/gruntwork-io/terratest/modules/k8s"
106
"github.com/gruntwork-io/terratest/modules/random"
117
"github.com/stretchr/testify/suite"
12-
"gopkg.in/yaml.v3"
8+
yaml3 "gopkg.in/yaml.v3"
139
appv1 "k8s.io/api/apps/v1"
1410
corev1 "k8s.io/api/core/v1"
11+
"path/filepath"
12+
"strings"
13+
"testing"
1514
)
1615

1716
type PlatformChartTemplateSuite struct {
@@ -513,7 +512,7 @@ func (s *PlatformChartTemplateSuite) Test_Custom_Config_Template_Services_Merged
513512
helm.UnmarshalK8SYaml(s.T(), output, &cm)
514513

515514
var config map[string]interface{}
516-
s.Require().NoError(yaml.Unmarshal([]byte(cm.Data["opentdf.yaml"]), &config))
515+
s.Require().NoError(yaml3.Unmarshal([]byte(cm.Data["opentdf.yaml"]), &config))
517516

518517
s.Require().Equal(releaseName+"-platform", cm.Name)
519518

@@ -530,7 +529,7 @@ func (s *PlatformChartTemplateSuite) Test_Custom_Config_Template_Services_Merged
530529
s.Require().True(testServiceKeyFound)
531530
}
532531

533-
func (s *PlatformChartTemplateSuite) Test_TLS_Enabled_Expect_HTTP2_AppProtocol() {
532+
func (s *PlatformChartTemplateSuite) Test_TLS_Enabled_Expect_HTTPS_AppProtocol() {
534533
releaseName := "basic"
535534

536535
namespaceName := "opentdf-" + strings.ToLower(random.UniqueId())
@@ -547,7 +546,18 @@ func (s *PlatformChartTemplateSuite) Test_TLS_Enabled_Expect_HTTP2_AppProtocol()
547546
helm.UnmarshalK8SYaml(s.T(), output, &svc)
548547

549548
for _, port := range svc.Spec.Ports {
550-
s.Require().Equal("http2", *port.AppProtocol)
549+
s.Require().Equal("https", *port.AppProtocol)
550+
}
551+
552+
output = helm.RenderTemplate(s.T(), options, s.chartPath, releaseName, []string{"templates/deployment.yaml"})
553+
var deployment appv1.Deployment
554+
helm.UnmarshalK8SYaml(s.T(), output, &deployment)
555+
for _, container := range deployment.Spec.Template.Spec.Containers {
556+
for _, port := range container.Ports {
557+
s.Require().Equal("https", port.Name)
558+
}
559+
s.Require().Equal("https", container.ReadinessProbe.HTTPGet.Port.String())
560+
s.Require().Equal("https", container.LivenessProbe.HTTPGet.Port.String())
551561
}
552562
}
553563

@@ -567,6 +577,17 @@ func (s *PlatformChartTemplateSuite) Test_TLS_Disabled_Generic_K8S_Expect_K8S_H2
567577
for _, port := range svc.Spec.Ports {
568578
s.Require().Equal("kubernetes.io/h2c", *port.AppProtocol)
569579
}
580+
581+
output = helm.RenderTemplate(s.T(), options, s.chartPath, releaseName, []string{"templates/deployment.yaml"})
582+
var deployment appv1.Deployment
583+
helm.UnmarshalK8SYaml(s.T(), output, &deployment)
584+
for _, container := range deployment.Spec.Template.Spec.Containers {
585+
for _, port := range container.Ports {
586+
s.Require().Equal("http2", port.Name)
587+
}
588+
s.Require().Equal("http2", container.ReadinessProbe.HTTPGet.Port.String())
589+
s.Require().Equal("http2", container.LivenessProbe.HTTPGet.Port.String())
590+
}
570591
}
571592

572593
func (s *PlatformChartTemplateSuite) Test_TLS_Disabled_Openshift_Expect_H2C_AppProtocol() {

0 commit comments

Comments
 (0)