From 61028541f14c6beddeaf0a14a25702cce29a5209 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=E1=B4=87=CA=80=C9=B4=E1=B4=85=20S=E1=B4=84=CA=9C?= =?UTF-8?q?=E1=B4=8F=CA=80=C9=A2=E1=B4=87=CA=80s?= <6213398+bjw-s@users.noreply.github.com> Date: Fri, 8 Jan 2021 15:21:03 +0100 Subject: [PATCH] [common] v2.2.1 (#480) * [common] v2.2.1 --- charts/common/CHANGELOG.md | 8 ++++++++ charts/common/Chart.yaml | 2 +- charts/common/templates/lib/controller/_ports.tpl | 3 +++ charts/common/values.yaml | 5 +++-- test/charts/common-test_spec.rb | 15 +++++++++++++++ 5 files changed, 30 insertions(+), 3 deletions(-) diff --git a/charts/common/CHANGELOG.md b/charts/common/CHANGELOG.md index 12d0116b..8a627487 100644 --- a/charts/common/CHANGELOG.md +++ b/charts/common/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2.2.1] + +### Fixed + +- Made explicit that `service.port.targetPort` cannot be a named port. + ## [2.2.0] ### Added @@ -53,6 +59,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 This is the last version before starting this changelog. All sorts of cool stuff was changed, but only `git log` remembers what that was :slightly_frowning_face: +[2.2.1]: https://github.com/k8s-at-home/charts/tree/common-2.2.1/charts/common + [2.2.0]: https://github.com/k8s-at-home/charts/tree/common-2.2.0/charts/common [2.1.0]: https://github.com/k8s-at-home/charts/tree/common-2.1.0/charts/common diff --git a/charts/common/Chart.yaml b/charts/common/Chart.yaml index 29362361..a11f0a6c 100644 --- a/charts/common/Chart.yaml +++ b/charts/common/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 name: common description: Function library for k8s-at-home charts type: library -version: 2.2.0 +version: 2.2.1 keywords: - k8s-at-home - common diff --git a/charts/common/templates/lib/controller/_ports.tpl b/charts/common/templates/lib/controller/_ports.tpl index c7fc4ac6..58daab31 100644 --- a/charts/common/templates/lib/controller/_ports.tpl +++ b/charts/common/templates/lib/controller/_ports.tpl @@ -32,6 +32,9 @@ Ports included by the controller. ports: {{- range $_ := $ports }} - name: {{ .name }} + {{- if and .targetPort (kindIs "string" .targetPort) }} + {{- fail (printf "Our charts do not support named ports for targetPort. (port name %s, targetPort %s)" .name .targetPort) }} + {{- end }} containerPort: {{ .targetPort | default .port }} protocol: {{ .protocol | default "TCP" }} {{- end -}} diff --git a/charts/common/values.yaml b/charts/common/values.yaml index 8c453b31..23402a44 100644 --- a/charts/common/values.yaml +++ b/charts/common/values.yaml @@ -107,8 +107,9 @@ service: ## name defaults to http name: protocol: TCP - ## targetPort defaults to the service name. If targetPort is specified, this port number - ## is used in the container definition instead of service.port.port. + ## Specify a service targetPort if you wish to differ the service port from the application port. + ## If targetPort is specified, this port number is used in the container definition instead of + ## service.port.port. Therefore named ports are not supported for this field. targetPort: ## Specify the nodePort value for the LoadBalancer and NodePort service types. ## ref: https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport diff --git a/test/charts/common-test_spec.rb b/test/charts/common-test_spec.rb index 5fb270f5..b7a198a1 100644 --- a/test/charts/common-test_spec.rb +++ b/test/charts/common-test_spec.rb @@ -81,6 +81,21 @@ class Test < ChartTest jq('.spec.template.spec.containers[0].ports[0].containerPort', resource('Deployment')).must_equal values[:service][:port][:targetPort] jq('.spec.template.spec.containers[0].ports[0].name', resource('Deployment')).must_equal default_name end + + it 'targetPort cannot be a named port' do + values = { + service: { + port: { + targetPort: 'test' + } + } + } + chart.value values + exception = assert_raises HelmCompileError do + chart.execute_helm_template! + end + assert_match("Our charts do not support named ports for targetPort. (port name #{default_name}, targetPort #{values[:service][:port][:targetPort]})", exception.message) + end end end end