Skip to content

Commit

Permalink
Set default port reference name
Browse files Browse the repository at this point in the history
  • Loading branch information
dzsak committed Feb 5, 2024
1 parent 3d0cbe7 commit 51208eb
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion charts/common/templates/_container.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ ports:
protocol: TCP
{{- else }}
{{- range .Values.ports }}
- name: {{ .name }}
- name: {{ if .name }}{{ .name }}{{ else if .containerPort }}{{ printf "tcp-%g" .containerPort}}{{ end }}
containerPort: {{ .containerPort }}
protocol: TCP
{{- end }}
Expand Down
4 changes: 2 additions & 2 deletions charts/onechart/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ spec:
{{- end }}
{{- else }}
{{- range .Values.ports }}
- name: {{ .name }}
- name: {{ if .name }}{{ .name }}{{ else if .svcPort }}{{ printf "tcp-%g" .svcPort }}{{ end }}
port: {{ if .svcPort }}{{ .svcPort }}{{ else }}{{ .containerPort }}{{ end }}
{{- if .nodePort }}
nodePort: {{ .nodePort }}
{{- end }}
targetPort: {{ .name }}
targetPort: {{ if .name }}{{ .name }}{{ else if .containerPort }}{{ printf "tcp-%g" .containerPort}}{{ end }}
protocol: TCP
{{- end }}
{{- end }}
Expand Down
13 changes: 13 additions & 0 deletions charts/onechart/tests/deployment_ports_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ tests:
- name: passive-2
containerPort: 3002
protocol: TCP
- it: Should set port definition if name is not set
set:
ports:
- containerPort: 21
asserts:
- template: deployment.yaml
documentIndex: 0
equal:
path: spec.template.spec.containers[0].ports
value:
- name: tcp-21
containerPort: 21
protocol: TCP
- it: Should set default port
asserts:
- template: deployment.yaml
Expand Down
13 changes: 13 additions & 0 deletions charts/onechart/tests/service_ports_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ tests:
port: 3002
targetPort: passive-2
protocol: TCP
- it: Should set port definition if name is not set
set:
ports:
- svcPort: 445
containerPort: 21
asserts:
- equal:
path: spec.ports
value:
- name: tcp-445
port: 445
targetPort: tcp-21
protocol: TCP
- it: Should set default port
asserts:
- equal:
Expand Down

0 comments on commit 51208eb

Please sign in to comment.