From 44b2f2e0cea12c7977fcc1ca47f275f1cbe23e6d Mon Sep 17 00:00:00 2001 From: Stavros kois Date: Fri, 25 Nov 2022 15:45:56 +0200 Subject: [PATCH] "finish" service --- .../common/1.0.0/templates/class/_service.tpl | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/library/common/1.0.0/templates/class/_service.tpl b/library/common/1.0.0/templates/class/_service.tpl index dd235304..5ba567d0 100644 --- a/library/common/1.0.0/templates/class/_service.tpl +++ b/library/common/1.0.0/templates/class/_service.tpl @@ -27,13 +27,14 @@ metadata: {{- with (include "ix.v1.common.util.annotations.render" (dict "root" $root "annotations" $annotations) | trim) }} annotations: {{- . | nindent 4 }} - {{- end }} + {{/* TODO: Make sure bellow annotations are added even if the above include is empty */}} {{- if and $root.addAnnotations.traefik (eq ($primaryPort.protocol | default "") "HTTPS") }} traefik.ingress.kubernetes.io/service.serversscheme: https {{- end -}} {{- if and $root.addAnnotations.metallb (eq $svcType "LoadBalancer") }} metallb.universe.tf/allow-shared-ip: {{ include "ix.v1.common.names.fullname" . }} {{- end -}} + {{- end }} spec: {{- if has $svcType (list "ClusterIP" "NodePort" "ExternalName" "LoadBalancer") }} type: {{ $svcType }} {{/* Specify type only for the above types */}} @@ -136,4 +137,35 @@ selector: {{- include "ix.v1.common.labels.selectorLabels" $root | nindent 4 }} {{- end }} {{- end -}} +{{- if eq $svcType "ExternalIP" }} +--- +apiVersion: {{ include "ix.v1.common.capabilities.endpoints.apiVersion" $root }} +kind: Endpoints +metadata: + name: {{ $svcName }} + {{- $labels := (mustMerge ($svcValues.labels | default dict) (include "ix.v1.common.labels" $root | fromYaml)) -}} + {{- with (include "ix.v1.common.util.labels.render" (dict "root" $root "labels" $labels) | trim) }} + labels: + {{- . | nindent 4 }} + {{- end }} + {{- $annotations := (mustMerge ($svcValues.annotations | default dict) (include "ix.v1.common.annotations" $root | fromYaml)) -}} + {{- with (include "ix.v1.common.util.annotations.render" (dict "root" $root "annotations" $annotations) | trim) }} + annotations: + {{- . | nindent 4 }} + {{- end }} + {{- with $svcValues.externalIP }} +subsets: + - addresses: + - {{ tpl . $root }} + {{- else -}} + {{- fail "Service type is set to ExternalIP, but no externalIP is defined." -}} + {{- end -}} + ports: + {{- range $name, $port := $svcValues.ports }} + {{- if $port.enabled }} + - port: {{ $port.port }} + name: {{ $name }} + {{- end }} + {{- end }} +{{- end -}} {{- end -}}