[Common] Refactor Services (#212)
* Refactor All Services - services (dict, including main service) - additionalServices (list) * Add Documentation and standardised questions.yaml layout for services * Update all existing Apps to 2.0.0 * Fix whiteline error * fix addons
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
apiVersion: v2
|
||||
kubeVersion: ">=1.16.0-0"
|
||||
name: common
|
||||
<<<<<<< HEAD
|
||||
version: 1.6.7
|
||||
=======
|
||||
version: 2.0.0
|
||||
>>>>>>> [Common] Refactor Services (#212)
|
||||
# upstream_version: 3.0.1
|
||||
# appVersion:
|
||||
description: Function library for TrueCharts
|
||||
|
||||
@@ -38,9 +38,7 @@ Main entrypoint for the common library chart. It will render all underlying temp
|
||||
{{ else if eq .Values.controllerType "statefulset" }}
|
||||
{{- include "common.statefulset" . | nindent 0 }}
|
||||
{{- end -}}
|
||||
{{- print "---" | nindent 0 -}}
|
||||
{{ include "common.service" . | nindent 0 }}
|
||||
{{ include "common.appService" . | nindent 0 }}
|
||||
{{ include "common.services" . | nindent 0 }}
|
||||
{{- print "---" | nindent 0 -}}
|
||||
{{ include "common.ingress" . | nindent 0 }}
|
||||
{{- print "---" | nindent 0 -}}
|
||||
|
||||
@@ -22,7 +22,7 @@ of the main Ingress and any additionalIngresses.
|
||||
*/}}
|
||||
{{- define "common.ingress" -}}
|
||||
{{- if .Values.ingress.enabled -}}
|
||||
{{- $svcPort := .Values.service.port.port -}}
|
||||
{{- $svcPort := .Values.services.main.port.port -}}
|
||||
|
||||
{{- /* Generate primary ingress */ -}}
|
||||
{{- $ingressValues := .Values.ingress -}}
|
||||
|
||||
@@ -20,22 +20,22 @@ This file is considered to be modified by the TrueCharts Project.
|
||||
Default NOTES.txt content.
|
||||
*/}}
|
||||
{{- define "common.notes.defaultNotes" -}}
|
||||
{{- $svcPort := .Values.service.port.port -}}
|
||||
{{- $svcPort := .Values.services.main.port.port -}}
|
||||
1. Get the application URL by running these commands:
|
||||
{{- if .Values.ingress.enabled }}
|
||||
{{- range .Values.ingress.hosts }}
|
||||
http{{ if $.Values.ingress.tls }}s{{ end }}://{{- if .hostTpl }}{{ tpl .hostTpl $ }}{{ else }}{{ .host }}{{ end }}{{ (first .paths).path }}
|
||||
{{- end }}
|
||||
{{- else if contains "NodePort" .Values.service.type }}
|
||||
{{- else if contains "NodePort" .Values.services.main.type }}
|
||||
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "common.names.fullname" . }})
|
||||
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
|
||||
echo http://$NODE_IP:$NODE_PORT
|
||||
{{- else if contains "LoadBalancer" .Values.service.type }}
|
||||
{{- else if contains "LoadBalancer" .Values.services.main.type }}
|
||||
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
|
||||
You can watch the status of by running 'kubectl get svc -w {{ include "common.names.fullname" . }}'
|
||||
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "common.names.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
|
||||
echo http://$SERVICE_IP:{{ $svcPort }}
|
||||
{{- else if contains "ClusterIP" .Values.service.type }}
|
||||
{{- else if contains "ClusterIP" .Values.services.main.type }}
|
||||
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "common.names.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
|
||||
echo "Visit http://127.0.0.1:8080 to use your application"
|
||||
kubectl port-forward $POD_NAME 8080:{{ $svcPort }}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
{{/*
|
||||
Renders the Service objects required by the chart by returning a concatinated list
|
||||
of the main Service and any additionalServices.
|
||||
*/}}
|
||||
{{- define "common.services" -}}
|
||||
{{- if .Values.services -}}
|
||||
{{- /* Add dict of primary services */ -}}
|
||||
{{- range $name, $service := .Values.services }}
|
||||
{{- if or ( $service.enabled ) ( eq $name "main" ) -}}
|
||||
{{- print ("---") | nindent 0 -}}
|
||||
{{- print ("\n") | nindent 0 -}}
|
||||
{{- $serviceValues := $service -}}
|
||||
{{- /* Dont add name suffix for primary service named "main" */ -}}
|
||||
{{- if or (not $serviceValues.nameSuffix) ( ne $name "main" ) -}}
|
||||
{{- $_ := set $serviceValues "nameSuffix" $name -}}
|
||||
{{ end -}}
|
||||
{{- $_ := set $ "ObjectValues" (dict "service" $serviceValues) -}}
|
||||
{{- include "common.classes.service" $ -}}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
|
||||
{{- if .Values.additionalServices -}}
|
||||
{{- /* Generate additional services as required */ -}}
|
||||
{{- range $index, $extraService := .Values.additionalServices }}
|
||||
{{- if $extraService.enabled -}}
|
||||
{{- print ("---") | nindent 0 -}}
|
||||
{{- $serviceValues := $extraService -}}
|
||||
{{- if not $serviceValues.nameSuffix -}}
|
||||
{{- $_ := set $serviceValues "nameSuffix" $index -}}
|
||||
{{ end -}}
|
||||
{{- $_ := set $ "ObjectValues" (dict "service" $serviceValues) -}}
|
||||
{{- include "common.classes.service" $ -}}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
@@ -21,7 +21,7 @@ This template serves as a blueprint for all Service objects that are created
|
||||
within the common library.
|
||||
*/}}
|
||||
{{- define "common.classes.service" -}}
|
||||
{{- $values := .Values.service -}}
|
||||
{{- $values := .Values.services.main -}}
|
||||
{{- if hasKey . "ObjectValues" -}}
|
||||
{{- with .ObjectValues.service -}}
|
||||
{{- $values = . -}}
|
||||
|
||||
@@ -14,7 +14,7 @@ within the common library.
|
||||
{{- $IngressName = printf "%v-%v" $IngressName $values.nameSuffix -}}
|
||||
{{ end -}}
|
||||
{{- $svcName := $values.serviceName | default (include "common.names.fullname" .) -}}
|
||||
{{- $svcPort := $values.servicePort | default $.Values.service.port.port -}}
|
||||
{{- $svcPort := $values.servicePort | default $.Values.services.main.port.port -}}
|
||||
apiVersion: {{ include "common.capabilities.ingress.apiVersion" . }}
|
||||
kind: Ingress
|
||||
metadata:
|
||||
|
||||
@@ -14,7 +14,7 @@ within the common library.
|
||||
{{- $IngressName = printf "%v-%v" $IngressName $values.nameSuffix -}}
|
||||
{{ end -}}
|
||||
{{- $svcName := $values.serviceName | default (include "common.names.fullname" .) -}}
|
||||
{{- $svcPort := $values.servicePort | default $.Values.service.port.port -}}
|
||||
{{- $svcPort := $values.servicePort | default $.Values.services.main.port.port -}}
|
||||
apiVersion: traefik.containo.us/v1alpha1
|
||||
kind: IngressRouteTCP
|
||||
metadata:
|
||||
|
||||
@@ -14,7 +14,7 @@ within the common library.
|
||||
{{- $IngressName = printf "%v-%v" $IngressName $values.nameSuffix -}}
|
||||
{{ end -}}
|
||||
{{- $svcName := $values.serviceName | default (include "common.names.fullname" .) -}}
|
||||
{{- $svcPort := $values.servicePort | default $.Values.service.port.port -}}
|
||||
{{- $svcPort := $values.servicePort | default $.Values.services.main.port.port -}}
|
||||
apiVersion: traefik.containo.us/v1alpha1
|
||||
kind: IngressRouteUDP
|
||||
metadata:
|
||||
|
||||
@@ -32,7 +32,7 @@ within the common library.
|
||||
{{- $ingressName = printf "%v-%v" $ingressName $values.nameSuffix -}}
|
||||
{{ end -}}
|
||||
{{- $svcName := $values.serviceName | default (include "common.names.fullname" .) -}}
|
||||
{{- $svcPort := $values.servicePort | default $.Values.service.port.port -}}
|
||||
{{- $svcPort := $values.servicePort | default $.Values.services.main.port.port -}}
|
||||
apiVersion: {{ include "common.capabilities.ingress.apiVersion" . }}
|
||||
kind: Ingress
|
||||
metadata:
|
||||
|
||||
@@ -21,34 +21,14 @@ This file is considered to be modified by the TrueCharts Project.
|
||||
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 -}}
|
||||
{{- $_ := set .port "name" (default "http" .port.name) -}}
|
||||
{{- $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 -}}
|
||||
{{- $_ := set .port "name" (required "Missing port.name" .port.name) -}}
|
||||
{{- $ports = mustAppend $ports .port -}}
|
||||
{{- range $_ := .additionalPorts -}}
|
||||
{{/* append the additonalPorts for each additional service */}}
|
||||
{{- $ports = mustAppend $ports . -}}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- $ports := list -}}
|
||||
{{/* append the ports for each appAdditionalService - TrueCharts */}}
|
||||
{{- if and $.Values.appAdditionalServicesEnabled $.Values.appAdditionalServices -}}
|
||||
{{- range $name, $_ := $.Values.appAdditionalServices }}
|
||||
{{- if .enabled -}}
|
||||
{{- if kindIs "string" $name -}}
|
||||
{{- if $.Values.services -}}
|
||||
{{- range $name, $_ := $.Values.services }}
|
||||
{{- if or ( .enabled ) ( eq $name "main" ) -}}
|
||||
{{- if eq $name "main" -}}
|
||||
{{- $_ := set .port "name" (default "http" .port.name) -}}
|
||||
{{- else if kindIs "string" $name -}}
|
||||
{{- $_ := set .port "name" (default .port.name | default $name) -}}
|
||||
{{- else -}}
|
||||
{{- $_ := set .port "name" (required "Missing port.name" .port.name) -}}
|
||||
@@ -61,7 +41,19 @@ Ports included by the controller.
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
{{- if $.Values.additionalServices -}}
|
||||
{{- range $_ := $.Values.additionalServices }}
|
||||
{{- if .enabled -}}
|
||||
{{- $_ := set .port "name" (required "Missing port.name" .port.name) -}}
|
||||
{{- $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 -}}
|
||||
|
||||
@@ -21,7 +21,7 @@ This file is considered to be modified by the TrueCharts Project.
|
||||
Probes selection logic.
|
||||
*/}}
|
||||
{{- define "common.controller.probes" -}}
|
||||
{{- $svcPort := .Values.service.port.name -}}
|
||||
{{- $svcPort := .Values.services.main.port.name -}}
|
||||
{{- range $probeName, $probe := .Values.probes }}
|
||||
{{- if $probe.enabled -}}
|
||||
{{- "" | nindent 0 }}
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
{{/*
|
||||
Renders the additioanl Service objects from appAdditionalServices
|
||||
*/}}
|
||||
{{- define "common.appService" -}}
|
||||
{{- /* Generate TrueNAS SCALE app services as required v1 */ -}}
|
||||
{{- if and .Values.appAdditionalServicesEnabled .Values.appAdditionalServices -}}
|
||||
{{- range $name, $srv := .Values.appAdditionalServices }}
|
||||
{{- if $srv.enabled -}}
|
||||
{{- print ("---") | nindent 0 -}}
|
||||
{{- $serviceValues := $srv -}}
|
||||
{{- if not $serviceValues.nameSuffix -}}
|
||||
{{- $_ := set $serviceValues "nameSuffix" $name -}}
|
||||
{{ end -}}
|
||||
{{- $_ := set $ "ObjectValues" (dict "service" $serviceValues) -}}
|
||||
{{- include "common.classes.service" $ -}}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
+40
-39
@@ -129,48 +129,49 @@ probes:
|
||||
periodSeconds: 10
|
||||
failureThreshold: 30
|
||||
|
||||
service:
|
||||
enabled: true
|
||||
type: ClusterIP
|
||||
## Specify the default port information
|
||||
port:
|
||||
services:
|
||||
main:
|
||||
enabled: true
|
||||
type: ClusterIP
|
||||
## Specify the default port information
|
||||
port:
|
||||
## name defaults to http
|
||||
name:
|
||||
protocol: TCP
|
||||
## 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
|
||||
port:
|
||||
## name defaults to http
|
||||
name:
|
||||
protocol: TCP
|
||||
## 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
|
||||
##
|
||||
# nodePort:
|
||||
additionalPorts: []
|
||||
|
||||
## Provide any additional annotations which may be required. This can be used to
|
||||
## set the LoadBalancer service type to internal only.
|
||||
## ref: https://kubernetes.io/docs/concepts/services-networking/service/#internal-load-balancer
|
||||
##
|
||||
# nodePort:
|
||||
additionalPorts: []
|
||||
annotations: {}
|
||||
labels: {}
|
||||
|
||||
## Provide any additional annotations which may be required. This can be used to
|
||||
## set the LoadBalancer service type to internal only.
|
||||
## ref: https://kubernetes.io/docs/concepts/services-networking/service/#internal-load-balancer
|
||||
##
|
||||
annotations: {}
|
||||
labels: {}
|
||||
|
||||
additionalServices: []
|
||||
# - enabled: false
|
||||
# nameSuffix: api
|
||||
# type: ClusterIP
|
||||
# # Specify the default port information
|
||||
# port:
|
||||
# port:
|
||||
# # name defaults to http
|
||||
# name:
|
||||
# protocol: TCP
|
||||
# # targetPort defaults to http
|
||||
# targetPort:
|
||||
# # nodePort:
|
||||
# additionalPorts: []
|
||||
# annotations: {}
|
||||
# labels: {}
|
||||
additionalServices: []
|
||||
# - enabled: false
|
||||
# nameSuffix: api
|
||||
# type: ClusterIP
|
||||
# # Specify the default port information
|
||||
# port:
|
||||
# port:
|
||||
# # name defaults to http
|
||||
# name:
|
||||
# protocol: TCP
|
||||
# # targetPort defaults to http
|
||||
# targetPort:
|
||||
# # nodePort:
|
||||
# additionalPorts: []
|
||||
# annotations: {}
|
||||
# labels: {}
|
||||
|
||||
ingress:
|
||||
enabled: false
|
||||
|
||||
Reference in New Issue
Block a user