Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#44 disables adding hook annotations #45

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 2.3.1 - Apr 2, 2023
* fix: disables adding hook annotations on all configmaps and secrets by default (you can setup it when you really need it, see a note `values.yaml` in parameter `generic.hookAnnotations`):
* `helm.sh/hook: "pre-install,pre-upgrade"`
* `helm.sh/hook-weight: "-999"`
* `helm.sh/hook-delete-policy: before-hook-creation`

## 2.3.0 - Mar 07, 2023

* feature: add typed volumes via generic and workloads generals parameter `volumes`
Expand Down
2 changes: 1 addition & 1 deletion Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v2
description: Nixys universal Helm chart for deploy your apps to Kubernetes
name: universal-chart
version: 2.2.0
version: 2.3.1
maintainers:
- name: Roman Andreev
email: r.andreev@nixys.ru
Expand Down
49 changes: 49 additions & 0 deletions samples/configmap-only.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
fooValue: "123" # define a custom variable

configMaps:
sample-config:
data:
data.conf: |
worker_processes 1;
load_module modules/ngx_http_js_module.so;
config-with-annotations:
annotations:
zzz: bar
helm.sh/hook: "pre-install,pre-upgrade,post-delete" # override default annotation "helm.sh/hook"
foo: '{{ $.Values.fooValue }}' # use a render function
data:
data.conf: |
worker_processes 1;
load_module modules/ngx_http_js_module.so;

# configmap with ENVs
envs:
BAR: foo
TEST: "true"

######
## run with:
## helm template w --values ./samples/configmap-only.yml ./charts/universal-chart/. --debug
##
## result should be:
######
# apiVersion: v1
# kind: ConfigMap
# metadata:
# name: w-whoami-config
# namespace: local-path-storage
# labels:
# app.kubernetes.io/name: w
# app.kubernetes.io/instance: w
# helm.sh/chart: universal-chart-2.1.12
# app.kubernetes.io/managed-by: Helm
# annotations:
# foo: "123"
# helm.sh/hook: pre-install
# helm.sh/hook-delete-policy: before-hook-creation
# helm.sh/hook-weight: "-999"
# zzz: bar
# data:
# data.conf: |
# worker_processes 1;
# load_module modules/ngx_http_js_module.so;
53 changes: 53 additions & 0 deletions samples/configmap-without-hooks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
fooValue: "123" # define a custom variable

generic:
# disable default hook annotations for configMaps & secrets (set `nil` value)
hookAnnotations: ~

configMaps:
sample-config:
data:
data.conf: |
worker_processes 1;
load_module modules/ngx_http_js_module.so;
config-with-annotations:
annotations:
zzz: bar
helm.sh/hook: "pre-install,pre-upgrade,post-delete" # override default annotation "helm.sh/hook"
foo: '{{ $.Values.fooValue }}' # use a render function
data:
data.conf: |
worker_processes 1;
load_module modules/ngx_http_js_module.so;

# configmap with ENVs
envs:
BAR: foo
TEST: "true"

######
## run with:
## helm template w --values ./samples/configmap-only.yml ./charts/universal-chart/. --debug
##
## result should be:
######
# apiVersion: v1
# kind: ConfigMap
# metadata:
# name: w-whoami-config
# namespace: local-path-storage
# labels:
# app.kubernetes.io/name: w
# app.kubernetes.io/instance: w
# helm.sh/chart: universal-chart-2.1.12
# app.kubernetes.io/managed-by: Helm
# annotations:
# foo: "123"
# helm.sh/hook: pre-install
# helm.sh/hook-delete-policy: before-hook-creation
# helm.sh/hook-weight: "-999"
# zzz: bar
# data:
# data.conf: |
# worker_processes 1;
# load_module modules/ngx_http_js_module.so;
60 changes: 60 additions & 0 deletions samples/whoami-configmap.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
fooValue: "123" # define a custom variable

deploymentsGeneral:
enableAffinity: false # default is true

deployments:
whoami:
securityContext:
runAsUser: 1000
runAsGroup: 3000
fsGroup: 2000
containers:
- name: whoami
image: containous/whoami
imageTag: v1.5.0
resources:
limits:
cpu: 10m
memory: 128Mi
requests:
cpu: 1m
memory: 64Mi
args:
- --port
- "8080"
ports:
- name: web
containerPort: 8080
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
volumeMounts:
- name: whoami-config
mountPath: /tmp/data.conf
subPath: data.conf
volumes:
- type: configMap
name: whoami-config
items:
- key: data.conf
path: data.conf

services:
whoami-web:
type: ClusterIP
ports:
- name: web
protocol: TCP
port: 80
targetPort: 8080

configMaps:
whoami-config:
annotations:
zzz: bar
foo: '{{ $.Values.fooValue }}' # use a render function
data:
data.conf: |
worker_processes 1;
load_module modules/ngx_http_js_module.so;
10 changes: 7 additions & 3 deletions templates/configmap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ metadata:
name: {{ include "helpers.app.fullname" (dict "name" "envs" "context" $) }}
namespace: {{ .Release.Namespace | quote }}
labels: {{- include "helpers.app.labels" $ | nindent 4 }}
annotations: {{- include "helpers.app.hooksAnnotations" $ | nindent 4 }}
annotations: {{- include "helpers.app.defaultHookAnnotations" $ | nindent 4 }}
data:
{{- include "helpers.configmaps.renderConfigMap" (dict "value" .Values.envs) | indent 2 }}
{{- include "helpers.configmaps.renderConfigMap" (dict "value" .Values.envsString) | indent 2 }}
Expand All @@ -24,8 +24,12 @@ metadata:
{{- include "helpers.app.labels" $ | nindent 4 }}
{{- with $val.labels }}{{- include "helpers.tplvalues.render" (dict "value" . "context" $) | nindent 4 }}{{ end }}
annotations:
{{- include "helpers.app.hooksAnnotations" $ | nindent 4 }}
{{- with $val.annotations }}{{- include "helpers.tplvalues.render" (dict "value" . "context" $) | nindent 4 }}{{ end }}
{{- if $val.annotations }}
{{- $_ := include "helpers.tplvalues.render" (dict "value" $val.annotations "context" $) }}
{{- include "helpers.app.annotations" (dict "value" $_ "context" $) | nindent 4 -}}
{{- else }}
{{- include "helpers.app.defaultHookAnnotations" $ | nindent 4 }}
{{- end }}
data:
{{- include "helpers.tplvalues.render" ( dict "value" $val.data "context" $ ) | nindent 2 }}
{{- end -}}
Expand Down
34 changes: 28 additions & 6 deletions templates/helpers/_app.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
{{- with .Values.generic.labels }}
{{- with ((.Values).generic).labels }}
{{ include "helpers.tplvalues.render" (dict "value" . "context" $) }}
{{- end }}
{{- end }}
Expand All @@ -45,19 +45,41 @@ app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{- define "helpers.app.genericSelectorLabels" -}}
{{- with .Values.generic.extraSelectorLabels }}
{{- with ((.Values).generic).extraSelectorLabels }}
{{- include "helpers.tplvalues.render" (dict "value" . "context" .) }}
{{- end }}
{{- end }}

{{- define "helpers.app.genericAnnotations" -}}
{{- with .Values.generic.annotations }}
{{- with ((.Values).generic).annotations }}
{{ include "helpers.tplvalues.render" (dict "value" . "context" $) }}
{{- end }}
{{- end }}

{{/*
For a backward compatibility
TODO: remove it in version 3.x.x, use defaultHookAnnotations
*/}}
{{- define "helpers.app.hooksAnnotations" -}}
helm.sh/hook: "pre-install,pre-upgrade"
helm.sh/hook-weight: "-999"
helm.sh/hook-delete-policy: before-hook-creation
{{ include "helpers.app.defaultHookAnnotations" .context | fromYaml }}
{{- end }}

{{/*
Template for default hook annotations for configmaps and secrets
*/}}
{{- define "helpers.app.defaultHookAnnotations" -}}
{{- with ((.Values).generic).hookAnnotations }}
{{- include "helpers.tplvalues.render" ( dict "value" . "context" $ ) }}
{{- end }}
{{- end }}

{{/*
Merge the user defined annotations and the common hook annotations
*/}}
{{- define "helpers.app.annotations" -}}
{{- $defaultHookValues := include "helpers.app.defaultHookAnnotations" .context | fromYaml }}
{{- $genericAnnotations := include "helpers.app.genericAnnotations" .context | fromYaml }}
{{- $userValues := .value | fromYaml }}
{{- $mergedValues := mustMergeOverwrite $defaultHookValues $userValues $genericAnnotations }}
{{- $mergedValues | toYaml -}}
{{- end -}}
12 changes: 8 additions & 4 deletions templates/secret.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ metadata:
name: {{ include "helpers.app.fullname" (dict "name" "secret-envs" "context" $) }}
namespace: {{ .Release.Namespace | quote }}
labels: {{- include "helpers.app.labels" $ | nindent 4 }}
annotations: {{- include "helpers.app.hooksAnnotations" $ | nindent 4 }}
annotations: {{- include "helpers.app.defaultHookAnnotations" $ | nindent 4 }}
data:
{{- include "helpers.secrets.render" (dict "value" .Values.secretEnvsString) | indent 2 }}
{{- include "helpers.secrets.render" (dict "value" .Values.secretEnvs) | indent 2 }}
Expand All @@ -26,8 +26,12 @@ metadata:
{{- include "helpers.app.labels" $ | nindent 4 }}
{{- with $val.labels }}{{- include "helpers.tplvalues.render" (dict "value" . "context" $) | nindent 4 }}{{ end }}
annotations:
{{- include "helpers.app.hooksAnnotations" $ | nindent 4 }}
{{- with $val.annotations }}{{- include "helpers.tplvalues.render" (dict "value" . "context" $) | nindent 4 }}{{ end }}
{{- if $val.annotations }}
{{- $_ := include "helpers.tplvalues.render" (dict "value" $val.annotations "context" $) }}
{{- include "helpers.app.annotations" (dict "value" $_ "context" $) | nindent 4 -}}
{{- else }}
{{- include "helpers.app.defaultHookAnnotations" $ | nindent 4 }}
{{- end }}
data:
{{- include "helpers.secrets.render" (dict "value" $val.data) | indent 2 }}
{{- end }}
Expand All @@ -42,7 +46,7 @@ metadata:
name: {{ $name }}
namespace: {{ $.Release.Namespace | quote }}
labels: {{- include "helpers.app.labels" $ | nindent 4 }}
annotations: {{- include "helpers.app.hooksAnnotations" $ | nindent 4 }}
annotations: {{- include "helpers.app.defaultHookAnnotations" $ | nindent 4 }}
data:
{{- include "helpers.secrets.render" (dict "value" (printf ".dockerconfigjson: %v" $value)) | indent 2 }}
{{- end }}
12 changes: 12 additions & 0 deletions values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@ generic:
labels: {}
# general-label: general-label-value
annotations: {}
# default annotation that will be added to configmaps and secrets
# docs: https://helm.sh/docs/topics/charts_hooks/
# necessary this default hooks if it used in other hooks, see a note
# https://github.com/helm/helm/issues/2622#issuecomment-526519546
# but the resources with hooks currently not tracked or managed as part of the release
# i.e. configmap with helm-hooks will not removed when release has removed
# https://helm.sh/docs/topics/charts_hooks/#hook-resources-are-not-managed-with-corresponding-releases
hookAnnotations: {}
# helm.sh/hook: "pre-install,pre-upgrade"
# helm.sh/hook-weight: "-999"
# helm.sh/hook-delete-policy: before-hook-creation
# helm.sh/resource-policy: keep
# general-annotation: general-annotation-value
extraSelectorLabels: {}
# label: special
Expand Down