diff --git a/library/common-test/tests/container_in_deployment/port_test.yaml b/library/common-test/tests/container_in_deployment/port_test.yaml index d47a651b..d478630f 100644 --- a/library/common-test/tests/container_in_deployment/port_test.yaml +++ b/library/common-test/tests/container_in_deployment/port_test.yaml @@ -33,6 +33,15 @@ tests: - failedTemplate: errorMessage: Port is required on enabled services. Service (main) + - it: should fail without ports dict in an enabled service + set: + service: + other: + enabled: true + asserts: + - failedTemplate: + errorMessage: At least one port is required in an enabled service (other) + - it: should fail with disabled port on enabled service set: service: diff --git a/library/common-test/tests/utils/utils_primary_service_test.yaml b/library/common-test/tests/utils/utils_primary_service_test.yaml index 7c74b574..c4d5cb2d 100644 --- a/library/common-test/tests/utils/utils_primary_service_test.yaml +++ b/library/common-test/tests/utils/utils_primary_service_test.yaml @@ -30,6 +30,10 @@ tests: other: enabled: true primary: true + ports: + other: + enabled: true + port: 80 asserts: - failedTemplate: errorMessage: More than one services are set as primary. This is not supported. diff --git a/library/common/1.0.0/templates/lib/container/_ports.tpl b/library/common/1.0.0/templates/lib/container/_ports.tpl index bb84a7c8..c3a61739 100644 --- a/library/common/1.0.0/templates/lib/container/_ports.tpl +++ b/library/common/1.0.0/templates/lib/container/_ports.tpl @@ -6,9 +6,12 @@ can be dynamically configured via an env var. {{/* Ports included by the container. */}} {{- define "ix.v1.common.container.ports" -}} {{ $ports := list }} - {{- range .Values.service -}} - {{- if .enabled -}} - {{- range $name, $port := .ports -}} + {{- range $svcName, $svc := .Values.service -}} + {{- if $svc.enabled -}} + {{- if not $svc.ports -}} + {{- fail (printf "At least one port is required in an enabled service (%s)" $svcName) -}} + {{- end -}} + {{- range $name, $port := $svc.ports -}} {{- $_ := set $port "name" $name -}} {{- $ports = mustAppend $ports $port -}} {{- end -}}