Commit 4f2ef369 authored by Waqar Ahmed's avatar Waqar Ahmed

Add common implementation of services

parent 0261fef3
{{/*
This template serves as a blueprint for all Service objects that are created
within the common library.
*/}}
{{- define "common.classes.service" -}}
{{- $values := . -}}
{{- $serviceName := include "common.names.fullname" . -}}
{{- if hasKey $values "nameSuffix" -}}
{{- $serviceName = printf "%v-%v" $serviceName $values.nameSuffix -}}
{{ end -}}
{{- $svcType := $values.type | default "" -}}
apiVersion: v1
kind: Service
metadata:
name: {{ $serviceName }}
labels:
{{- include "common.labels" . | nindent 4 }}
{{- if $values.labels }}
{{ toYaml $values.labels | nindent 4 }}
{{- end }}
{{- if $values.annotations }}
{{- with $values.annotations }}
annotations:
{{ toYaml . | nindent 4 }}
{{- end }}
{{- end }}
spec:
{{- if (or (eq $svcType "ClusterIP") (empty $svcType)) }}
type: ClusterIP
{{- if $values.clusterIP }}
clusterIP: {{ $values.clusterIP }}
{{end}}
{{- else if eq $svcType "NodePort" }}
type: {{ $svcType }}
{{- else }}
{{- fail "Only ClusterIP and NodePort services are supported in common chart" }}
{{- end }}
{{- include "common.classes.service.ports" (dict "svcType" $svcType "values" $values ) | trim | nindent 2 }}
selector:
{{- include "common.labels.selectorLabels" . | nindent 4 }}
{{- end }}
{{/*
Render all the ports and additionalPorts for a Service object.
*/}}
{{- define "common.classes.service.ports" -}}
{{- $values := .values -}}
{{- $ports := $values.ports -}}
{{- if $ports -}}
ports:
{{- range $_ := $ports }}
- port: {{ .port }}
targetPort: {{ .targetPort | default "http" }}
protocol: {{ .protocol | default "TCP" }}
name: {{ .name | default "http" }}
{{- if (and (eq $.svcType "NodePort") (not (empty .nodePort))) }}
nodePort: {{ .nodePort }}
{{ end }}
{{- end -}}
{{- end -}}
{{- end }}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment