diff --git a/library/common/1.0.0/templates/lib/_annotations.md b/library/common/1.0.0/templates/lib/_annotations.md deleted file mode 100644 index d2a0f5d8..00000000 --- a/library/common/1.0.0/templates/lib/_annotations.md +++ /dev/null @@ -1,103 +0,0 @@ -# Annotations - -These named functions will usually be called into other common templates. -Chances for these to be called directly in an application chart should be non-existent. - -So some example inputs, should not be considered that will be used in a values.yaml. - ---- - -## ix.common.annotations - -Input: - -Values.yaml - -```yaml -global: - annotations: - annotation1: hard_value - annotation2: "{{ .Values.key }}" - -key: value -``` - -Output: - -```yaml -apiVersion: apps/v1 -kind: Deployment -metadata: - annotations: - - annotation1: "hard_value" - annotation2: "value" -``` - ---- - -## ix.common.annotations.workload.spec - -Inputs: - -Values.yaml - -```yaml -ixExternalInterfacesConfigurationNames: - - iface1 - - iface2 -``` - -Template file - -```yaml -apiVersion: apps/v1 -kind: Deployment -metadata: - ... -spec: - template: - metadata: - annotations: - {{- include "ix.common.annotations.workload.spec" $ | nindent 8 }} -``` - -Output: - -```yaml -apiVersion: apps/v1 -kind: Deployment -metadata: -spec: - template: - metadata: - annotations: - - k8s.v1.cni.cncf.io/networks: iface1, iface2 -``` - ---- - -## ix.common.annotations.workload - -Input: - -Template file - -```yaml -apiVersion: apps/v1 -kind: Deployment -metadata: - annotations: - {{- include "ix.common.annotations.workload" $ | nindent 4 }} -``` - -Output: - -```yaml -apiVersion: apps/v1 -kind: Deployment -metadata: - annotations: - rollme: "aqG2v" -``` diff --git a/library/common/1.0.0/templates/lib/_annotations.tpl b/library/common/1.0.0/templates/lib/chart/_annotations.tpl similarity index 72% rename from library/common/1.0.0/templates/lib/_annotations.tpl rename to library/common/1.0.0/templates/lib/chart/_annotations.tpl index 136aba62..104a494c 100644 --- a/library/common/1.0.0/templates/lib/_annotations.tpl +++ b/library/common/1.0.0/templates/lib/chart/_annotations.tpl @@ -1,5 +1,6 @@ {{/* These annotations will be shared on all objects +Rendered under ".metadata.annotations" */}} {{- define "ix.common.annotations" -}} {{- with .Values.global.annotations -}} @@ -10,7 +11,8 @@ These annotations will be shared on all objects {{- end -}} {{/* -These annotations will be applied to all workload "spec" objects +These annotations will be applied to all "workload" "spec" objects +Rendered under ".spec.template.metadata.annotations" */}} {{- define "ix.common.annotations.workload.spec" -}} {{- if .Values.ixExternalInterfacesConfigurationNames }} @@ -19,7 +21,8 @@ k8s.v1.cni.cncf.io/networks: {{ join ", " .Values.ixExternalInterfacesConfigurat {{- end -}} {{/* -These annotations will be applied to all workload objects +These annotations will be applied to all "workload" objects +Rendered under ".metadata.annotations" */}} {{- define "ix.common.annotations.workload" -}} rollme: {{ randAlphaNum 5 | quote }} diff --git a/library/common/1.0.0/templates/lib/chart/_names.tpl b/library/common/1.0.0/templates/lib/chart/_names.tpl new file mode 100644 index 00000000..bec2cc42 --- /dev/null +++ b/library/common/1.0.0/templates/lib/chart/_names.tpl @@ -0,0 +1,68 @@ +{{/* +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +global.nameOverride applies to the current chart and all sub-charts +nameOverride applies only to the current chart +*/}} + +{{/* +Expand ther name of the chart +*/}} +{{- define "ix.common.names.name" -}} + {{- $globalNameOverride := "" -}} + {{- if hasKey .Values "global" -}} + {{/* Set to global.nameOverride if set, else set to empty */}} + {{- $globalNameOverride = (default $globalNameOverride .Values.global.nameOverride) -}} + {{- end -}} + {{/* Order of preference: global.nameOverride -> nameOverride -> Chart.Name */}} + {{- default .Chart.Name (default .Values.nameOverride $globalNameOverride) | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Create a default fully qualified app name. +*/}} +{{- define "ix.common.names.fullname" -}} + {{- $name := include "ix.common.names.name" . -}} + {{- $globalFullNameOverride := "" -}} + {{- if hasKey .Values "global" -}} + {{- $globalFullNameOverride = (default $globalFullNameOverride .Values.global.fullnameOverride) -}} + {{- end -}} + {{- if or .Values.fullnameOverride $globalFullNameOverride -}} + {{- $name = default .Values.fullnameOverride $globalFullNameOverride -}} + {{- else -}} + {{- if contains $name .Release.Name -}} + {{- $name = .Release.Name -}} + {{- else -}} + {{- $name = printf "%s-%s" .Release.Name $name -}} + {{- end -}} + {{- end -}} + {{- trunc 63 $name | trimSuffix "-" -}} +{{- end -}} + +{{/* +Return the properly cased vresion of the controller type +*/}} +{{- define "ix.common.names.controllerType" -}} + {{- if eq .Values.controller.type "deployment" -}} + {{- print "Deployment" -}} + {{- else if eq .Values.controller.type "daemonset" -}} + {{- print "DaemonSet" -}} + {{- else if eq .Values.controller.type "statefulset" -}} + {{- print "StatefulSet" -}} + {{- else -}} + {{- fail (printf "Not a valid controller.type (%s)" .Values.controller.type) -}} + {{- end -}} +{{- end -}} + +{{/* +Create the "name" + "." + "namespace" fqdn +*/}} +{{- define "ix.common.names.fqdn" -}} + {{- printf "%s.%s" (include "tc.common.names.fullname" .) .Release.Namespace | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Create the "fqdn" + "." + "svc.cluster.local" +*/}} +{{- define "ix.common.names.fqdn" -}} + {{- printf "%s.%s" (include "ix.common.names.fqdn" .) ".svc.cluster.local" -}} +{{- end -}} diff --git a/library/common/1.0.0/values.yaml b/library/common/1.0.0/values.yaml index 12d2b517..3802a9eb 100644 --- a/library/common/1.0.0/values.yaml +++ b/library/common/1.0.0/values.yaml @@ -1,7 +1,16 @@ global: - # -- Set additional global annotations. Helm templates can be used. + # -- Sets an override for the suffix of the full name (Applies to current chart and all sub-charts) + nameOverride: "" + # -- Sets additional global annotations. Helm templates can be used. annotations: {} +# -- Sets an override for the suffix of the full name (Applies to current chart only) +nameOverride: "" + ixExternalInterfacesConfigurationNames: [] - # - iface1 - # - iface2 + # - interface1 + # - interface2 + +controller: + # Valid options are: deployment | daemonset | statefulset + type: deployment