From 941c1741f94f092fc0314350949674fc10499f5a Mon Sep 17 00:00:00 2001 From: Pedro Nauck Date: Wed, 22 Jan 2025 15:02:09 -0300 Subject: [PATCH] build(repo): Fixing helm charts helpers --- cluster/charts/fuel-streams/Chart.yaml | 2 +- .../templates/_blocks-container.tpl | 111 +++++++++++ .../fuel-streams/templates/_blocks-nats.tpl | 20 ++ .../fuel-streams/templates/_blocks-pod.tpl | 102 ++++++++++ .../templates/_blocks-resource.tpl | 53 +++++ .../templates/_blocks-template.tpl | 49 +++++ .../charts/fuel-streams/templates/_blocks.tpl | 184 ------------------ .../charts/fuel-streams/templates/_hpa.yaml | 13 +- .../fuel-streams/templates/common-config.yaml | 12 +- .../templates/consumer/deployment.yaml | 20 +- .../templates/publisher/statefulset.yaml | 20 +- .../templates/service-account.yaml | 8 +- .../templates/webserver/certificate.yaml | 9 +- .../templates/webserver/deployment.yaml | 30 +-- .../tests/consumer/deployment_test.yaml | 45 ++++- .../tests/publisher/statefulset_test.yaml | 45 ++++- .../tests/webserver/deployment_test.yaml | 45 ++++- cluster/charts/fuel-streams/values.yaml | 15 +- 18 files changed, 540 insertions(+), 243 deletions(-) create mode 100644 cluster/charts/fuel-streams/templates/_blocks-container.tpl create mode 100644 cluster/charts/fuel-streams/templates/_blocks-nats.tpl create mode 100644 cluster/charts/fuel-streams/templates/_blocks-pod.tpl create mode 100644 cluster/charts/fuel-streams/templates/_blocks-resource.tpl create mode 100644 cluster/charts/fuel-streams/templates/_blocks-template.tpl delete mode 100644 cluster/charts/fuel-streams/templates/_blocks.tpl diff --git a/cluster/charts/fuel-streams/Chart.yaml b/cluster/charts/fuel-streams/Chart.yaml index 06c4b971..cfc6be2b 100755 --- a/cluster/charts/fuel-streams/Chart.yaml +++ b/cluster/charts/fuel-streams/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 appVersion: "1.0" description: A Helm chart for Kubernetes name: fuel-streams -version: 0.9.1 +version: 0.9.2 dependencies: - name: nats version: 1.2.9 diff --git a/cluster/charts/fuel-streams/templates/_blocks-container.tpl b/cluster/charts/fuel-streams/templates/_blocks-container.tpl new file mode 100644 index 00000000..0cdfbd04 --- /dev/null +++ b/cluster/charts/fuel-streams/templates/_blocks-container.tpl @@ -0,0 +1,111 @@ +{{/* +Configure container resource requests and limits +Parameters: + - root: Root context object for fallback values + - context: Service-specific context object containing configuration +*/}} +{{ define "k8s.container-config.resources" -}} +{{- include "set-field-and-value" (dict "root" .root "context" .context "field" "resources") -}} +{{- end }} + +{{/* +Configure container security context settings +Parameters: + - root: Root context object for fallback values + - context: Service-specific context object containing configuration +*/}} +{{- define "k8s.container-config.securityContext" -}} +{{- include "set-field-and-value" (dict "root" .root "context" .context "field" "securityContext" "path" "config.containerSecurityContext") -}} +{{- end }} + +{{/* +Configure container health check probes +Parameters: + - root: Root context object for fallback values + - context: Service-specific context object containing configuration +*/}} +{{- define "k8s.container-config.probes" -}} +{{- if .root.Values.config.healthChecks }} +{{- include "set-field-and-value" (dict "root" .root "context" .context "field" "startupProbe") -}} +{{- include "set-field-and-value" (dict "root" .root "context" .context "field" "livenessProbe") -}} +{{- include "set-field-and-value" (dict "root" .root "context" .context "field" "readinessProbe") -}} +{{- end }} +{{- end }} + +{{- define "k8s.container-config.ports" -}} +ports: +{{- if .context.port }} +- name: {{ .context.name | default .name }} + containerPort: {{ .context.port }} + protocol: TCP +{{- end }} +{{- with .context.ports }} +{{ toYaml . | nindent 0 }} +{{- end }} +{{- end }} + +{{/* +Configure container environment variables +Parameters: + - root: Root context object for fallback values + - context: Service-specific context object containing configuration with port and env map +*/}} +{{- define "k8s.container-config.env" -}} +env: +{{- if .context.port }} +- name: PORT + value: {{ .context.port | quote }} +{{- end }} +{{- range $key, $value := .context.env }} +- name: {{ $key }} + value: {{ $value | quote }} +{{- end }} +{{- end }} + +{{/* +Configure container environment from external sources +Parameters: + - root: Root context object for fallback values + - context: Service-specific context object containing configuration with envFrom +*/}} +{{- define "k8s.container-config.envFrom" -}} +envFrom: +- configMapRef: + name: {{ include "fuel-streams.fullname" .root }}-config + optional: true +- secretRef: + name: {{ include "fuel-streams.fullname" .root }}-keys + optional: true +{{- with .context.envFrom }} +{{ toYaml . | nindent 0 }} +{{- end }} +{{- end }} + +{{/* +Configure container image settings +Parameters: + - root: Root context object for fallback values + - context: Service-specific context object containing image configuration +*/}} +{{- define "k8s.container-config.image" -}} +image: "{{ .context.image.repository }}:{{ .context.image.tag | default .root.Chart.AppVersion }}" +imagePullPolicy: {{ .context.image.pullPolicy }} +{{- end }} + +{{/* +Configure container-level settings including resource requests, security context, and probes +Parameters: + - root: Root context object for fallback values + - context: Service-specific context object containing configuration + - component: Optional component name for labels + - name: Name of the service for labels +Returns: YAML configuration for container-level settings +*/}} +{{- define "k8s.container-config" -}} +{{ include "k8s.container-config.resources" . }} +{{ include "k8s.container-config.securityContext" . }} +{{ include "k8s.container-config.probes" . }} +{{ include "k8s.container-config.ports" . }} +{{ include "k8s.container-config.env" . }} +{{ include "k8s.container-config.envFrom" . }} +{{- end }} diff --git a/cluster/charts/fuel-streams/templates/_blocks-nats.tpl b/cluster/charts/fuel-streams/templates/_blocks-nats.tpl new file mode 100644 index 00000000..0f49cf8e --- /dev/null +++ b/cluster/charts/fuel-streams/templates/_blocks-nats.tpl @@ -0,0 +1,20 @@ +{{/* +* NATS default accounts +*/}} +{{- define "nats-accounts" -}} +data: + auth.conf: | + accounts { + SYS: { + users: [ + {user: $NATS_SYSTEM_USER, password: $NATS_SYSTEM_PASS} + ] + } + ADMIN: { + jetstream: enabled + users: [ + {user: $NATS_ADMIN_USER, password: $NATS_ADMIN_PASS} + ] + } + } +{{- end }} \ No newline at end of file diff --git a/cluster/charts/fuel-streams/templates/_blocks-pod.tpl b/cluster/charts/fuel-streams/templates/_blocks-pod.tpl new file mode 100644 index 00000000..a83aaab9 --- /dev/null +++ b/cluster/charts/fuel-streams/templates/_blocks-pod.tpl @@ -0,0 +1,102 @@ +{{/* +Configure default affinity settings for pod scheduling +*/}} +{{- define "k8s.pod-config.affinityy" -}} +podAntiAffinity: + preferredDuringSchedulingIgnoredDuringExecution: + - weight: 100 + podAffinityTerm: + labelSelector: + matchLabels: + app.kubernetes.io/component: publisher + topologyKey: topology.kubernetes.io/zone +{{- end }} + +{{/* +Configure pod spec header including replicas and selector labels +Parameters: + - root: Root context object for fallback values + - context: Service-specific context object containing configuration + - name: Name of the service for selector labels +Returns: YAML configuration for pod spec header +*/}} +{{- define "k8s.pod-spec" -}} +{{- if not .context.autoscaling.enabled }} +replicas: {{ .context.config.replicaCount }} +{{- end }} +selector: + matchLabels: + {{- include "fuel-streams.selectorLabels" (dict "name" .name "context" .root) | nindent 4 }} + app.kubernetes.io/component: {{ .component }} +{{- end }} + +{{/* +Configure service account for pod +Parameters: + - root: Root context object containing serviceAccount configuration +Returns: serviceAccountName if serviceAccount creation is enabled +*/}} +{{- define "k8s.pod-config.serviceAccount" -}} +{{- if .root.Values.serviceAccount.create }} +serviceAccountName: {{ include "fuel-streams.serviceAccountName" .root }} +{{- end }} +{{- end }} + +{{/* +Configure image pull secrets for pod +Parameters: + - root: Root context object for fallback values + - context: Service-specific context object containing configuration +Returns: imagePullSecrets configuration if specified +*/}} +{{- define "k8s.pod-config.imagePullSecrets" -}} +{{ include "set-field-and-value" (dict "root" .root "context" .context "field" "imagePullSecrets") -}} +{{- end }} + +{{/* +Configure node selector for pod scheduling +Parameters: + - root: Root context object for fallback values + - context: Service-specific context object containing configuration +Returns: nodeSelector configuration if specified +*/}} +{{- define "k8s.pod-config.nodeSelector" -}} +{{ include "set-field-and-value" (dict "root" .root "context" .context "field" "nodeSelector") -}} +{{- end }} + +{{/* +Configure pod tolerations +Parameters: + - root: Root context object for fallback values + - context: Service-specific context object containing configuration +Returns: tolerations configuration if specified +*/}} +{{- define "k8s.pod-config.tolerations" -}} +{{ include "set-field-and-value" (dict "root" .root "context" .context "field" "tolerations") -}} +{{- end }} + +{{/* +Configure pod security context +Parameters: + - root: Root context object for fallback values + - context: Service-specific context object containing configuration +Returns: securityContext configuration from config.podSecurityContext if specified +*/}} +{{- define "k8s.pod-config.securityContext" -}} +{{ include "set-field-and-value" (dict "root" .root "context" .context "field" "securityContext" "path" "config.podSecurityContext") -}} +{{- end }} + +{{/* +Configure pod-level settings including security, scheduling and image pull configuration +Parameters: + - root: Root context object for fallback values + - context: Service-specific context object containing configuration +Returns: YAML configuration for pod-level settings +*/}} +{{- define "k8s.pod-config" -}} +{{ include "k8s.pod-config.serviceAccount" (dict "root" .root "context" .context) }} +{{ include "k8s.pod-config.imagePullSecrets" (dict "root" .root "context" .context) }} +{{ include "k8s.pod-config.nodeSelector" (dict "root" .root "context" .context) }} +{{ include "k8s.pod-config.tolerations" (dict "root" .root "context" .context) }} +{{ include "k8s.pod-config.securityContext" (dict "root" .root "context" .context) }} +{{- end }} \ No newline at end of file diff --git a/cluster/charts/fuel-streams/templates/_blocks-resource.tpl b/cluster/charts/fuel-streams/templates/_blocks-resource.tpl new file mode 100644 index 00000000..436dff68 --- /dev/null +++ b/cluster/charts/fuel-streams/templates/_blocks-resource.tpl @@ -0,0 +1,53 @@ +{{/* +Configure resource annotations +Parameters: + - root: Root context object for fallback values + - context: Service-specific context object containing configuration +Returns: Annotations from config.annotations +*/}} +{{- define "k8s.resource-metadata.annotations" -}} +{{- include "set-value" (dict "root" .root "context" .context "path" "config.annotations") }} +{{- end }} + +{{/* +Configure resource labels +Parameters: + - root: Root context object for fallback values + - context: Service-specific context object containing configuration + - name: Name of the service for labels + - component: Optional component name for labels +Returns: Labels including common labels, custom labels from config.labels, and component if specified +*/}} +{{- define "k8s.resource-metadata.labels" -}} +{{- include "fuel-streams.labels" (dict "name" .name "context" .root) }} +{{- include "set-value" (dict "root" .root "context" .context "path" "config.labels") }} +{{- if .component }} +app.kubernetes.io/component: {{ .component }} +{{- end }} +{{- end }} + +{{/* +Configure resource metadata including name, namespace, labels and annotations +Parameters: + - context: Root context object containing Release and Chart info + - name: Name to use for the resource + - suffix: Optional suffix to append to resource name + - component: Optional component name for labels + - noAnnotations: If true, skip adding annotations +Returns: Complete resource metadata configuration +*/}} +{{- define "k8s.resource-metadata" -}} +{{- $fullname := include "fuel-streams.fullname" .root -}} +{{- $name := printf "%s-%s" $fullname .name -}} +{{- $noAnnotations := .noAnnotations | default false -}} +name: {{ $name }} +namespace: {{ .root.Release.Namespace }} +app: {{ .root.Chart.Name }} +labels: + {{- include "k8s.resource-metadata.labels" (dict "root" .root "context" .context "name" .name "component" .component) | nindent 2 -}} +{{ $annotations := include "k8s.resource-metadata.annotations" (dict "root" .root "context" .context) }} +{{ if and $annotations (not $noAnnotations) }} +annotations: + {{- $annotations | nindent 2 }} +{{- end }} +{{- end }} diff --git a/cluster/charts/fuel-streams/templates/_blocks-template.tpl b/cluster/charts/fuel-streams/templates/_blocks-template.tpl new file mode 100644 index 00000000..d405c793 --- /dev/null +++ b/cluster/charts/fuel-streams/templates/_blocks-template.tpl @@ -0,0 +1,49 @@ + +{{/* +Configure pod template metadata including annotations and labels +Parameters: + - root: Root context object for fallback values + - context: Service-specific context object containing configuration + - name: Name of the service for labels + - component: Optional component name for labels +Returns: YAML configuration for pod template metadata +*/}} +{{- define "k8s.template-labels" -}} +{{- $component := .component | default .name }} +{{- include "fuel-streams.labels" (dict "name" .name "context" .root) }} +{{- include "set-value" (dict "root" .root "context" .context "path" "config.labels") }} +{{- if $component }} +app.kubernetes.io/component: {{ $component }} +{{- end }} +{{- end }} + +{{/* +Configure pod template metadata including annotations and labels +Parameters: + - root: Root context object for fallback values + - context: Service-specific context object containing configuration + - name: Name of the service for labels +Returns: YAML configuration for pod template metadata +*/}} +{{- define "k8s.template-annotations" -}} +{{- include "set-field-and-value" (dict "root" .root "context" .context "field" "annotations" "path" "config.podAnnotations") }} +{{- end }} + +{{/* +Configure pod template metadata including annotations and labels + +Parameters: + - root: Root context object for fallback values + - context: Service-specific context object containing configuration + - component: Optional component name for labels + - name: Name of the service for labels +Returns: YAML configuration for pod template metadata including: + - Annotations from config.podAnnotations + - Labels from k8s.template-labels helper +*/}} +{{- define "k8s.template-metadata" -}} +metadata: + {{- include "k8s.template-annotations" (dict "root" .root "context" .context) | nindent 2 }} + labels: + {{- include "k8s.template-labels" (dict "root" .root "context" .context "component" .component "name" .name) | nindent 4 }} +{{- end }} \ No newline at end of file diff --git a/cluster/charts/fuel-streams/templates/_blocks.tpl b/cluster/charts/fuel-streams/templates/_blocks.tpl deleted file mode 100644 index 2f373d57..00000000 --- a/cluster/charts/fuel-streams/templates/_blocks.tpl +++ /dev/null @@ -1,184 +0,0 @@ -{{/* -Configure nats accounts -*/}} -{{- define "nats-accounts" -}} -data: - auth.conf: | - accounts { - SYS: { - users: [ - {user: $NATS_SYSTEM_USER, password: $NATS_SYSTEM_PASS} - ] - } - ADMIN: { - jetstream: enabled - users: [ - {user: $NATS_ADMIN_USER, password: $NATS_ADMIN_PASS} - ] - } - } -{{- end }} - -{{- define "k8s.default-affinity" -}} -podAntiAffinity: - preferredDuringSchedulingIgnoredDuringExecution: - - weight: 100 - podAffinityTerm: - labelSelector: - matchLabels: - app.kubernetes.io/component: publisher - topologyKey: topology.kubernetes.io/zone -{{- end }} - -{{/* -Configure basic Kubernetes resource metadata fields. -Parameters: - - context: The context (.) - - suffix: Optional suffix to append to resource name - - name: Optional name override -*/}} -{{- define "k8s.metadata" -}} -name: {{ default (include "fuel-streams.fullname" .context) .name }}{{ .suffix }} -namespace: {{ .context.Release.Namespace }} -app: {{ .context.Chart.Name }} -{{- end }} - -{{/* -Configure resource header including replicas and selector labels -*/}} -{{- define "k8s.resource-metadata" -}} -{{- $suffix := printf "-%s" .name -}} -{{- $component := .component | default .name }} -{{- include "k8s.metadata" (dict "context" .root "suffix" $suffix) }} -labels: - {{- include "fuel-streams.labels" (dict "name" .name "context" .root) | nindent 2 }} - {{- include "set-value" (dict "root" .root "context" .context "path" "config.labels") | nindent 2 -}} - app.kubernetes.io/component: {{ $component }} -{{- if not .noAnnotations -}} -{{- include "set-field-and-value" (dict "root" .root "context" .context "field" "annotations" "path" "config.annotations") }} -{{- end }} -{{- end }} - -{{/* -Configure resource annotations -*/}} -{{- define "k8s.resource-annotations" -}} -{{- include "set-value" (dict "root" .root "context" .context "path" "config.annotations") }} -{{- end }} - -{{/* -Configure pod spec header including replicas and selector labels -Parameters: - - root: Root context object for fallback values - - context: Service-specific context object containing configuration - - name: Name of the service for selector labels -Returns: YAML configuration for pod spec header -*/}} -{{- define "k8s.pod-spec-common" -}} -{{- if not .context.autoscaling.enabled }} -replicas: {{ .context.config.replicaCount }} -{{- end }} -selector: - matchLabels: - {{- include "fuel-streams.selectorLabels" (dict "name" .name "context" .root) | nindent 4 }} -{{- end }} - -{{/* -Configure pod template metadata including annotations and labels -Parameters: - - root: Root context object for fallback values - - context: Service-specific context object containing configuration - - name: Name of the service for labels -Returns: YAML configuration for pod template metadata -*/}} -{{- define "k8s.template-labels" -}} -{{- $component := .component | default .name }} -{{- include "fuel-streams.labels" (dict "name" .name "context" .root) }} -{{- include "set-value" (dict "root" .root "context" .context "path" "config.labels") }} -app.kubernetes.io/component: {{ $component }} -{{- end }} - -{{/* -Configure pod template metadata including annotations and labels -Parameters: - - root: Root context object for fallback values - - context: Service-specific context object containing configuration - - name: Name of the service for labels -Returns: YAML configuration for pod template metadata -*/}} -{{- define "k8s.template-annotations" -}} -{{- include "set-value" (dict "root" .root "context" .context "path" "config.podAnnotations") }} -{{- end }} - -{{- define "k8s.template-metadata" -}} -metadata: - {{- include "set-field-and-value" (dict "root" .root "context" .context "field" "annotations" "path" "config.podAnnotations") | nindent 4 }} - labels: - {{- include "k8s.template-labels" (dict "root" .root "context" .context) | nindent 4 }} -{{- end }} - -{{/* -Configure pod-level settings including security, scheduling and image pull configuration -Parameters: - - root: Root context object for fallback values - - context: Service-specific context object containing configuration -Returns: YAML configuration for pod-level settings -*/}} -{{- define "k8s.pod-config" -}} -{{- if .root.Values.serviceAccount.create }} -serviceAccountName: {{ include "fuel-streams.serviceAccountName" .root }} -{{- end }} - -{{- include "set-field-and-value" (dict "root" .root "context" .context "field" "imagePullSecrets") }} -{{- include "set-field-and-value" (dict "root" .root "context" .context "field" "nodeSelector") }} -{{- include "set-field-and-value" (dict "root" .root "context" .context "field" "affinity") }} -{{- include "set-field-and-value" (dict "root" .root "context" .context "field" "tolerations") }} -{{- include "set-field-and-value" (dict "root" .root "context" .context "field" "securityContext" "path" "config.podSecurityContext") }} -{{- end }} - -{{/* -Configure container-level settings including resource requests, security context, and probes -Parameters: - - root: Root context object for fallback values - - context: Service-specific context object containing configuration -Returns: YAML configuration for container-level settings -*/}} -{{- define "k8s.container-config" -}} -{{- include "set-field-and-value" (dict "root" .root "context" .context "field" "resources") }} -{{- include "set-field-and-value" (dict "root" .root "context" .context "field" "securityContext" "path" "config.containerSecurityContext") }} - -{{- if .root.Values.config.healthChecks }} -{{- include "set-field-and-value" (dict "root" .root "context" .context "field" "livenessProbe") }} -{{- include "set-field-and-value" (dict "root" .root "context" .context "field" "readinessProbe") }} -{{- include "set-field-and-value" (dict "root" .root "context" .context "field" "startupProbe") }} -{{- end }} - -ports: - - name: server - containerPort: {{ .context.port }} - protocol: TCP - {{- with .context.ports }} - {{- toYaml . | nindent 2 }} - {{- end }} - -env: - {{- if .context.port }} - - name: PORT - value: {{ .context.port | quote }} - {{- end }} - {{- range $key, $value := .context.env }} - - name: {{ $key }} - value: {{ $value | quote }} - {{- end }} - -envFrom: -- configMapRef: - name: {{ include "fuel-streams.fullname" .root }}-config - optional: true -- secretRef: - name: {{ include "fuel-streams.fullname" .root }}-keys - optional: true -{{- with .context.envFrom }} -{{- toYaml . | nindent 0 }} -{{- end }} -{{- end }} diff --git a/cluster/charts/fuel-streams/templates/_hpa.yaml b/cluster/charts/fuel-streams/templates/_hpa.yaml index 47b47c9e..91bf9a0d 100644 --- a/cluster/charts/fuel-streams/templates/_hpa.yaml +++ b/cluster/charts/fuel-streams/templates/_hpa.yaml @@ -1,19 +1,20 @@ {{- define "k8s.hpa" -}} -{{- $root := .context -}} -{{- $service := .service -}} -{{- $autoscaling := $service.autoscaling -}} -{{- $name := $service.name -}} +{{- $root := .root -}} +{{- $context := .context -}} +{{- $name := .name -}} +{{- $component := .component -}} +{{- $autoscaling := .autoscaling -}} {{- if $autoscaling.enabled }} --- apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler metadata: - {{- include "k8s.resource-metadata" (dict "root" $root "context" $service.context "name" $name) | nindent 2 }} + {{- include "k8s.resource-metadata" (dict "root" $root "context" $context "name" $name "component" $component) | nindent 2 }} spec: scaleTargetRef: apiVersion: apps/v1 kind: Deployment - name: {{ include "fuel-streams.fullname" $root }}-{{ $service.name }} + name: {{ include "fuel-streams.fullname" $root }}-{{ $name }} minReplicas: {{ $autoscaling.minReplicas }} maxReplicas: {{ $autoscaling.maxReplicas }} behavior: diff --git a/cluster/charts/fuel-streams/templates/common-config.yaml b/cluster/charts/fuel-streams/templates/common-config.yaml index 89018682..d59273a1 100644 --- a/cluster/charts/fuel-streams/templates/common-config.yaml +++ b/cluster/charts/fuel-streams/templates/common-config.yaml @@ -1,20 +1,22 @@ +{{- $localSecrets := .Values.localSecrets }} +{{- $configMap := .Values.commonConfigMap }} +{{- $configMapDict := dict "root" . "context" $configMap "name" "config" "component" "config" -}} +{{- $localSecretsDict := dict "root" . "context" $localSecrets "name" "keys" "component" "config" -}} {{- if .Values.commonConfigMap.enabled }} -{{- $commonConfigMap := .Values.commonConfigMap }} --- apiVersion: v1 kind: ConfigMap metadata: - {{- include "k8s.resource-metadata" (dict "root" . "context" $commonConfigMap "name" "config") | nindent 2 }} + {{- include "k8s.resource-metadata" $configMapDict | nindent 2 }} data: - {{ $commonConfigMap.data | toYaml | nindent 2 }} + {{ $configMap.data | toYaml | nindent 2 }} {{- end }} {{- if .Values.localSecrets.enabled }} -{{- $localSecrets := .Values.localSecrets }} --- apiVersion: v1 kind: Secret metadata: - {{- include "k8s.resource-metadata" (dict "root" . "context" $localSecrets "name" "keys" "component" "common") | nindent 2 }} + {{- include "k8s.resource-metadata" $localSecretsDict | nindent 2 }} stringData: {{ $localSecrets.data | toYaml | nindent 2 }} {{- end }} diff --git a/cluster/charts/fuel-streams/templates/consumer/deployment.yaml b/cluster/charts/fuel-streams/templates/consumer/deployment.yaml index a002d8fa..6ae30c67 100644 --- a/cluster/charts/fuel-streams/templates/consumer/deployment.yaml +++ b/cluster/charts/fuel-streams/templates/consumer/deployment.yaml @@ -1,19 +1,21 @@ {{- $consumer := .Values.consumer -}} +{{- $name := "consumer" -}} +{{- $component := "consumer" -}} +{{- $serviceDict := dict "root" . "context" $consumer "name" $name "component" $component -}} {{- if $consumer.enabled -}} apiVersion: apps/v1 kind: Deployment metadata: - {{- include "k8s.resource-metadata" (dict "root" . "context" $consumer "name" "consumer") | nindent 2 }} + {{- include "k8s.resource-metadata" $serviceDict | nindent 2 }} spec: - {{- include "k8s.pod-spec-common" (dict "root" . "context" $consumer "name" "consumer") | nindent 2 }} + {{- include "k8s.pod-spec" $serviceDict | nindent 2 }} template: - {{- include "k8s.template-metadata" (dict "root" . "context" $consumer "name" "consumer") | nindent 4 }} + {{- include "k8s.template-metadata" $serviceDict | nindent 4 }} spec: - {{- include "k8s.pod-config" (dict "root" . "context" $consumer) | nindent 6 }} + {{- include "k8s.pod-config" $serviceDict | nindent 6 }} containers: - name: consumer - image: "{{ $consumer.image.repository }}:{{ $consumer.image.tag | default .Chart.AppVersion }}" - imagePullPolicy: {{ $consumer.image.pullPolicy }} + {{ include "k8s.container-config.image" $serviceDict | nindent 10 }} command: ["/usr/src/sv-consumer"] args: - "--nats-url" @@ -21,6 +23,6 @@ spec: {{- with $consumer.image.args }} {{- toYaml . | nindent 10 }} {{- end }} - {{- include "k8s.container-config" (dict "root" . "context" $consumer) | nindent 10 }} -{{- include "k8s.hpa" (dict "context" . "service" (dict "context" $consumer "name" "consumer" "autoscaling" $consumer.autoscaling)) }} -{{- end }} \ No newline at end of file + {{ include "k8s.container-config" $serviceDict | nindent 10 }} +{{ include "k8s.hpa" (merge $serviceDict (dict "autoscaling" $consumer.autoscaling)) }} +{{- end }} diff --git a/cluster/charts/fuel-streams/templates/publisher/statefulset.yaml b/cluster/charts/fuel-streams/templates/publisher/statefulset.yaml index 83a224e4..08314641 100644 --- a/cluster/charts/fuel-streams/templates/publisher/statefulset.yaml +++ b/cluster/charts/fuel-streams/templates/publisher/statefulset.yaml @@ -1,23 +1,24 @@ {{- if .Values.publisher.enabled -}} {{- $publisher := .Values.publisher -}} +{{- $name := "publisher" -}} +{{- $component := "publisher" -}} +{{- $serviceDict := dict "root" . "context" $publisher "name" $name "component" $component -}} apiVersion: apps/v1 kind: StatefulSet metadata: - {{- include "k8s.resource-metadata" (dict "root" . "context" $publisher "name" "publisher") | nindent 2 }} + {{- include "k8s.resource-metadata" $serviceDict | nindent 2 }} spec: serviceName: {{ include "fuel-streams.fullname" . }}-publisher - {{- include "k8s.pod-spec-common" (dict "root" . "context" $publisher "name" "publisher") | nindent 2 }} + {{- include "k8s.pod-spec" $serviceDict | nindent 2 }} template: - {{- include "k8s.template-metadata" (dict "root" . "context" $publisher "name" "publisher") | nindent 4 }} + {{- include "k8s.template-metadata" $serviceDict | nindent 4 }} spec: - {{- include "k8s.pod-config" (dict "root" . "context" $publisher) | nindent 6 }} - + {{- include "k8s.pod-config" $serviceDict | nindent 6 }} volumes: - name: tmp-dir emptyDir: {} - name: var-dir emptyDir: {} - initContainers: - name: update-{{ $publisher.storage.name }} image: alpine:latest @@ -30,10 +31,10 @@ spec: mkdir -p {{ $publisher.storage.mountPath }} && \ touch {{ $publisher.storage.mountPath }}/.init-complete && \ rm {{ $publisher.storage.mountPath }}/.init-complete - {{- include "set-field-and-value" (dict "root" . "context" .context "field" "securityContext" "path" "config.containerSecurityContext") | nindent 10 }} volumeMounts: - name: {{ $publisher.storage.name }} mountPath: {{ $publisher.storage.mountPath }} + {{- include "k8s.container-config.securityContext" $serviceDict | nindent 10 }} - name: init-permissions image: alpine:latest @@ -51,8 +52,7 @@ spec: containers: - name: publisher - image: "{{ $publisher.image.repository }}:{{ $publisher.image.tag | default .Chart.AppVersion }}" - imagePullPolicy: {{ $publisher.image.pullPolicy }} + {{- include "k8s.container-config.image" $serviceDict | nindent 10 }} command: ["/usr/src/sv-publisher"] args: # Common arguments @@ -114,7 +114,7 @@ spec: - "--relayer-da-deploy-height" - "5827607" {{- end }} - {{- include "k8s.container-config" (dict "root" . "context" $publisher) | nindent 10 }} + {{- include "k8s.container-config" $serviceDict | nindent 10 }} volumeMounts: - name: {{ $publisher.storage.name }} mountPath: {{ $publisher.storage.mountPath }} diff --git a/cluster/charts/fuel-streams/templates/service-account.yaml b/cluster/charts/fuel-streams/templates/service-account.yaml index 067324d9..13609de7 100755 --- a/cluster/charts/fuel-streams/templates/service-account.yaml +++ b/cluster/charts/fuel-streams/templates/service-account.yaml @@ -1,9 +1,11 @@ {{- $serviceAccount := .Values.serviceAccount -}} +{{- $serviceAccountDict := dict "root" . "context" $serviceAccount "name" "service-account" "component" "config" -}} +{{- $secretCreatorDict := dict "root" . "context" $serviceAccount "name" "secret-creator" "component" "config" -}} {{- if .Values.serviceAccount.create -}} apiVersion: v1 kind: ServiceAccount metadata: - {{- include "k8s.resource-metadata" (dict "root" . "context" $serviceAccount "name" "service-account") | nindent 2 }} + {{- include "k8s.resource-metadata" $serviceAccountDict | nindent 2 }} automountServiceAccountToken: {{ $serviceAccount.automount }} {{- end -}} {{- if and .Values.config.createRoles $serviceAccount.create }} @@ -11,7 +13,7 @@ automountServiceAccountToken: {{ $serviceAccount.automount }} apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: - {{- include "k8s.resource-metadata" (dict "root" . "context" $serviceAccount "name" "secret-creator") | nindent 2 }} + {{- include "k8s.resource-metadata" $secretCreatorDict | nindent 2 }} rules: - apiGroups: [""] # "" indicates the core API group resources: ["pods"] @@ -26,7 +28,7 @@ rules: apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding metadata: - {{- include "k8s.resource-metadata" (dict "root" . "context" $serviceAccount "name" "secret-creator") | nindent 2 }} + {{- include "k8s.resource-metadata" $secretCreatorDict | nindent 2 }} subjects: - kind: ServiceAccount name: {{ include "fuel-streams.serviceAccountName" . }} diff --git a/cluster/charts/fuel-streams/templates/webserver/certificate.yaml b/cluster/charts/fuel-streams/templates/webserver/certificate.yaml index cf3d37c6..076df68b 100644 --- a/cluster/charts/fuel-streams/templates/webserver/certificate.yaml +++ b/cluster/charts/fuel-streams/templates/webserver/certificate.yaml @@ -3,12 +3,15 @@ {{- $tls := $webserver.tls }} {{- $certificate := $tls.certificate }} {{- $ingress := $tls.ingress }} +{{- $name := "webserver" -}} +{{- $component := "webserver" -}} +{{- $serviceDict := dict "root" . "context" $webserver "name" $name "component" $component -}} {{- if and $webserver.enabled $service.host }} {{- if $tls.enabled }} apiVersion: cert-manager.io/v1 kind: Certificate metadata: - {{- include "k8s.resource-metadata" (dict "root" . "context" $certificate "name" "webserver-cert" "component" "webserver") | nindent 2 }} + {{- include "k8s.resource-metadata" (merge $serviceDict (dict "context" $certificate)) | nindent 2 }} spec: secretName: {{ include "fuel-streams.fullname" . }}-webserver-tls duration: {{ $certificate.duration }} @@ -23,7 +26,7 @@ spec: apiVersion: networking.k8s.io/v1 kind: Ingress metadata: - {{- include "k8s.resource-metadata" (dict "root" . "context" $ingress "name" "webserver-cert-validator" "component" "webserver" "noAnnotations" true) | nindent 2 }} + {{- include "k8s.resource-metadata" (merge $serviceDict (dict "context" $ingress "name" "webserver-cert-validator" "noAnnotations" true)) | nindent 2 -}} annotations: kubernetes.io/ingress.class: nginx nginx.ingress.kubernetes.io/proxy-body-size: "0" @@ -38,7 +41,7 @@ metadata: cert-manager.io/common-name: {{ $service.host }} cert-manager.io/cluster-issuer: {{ $certificate.issuer }} {{- end }} - {{- include "k8s.resource-annotations" (dict "root" . "context" $ingress) | nindent 4 }} + {{- include "k8s.resource-metadata.annotations" (merge $serviceDict (dict "context" $ingress)) | nindent 4 }} spec: ingressClassName: nginx {{- if $tls.enabled }} diff --git a/cluster/charts/fuel-streams/templates/webserver/deployment.yaml b/cluster/charts/fuel-streams/templates/webserver/deployment.yaml index 0b082b8c..c3d8ead0 100644 --- a/cluster/charts/fuel-streams/templates/webserver/deployment.yaml +++ b/cluster/charts/fuel-streams/templates/webserver/deployment.yaml @@ -1,39 +1,43 @@ {{- $webserver := .Values.webserver -}} {{- $tls := $webserver.tls -}} +{{- $name := "webserver" -}} +{{- $component := "webserver" -}} +{{- $serviceDict := dict "root" . "context" $webserver "name" $name "component" $component -}} {{- if $webserver.enabled -}} apiVersion: apps/v1 kind: Deployment metadata: - {{- include "k8s.resource-metadata" (dict "root" . "context" $webserver "name" "webserver" "component" "webserver") | nindent 2 }} + {{- include "k8s.resource-metadata" $serviceDict | nindent 2 }} spec: - {{- include "k8s.pod-spec-common" (dict "root" . "context" $webserver "name" "webserver") | nindent 2 }} + {{- include "k8s.pod-spec" $serviceDict | nindent 2 }} template: - {{- include "k8s.template-metadata" (dict "root" . "context" $webserver "name" "webserver") | nindent 4 }} + {{- include "k8s.template-metadata" $serviceDict | nindent 4 }} spec: - {{- include "k8s.pod-config" (dict "root" . "context" $webserver) | nindent 6 }} + {{- include "k8s.pod-config" $serviceDict | nindent 6 }} containers: - name: webserver - image: "{{ $webserver.image.repository }}:{{ $webserver.image.tag | default .Chart.AppVersion }}" - imagePullPolicy: {{ $webserver.image.pullPolicy }} - {{- include "k8s.container-config" (dict "root" . "context" $webserver) | nindent 10 }} -{{- include "k8s.hpa" (dict "context" . "service" (dict "context" $webserver "name" "webserver" "autoscaling" $webserver.autoscaling)) }} + {{- include "k8s.container-config.image" $serviceDict | nindent 10 }} + {{- include "k8s.container-config" $serviceDict | nindent 10 }} +{{- include "k8s.hpa" (merge $serviceDict (dict "autoscaling" $webserver.autoscaling)) }} {{- end }} + {{- $service := $webserver.service }} +{{- $port := $service.port -}} {{- if and $webserver.enabled $service.enabled }} --- apiVersion: v1 kind: Service metadata: - {{- include "k8s.resource-metadata" (dict "root" . "context" $service "name" "webserver" "component" "webserver") | nindent 2 }} + {{- include "k8s.resource-metadata" (merge $serviceDict (dict "context" $service)) | nindent 2 }} spec: type: ClusterIP ports: - appProtocol: tcp - name: websocket - port: {{ $service.port }} + name: {{ $name }} + port: {{ $port }} protocol: TCP - targetPort: webserver + targetPort: {{ $name }} selector: {{- include "fuel-streams.selectorLabels" (dict "name" "webserver" "context" .) | nindent 4 }} - app.kubernetes.io/component: webserver + app.kubernetes.io/component: {{ $component }} {{- end }} diff --git a/cluster/charts/fuel-streams/tests/consumer/deployment_test.yaml b/cluster/charts/fuel-streams/tests/consumer/deployment_test.yaml index b146f259..95df2ba9 100644 --- a/cluster/charts/fuel-streams/tests/consumer/deployment_test.yaml +++ b/cluster/charts/fuel-streams/tests/consumer/deployment_test.yaml @@ -29,6 +29,18 @@ tests: path: metadata.labels["app.kubernetes.io/instance"] value: RELEASE-NAME documentIndex: 0 + - equal: + path: spec.template.metadata.labels["app.kubernetes.io/name"] + value: consumer + documentIndex: 0 + - equal: + path: spec.template.metadata.labels["app.kubernetes.io/instance"] + value: RELEASE-NAME + documentIndex: 0 + - equal: + path: spec.template.metadata.labels["app.kubernetes.io/component"] + value: consumer + documentIndex: 0 - it: should set correct selector labels set: @@ -44,6 +56,37 @@ tests: app.kubernetes.io/name: consumer app.kubernetes.io/instance: RELEASE-NAME documentIndex: 0 + - isSubset: + path: spec.template.metadata.labels + content: + app.kubernetes.io/name: consumer + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/component: consumer + documentIndex: 0 + + - it: should ensure selector labels match template labels + set: + consumer.enabled: true + asserts: + - equal: + path: spec.selector.matchLabels + value: + app.kubernetes.io/name: consumer + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/component: consumer + documentIndex: 0 + - equal: + path: spec.template.metadata.labels["app.kubernetes.io/name"] + value: consumer + documentIndex: 0 + - equal: + path: spec.template.metadata.labels["app.kubernetes.io/instance"] + value: RELEASE-NAME + documentIndex: 0 + - equal: + path: spec.template.metadata.labels["app.kubernetes.io/component"] + value: consumer + documentIndex: 0 - it: should set image configuration correctly set: @@ -90,7 +133,7 @@ tests: - contains: path: spec.template.spec.containers[0].ports content: - name: server + name: consumer containerPort: 8082 protocol: TCP documentIndex: 0 diff --git a/cluster/charts/fuel-streams/tests/publisher/statefulset_test.yaml b/cluster/charts/fuel-streams/tests/publisher/statefulset_test.yaml index 50c6af4a..7589f80b 100644 --- a/cluster/charts/fuel-streams/tests/publisher/statefulset_test.yaml +++ b/cluster/charts/fuel-streams/tests/publisher/statefulset_test.yaml @@ -29,6 +29,18 @@ tests: path: metadata.labels["app.kubernetes.io/instance"] value: RELEASE-NAME documentIndex: 0 + - equal: + path: spec.template.metadata.labels["app.kubernetes.io/name"] + value: publisher + documentIndex: 0 + - equal: + path: spec.template.metadata.labels["app.kubernetes.io/instance"] + value: RELEASE-NAME + documentIndex: 0 + - equal: + path: spec.template.metadata.labels["app.kubernetes.io/component"] + value: publisher + documentIndex: 0 - it: should set correct selector labels set: @@ -44,6 +56,37 @@ tests: app.kubernetes.io/name: publisher app.kubernetes.io/instance: RELEASE-NAME documentIndex: 0 + - isSubset: + path: spec.template.metadata.labels + content: + app.kubernetes.io/name: publisher + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/component: publisher + documentIndex: 0 + + - it: should ensure selector labels match template labels + set: + publisher.enabled: true + asserts: + - equal: + path: spec.selector.matchLabels + value: + app.kubernetes.io/name: publisher + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/component: publisher + documentIndex: 0 + - equal: + path: spec.template.metadata.labels["app.kubernetes.io/name"] + value: publisher + documentIndex: 0 + - equal: + path: spec.template.metadata.labels["app.kubernetes.io/instance"] + value: RELEASE-NAME + documentIndex: 0 + - equal: + path: spec.template.metadata.labels["app.kubernetes.io/component"] + value: publisher + documentIndex: 0 - it: should set image configuration correctly set: @@ -90,7 +133,7 @@ tests: - contains: path: spec.template.spec.containers[0].ports content: - name: server + name: publisher containerPort: 8082 protocol: TCP documentIndex: 0 diff --git a/cluster/charts/fuel-streams/tests/webserver/deployment_test.yaml b/cluster/charts/fuel-streams/tests/webserver/deployment_test.yaml index e5329ce3..00dd5e92 100644 --- a/cluster/charts/fuel-streams/tests/webserver/deployment_test.yaml +++ b/cluster/charts/fuel-streams/tests/webserver/deployment_test.yaml @@ -29,6 +29,18 @@ tests: path: metadata.labels["app.kubernetes.io/instance"] value: RELEASE-NAME documentIndex: 0 + - equal: + path: spec.template.metadata.labels["app.kubernetes.io/name"] + value: webserver + documentIndex: 0 + - equal: + path: spec.template.metadata.labels["app.kubernetes.io/instance"] + value: RELEASE-NAME + documentIndex: 0 + - equal: + path: spec.template.metadata.labels["app.kubernetes.io/component"] + value: webserver + documentIndex: 0 - it: should set correct selector labels set: @@ -44,6 +56,37 @@ tests: app.kubernetes.io/name: webserver app.kubernetes.io/instance: RELEASE-NAME documentIndex: 0 + - isSubset: + path: spec.template.metadata.labels + content: + app.kubernetes.io/name: webserver + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/component: webserver + documentIndex: 0 + + - it: should ensure selector labels match template labels + set: + webserver.enabled: true + asserts: + - equal: + path: spec.selector.matchLabels + value: + app.kubernetes.io/name: webserver + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/component: webserver + documentIndex: 0 + - equal: + path: spec.template.metadata.labels["app.kubernetes.io/name"] + value: webserver + documentIndex: 0 + - equal: + path: spec.template.metadata.labels["app.kubernetes.io/instance"] + value: RELEASE-NAME + documentIndex: 0 + - equal: + path: spec.template.metadata.labels["app.kubernetes.io/component"] + value: webserver + documentIndex: 0 - it: should set image configuration correctly set: @@ -90,7 +133,7 @@ tests: - contains: path: spec.template.spec.containers[0].ports content: - name: server + name: webserver containerPort: 8082 protocol: TCP documentIndex: 0 diff --git a/cluster/charts/fuel-streams/values.yaml b/cluster/charts/fuel-streams/values.yaml index fc9c1132..1e029cce 100755 --- a/cluster/charts/fuel-streams/values.yaml +++ b/cluster/charts/fuel-streams/values.yaml @@ -22,8 +22,11 @@ config: healthChecks: true livenessProbe: - readinessProbe: {} - startupProbe: {} + enabled: true + readinessProbe: + enabled: true + startupProbe: + enabled: true # Default pod security context podSecurityContext: @@ -90,7 +93,7 @@ monitoring: # ------------------------------------------------------------------------------ publisher: - enabled: false + enabled: true network: mainnet port: 9001 ports: [] @@ -158,7 +161,7 @@ publisher: # ------------------------------------------------------------------------------ consumer: - enabled: false + enabled: true port: 9002 ports: [] @@ -211,7 +214,7 @@ consumer: # ------------------------------------------------------------------------------ webserver: - enabled: false + enabled: true network: mainnet port: 9003 ports: [] @@ -359,7 +362,7 @@ nats: spec: affinity: $tplYaml: | - {{- include "k8s.default-affinity" . | nindent 4 }} + {{- include "k8s.pod-config.affinityy" . | nindent 4 }} configMap: merge: