mirror of
https://github.com/k8s-at-home/charts.git
synced 2025-01-24 16:09:08 +00:00
[common] Read and the service ports correctly (#170)
This commit is contained in:
parent
e67b0cc17b
commit
e46d898ee4
@ -2,7 +2,7 @@ apiVersion: v2
|
|||||||
name: common
|
name: common
|
||||||
description: Function library for k8s-at-home charts
|
description: Function library for k8s-at-home charts
|
||||||
type: library
|
type: library
|
||||||
version: 1.5.0
|
version: 1.5.1
|
||||||
keywords:
|
keywords:
|
||||||
- k8s-at-home
|
- k8s-at-home
|
||||||
- common
|
- common
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
{{/*
|
||||||
|
service class: all services should adhere to this
|
||||||
|
*/}}
|
||||||
{{- define "common.classes.service" -}}
|
{{- define "common.classes.service" -}}
|
||||||
{{- $values := .Values.service -}}
|
{{- $values := .Values.service -}}
|
||||||
{{- if hasKey . "ObjectValues" -}}
|
{{- if hasKey . "ObjectValues" -}}
|
||||||
@ -9,7 +12,7 @@
|
|||||||
{{- if hasKey $values "nameSuffix" -}}
|
{{- if hasKey $values "nameSuffix" -}}
|
||||||
{{- $serviceName = printf "%v-%v" $serviceName $values.nameSuffix -}}
|
{{- $serviceName = printf "%v-%v" $serviceName $values.nameSuffix -}}
|
||||||
{{ end -}}
|
{{ end -}}
|
||||||
{{- $svcType := $values.type -}}
|
{{- $svcType := $values.type | default "" -}}
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Service
|
kind: Service
|
||||||
metadata:
|
metadata:
|
||||||
@ -58,17 +61,7 @@ spec:
|
|||||||
{{- if $values.publishNotReadyAddresses }}
|
{{- if $values.publishNotReadyAddresses }}
|
||||||
publishNotReadyAddresses: {{ $values.publishNotReadyAddresses }}
|
publishNotReadyAddresses: {{ $values.publishNotReadyAddresses }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
ports:
|
{{- include "common.classes.service.ports" (dict "svcType" $svcType "values" $values ) | trim | nindent 2 }}
|
||||||
- port: {{ $values.port.port }}
|
|
||||||
targetPort: {{ $values.port.targetPort }}
|
|
||||||
protocol: {{ $values.port.protocol }}
|
|
||||||
name: {{ $values.port.name }}
|
|
||||||
{{- if (and (eq $svcType "NodePort") (not (empty $values.port.nodePort))) }}
|
|
||||||
nodePort: {{ $values.port.nodePort }}
|
|
||||||
{{ end }}
|
|
||||||
{{- with $values.additionalPorts }}
|
|
||||||
{{ toYaml . | nindent 4 }}
|
|
||||||
{{- end }}
|
|
||||||
selector:
|
selector:
|
||||||
{{- include "common.labels.selectorLabels" . | nindent 4 }}
|
{{- include "common.labels.selectorLabels" . | nindent 4 }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
23
charts/common/templates/classes/_service_ports.tpl
Normal file
23
charts/common/templates/classes/_service_ports.tpl
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
{{/*
|
||||||
|
logic that lists the ports and additionalPorts for a service
|
||||||
|
*/}}
|
||||||
|
{{- define "common.classes.service.ports" -}}
|
||||||
|
{{- $ports := list -}}
|
||||||
|
{{- $values := .values -}}
|
||||||
|
{{- $ports = mustAppend $ports $values.port -}}
|
||||||
|
{{- range $_ := $values.additionalPorts -}}
|
||||||
|
{{- $ports = mustAppend $ports . -}}
|
||||||
|
{{- end }}
|
||||||
|
{{- if $ports -}}
|
||||||
|
ports:
|
||||||
|
{{- range $_ := $ports }}
|
||||||
|
- port: {{ .port }}
|
||||||
|
targetPort: {{ .targetPort | default .name }}
|
||||||
|
protocol: {{ .protocol | default "TCP" }}
|
||||||
|
name: {{ .name }}
|
||||||
|
{{- if (and (eq $.svcType "NodePort") (not (empty .nodePort))) }}
|
||||||
|
nodePort: {{ .nodePort }}
|
||||||
|
{{ end }}
|
||||||
|
{{- end -}}
|
||||||
|
{{- end -}}
|
||||||
|
{{- end }}
|
@ -1,4 +1,6 @@
|
|||||||
{{- /* The main containter that will be included in the controller */ -}}
|
{{- /*
|
||||||
|
The main containter that will be included in the controller
|
||||||
|
*/ -}}
|
||||||
{{- define "common.controller.mainContainer" -}}
|
{{- define "common.controller.mainContainer" -}}
|
||||||
- name: {{ template "common.names.fullname" . }}
|
- name: {{ template "common.names.fullname" . }}
|
||||||
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
|
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
|
||||||
@ -14,15 +16,7 @@
|
|||||||
value: {{ $value | quote }}
|
value: {{ $value | quote }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
ports:
|
{{- include "common.controller.ports" . | trim | nindent 2 }}
|
||||||
- name: {{ .Values.service.port.name }}
|
|
||||||
containerPort: {{ .Values.service.port.port }}
|
|
||||||
protocol: {{ .Values.service.port.protocol }}
|
|
||||||
{{- range $port := .Values.service.additionalPorts }}
|
|
||||||
- name: {{ $port.name }}
|
|
||||||
containerPort: {{ $port.port }}
|
|
||||||
protocol: {{ $port.protocol }}
|
|
||||||
{{- end }}
|
|
||||||
volumeMounts:
|
volumeMounts:
|
||||||
{{- range $index, $PVC := .Values.persistence }}
|
{{- range $index, $PVC := .Values.persistence }}
|
||||||
{{- if $PVC.enabled }}
|
{{- if $PVC.enabled }}
|
||||||
|
36
charts/common/templates/lib/controller/_ports.tpl
Normal file
36
charts/common/templates/lib/controller/_ports.tpl
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
{{/*
|
||||||
|
ports included by the controller
|
||||||
|
*/}}
|
||||||
|
{{- define "common.controller.ports" -}}
|
||||||
|
{{- $ports := list -}}
|
||||||
|
{{- with .Values.service -}}
|
||||||
|
{{- $serviceValues := deepCopy . -}}
|
||||||
|
{{/* append the ports for the main service */}}
|
||||||
|
{{- if .enabled -}}
|
||||||
|
{{- $ports = mustAppend $ports .port -}}
|
||||||
|
{{- range $_ := .additionalPorts -}}
|
||||||
|
{{/* append the additonalPorts for the main service */}}
|
||||||
|
{{- $ports = mustAppend $ports . -}}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
{{/* append the ports for each additional service */}}
|
||||||
|
{{- range $_ := .additionalServices }}
|
||||||
|
{{- if .enabled -}}
|
||||||
|
{{- $ports = mustAppend $ports .port -}}
|
||||||
|
{{- range $_ := .additionalPorts -}}
|
||||||
|
{{/* append the additonalPorts for each additional service */}}
|
||||||
|
{{- $ports = mustAppend $ports . -}}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
{{/* export/render the list of ports */}}
|
||||||
|
{{- if $ports -}}
|
||||||
|
ports:
|
||||||
|
{{- range $_ := $ports }}
|
||||||
|
- name: {{ required "Missing port.name" .name }}
|
||||||
|
containerPort: {{ required "Missing port.port" .port }}
|
||||||
|
protocol: {{ .protocol | default "TCP" }}
|
||||||
|
{{- end -}}
|
||||||
|
{{- end -}}
|
||||||
|
{{- end -}}
|
Loading…
Reference in New Issue
Block a user