mirror of
https://github.com/element-hq/ess-helm.git
synced 2026-11-25 19:41:33 -08:00
Harmonise the hook weights
This commit is contained in:
1 parent
4dbfd71fa2
commit
0a5502a0ff
20 files changed
+64
-59
No files matched your search
@@ -15,7 +15,7 @@ metadata:
|
||||
namespace: {{ $.Release.Namespace }}
|
||||
annotations:
|
||||
"helm.sh/hook": {{ $step }}-install,{{ $step }}-upgrade
|
||||
"helm.sh/hook-weight": "-20"
|
||||
"helm.sh/hook-weight": "{{ (eq $step "pre") | ternary -10 10 }}"
|
||||
{{- with .annotations }}
|
||||
{{- toYaml . | nindent 4 }}
|
||||
{{- end }}
|
||||
|
||||
@@ -16,7 +16,7 @@ metadata:
|
||||
{{- include "element-io.deployment-markers.labels" (dict "root" $ "context" (mustMergeOverwrite (dict "step" $step) .)) | nindent 4 }}
|
||||
annotations:
|
||||
"helm.sh/hook": {{ $step }}-install,{{ $step }}-upgrade
|
||||
"helm.sh/hook-weight": "-20"
|
||||
"helm.sh/hook-weight": "{{ (eq $step "pre") | ternary -11 9 }}"
|
||||
rules:
|
||||
{{/*
|
||||
https://kubernetes.io/docs/reference/access-authn-authz/rbac/#referring-to-resources
|
||||
|
||||
@@ -17,7 +17,7 @@ metadata:
|
||||
{{- include "element-io.deployment-markers.labels" (dict "root" $ "context" (mustMergeOverwrite (dict "step" $step) .)) | nindent 4 }}
|
||||
annotations:
|
||||
"helm.sh/hook": {{ $step }}-install,{{ $step }}-upgrade
|
||||
"helm.sh/hook-weight": "-20"
|
||||
"helm.sh/hook-weight": "{{ (eq $step "pre") | ternary -11 9 }}"
|
||||
roleRef:
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
kind: Role
|
||||
|
||||
@@ -8,10 +8,10 @@ SPDX-License-Identifier: AGPL-3.0-only
|
||||
{{- with $.Values.deploymentMarkers -}}
|
||||
{{- if .enabled -}}
|
||||
{{- if and .enabled (include "element-io.deployment-markers.markers" (dict "root" $)) -}}
|
||||
{{- include "element-io.ess-library.serviceAccount" (dict "root" $ "context" (dict "componentValues" . "nameSuffix" (printf "deployment-markers-%s" $step) "extraAnnotations" (dict "helm.sh/hook" (printf "%s-install,%s-upgrade" $step $step) "helm.sh/hook-weight" "-20"))) }}
|
||||
{{- $weight := (eq $step "pre") | ternary "-11" "9" -}}
|
||||
{{- include "element-io.ess-library.serviceAccount" (dict "root" $ "context" (dict "componentValues" . "nameSuffix" (printf "deployment-markers-%s" $step) "extraAnnotations" (dict "helm.sh/hook" (printf "%s-install,%s-upgrade" $step $step) "helm.sh/hook-weight" $weight))) }}
|
||||
---
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
@@ -15,7 +15,7 @@ metadata:
|
||||
{{- include "element-io.init-secrets.labels" (dict "root" $ "context" .) | nindent 4 }}
|
||||
annotations:
|
||||
"helm.sh/hook": pre-install,pre-upgrade
|
||||
"helm.sh/hook-weight": "-10"
|
||||
"helm.sh/hook-weight": "-11"
|
||||
rules:
|
||||
{{/*
|
||||
https://kubernetes.io/docs/reference/access-authn-authz/rbac/#referring-to-resources
|
||||
|
||||
@@ -16,7 +16,7 @@ metadata:
|
||||
{{- include "element-io.init-secrets.labels" (dict "root" $ "context" .) | nindent 4 }}
|
||||
annotations:
|
||||
"helm.sh/hook": pre-install,pre-upgrade
|
||||
"helm.sh/hook-weight": "-10"
|
||||
"helm.sh/hook-weight": "-11"
|
||||
roleRef:
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
kind: Role
|
||||
|
||||
@@ -7,8 +7,7 @@ SPDX-License-Identifier: AGPL-3.0-only
|
||||
{{- with .Values.initSecrets -}}
|
||||
{{- if .enabled -}}
|
||||
{{- if and .enabled (include "element-io.init-secrets.generated-secrets" (dict "root" $)) -}}
|
||||
{{- include "element-io.ess-library.serviceAccount" (dict "root" $ "context" (dict "componentValues" . "nameSuffix" "init-secrets" "extraAnnotations" (dict "helm.sh/hook" "pre-install,pre-upgrade" "helm.sh/hook-weight" "-10"))) }}
|
||||
{{- include "element-io.ess-library.serviceAccount" (dict "root" $ "context" (dict "componentValues" . "nameSuffix" "init-secrets" "extraAnnotations" (dict "helm.sh/hook" "pre-install,pre-upgrade" "helm.sh/hook-weight" "-11"))) }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
@@ -17,7 +17,7 @@ metadata:
|
||||
{{- include "element-io.matrix-authentication-service.labels" (dict "root" $ "context" $masContext) | nindent 4 }}
|
||||
annotations:
|
||||
"helm.sh/hook": pre-install,pre-upgrade
|
||||
"helm.sh/hook-weight": "-5"
|
||||
"helm.sh/hook-weight": "-1"
|
||||
data:
|
||||
{{- include "element-io.matrix-authentication-service.configmap-data" (dict "root" $ "context" $masContext) | nindent 2 -}}
|
||||
{{ end -}}
|
||||
|
||||
@@ -22,7 +22,7 @@ metadata:
|
||||
{{- include "element-io.matrix-authentication-service.labels" (dict "root" $ "context" $masContext) | nindent 4 }}
|
||||
annotations:
|
||||
"helm.sh/hook": pre-install,pre-upgrade
|
||||
"helm.sh/hook-weight": "-5"
|
||||
"helm.sh/hook-weight": "-1"
|
||||
type: Opaque
|
||||
data:
|
||||
{{- if .syn2mas.enabled }}
|
||||
|
||||
@@ -37,23 +37,11 @@ metadata:
|
||||
) }}
|
||||
annotations:
|
||||
{{- if .dryRun }}
|
||||
{{- /*
|
||||
Hook Weights are
|
||||
- -25 : The syn2mas dryRun job, running after MAS pod which initialized its DB
|
||||
- 0 : The deployment marker job, we want it not to update any marker if the dryRun is not completed
|
||||
*/}}
|
||||
"helm.sh/hook": post-install,post-upgrade
|
||||
"helm.sh/hook-weight": "-25"
|
||||
{{- else }}
|
||||
"helm.sh/hook": pre-install,pre-upgrade
|
||||
{{- /*
|
||||
Hook Weights are
|
||||
- -10 : The initSecret hook generating secrets used by the syn2mas job
|
||||
- -5 : The MAS & synapse secret & configMap for the hook, so that they are created before the job
|
||||
- 0 : The job itself, so that it is run after the secrets and configs are created
|
||||
*/}}
|
||||
"helm.sh/hook-weight": "0"
|
||||
{{- end }}
|
||||
"helm.sh/hook-weight": "0"
|
||||
name: {{ $.Release.Name }}-syn2mas
|
||||
namespace: {{ $.Release.Namespace }}
|
||||
spec:
|
||||
|
||||
@@ -16,13 +16,7 @@ metadata:
|
||||
{{- include "element-io.syn2mas.labels" (dict "root" $ "context" .) | nindent 4 }}
|
||||
annotations:
|
||||
"helm.sh/hook": pre-install,pre-upgrade
|
||||
{{- /*
|
||||
Hook Weights are
|
||||
- -10 : The initSecret hook generating secrets used by the syn2mas job
|
||||
- -5 : The MAS & synapse secret & configMap for the hook, so that they are created before the job
|
||||
- 0 : The job itself, so that it is run after the secrets and configs are created
|
||||
*/}}
|
||||
"helm.sh/hook-weight": "0"
|
||||
"helm.sh/hook-weight": "-1"
|
||||
rules:
|
||||
- apiGroups: [""]
|
||||
resources: ["pods"]
|
||||
|
||||
+1
-7
@@ -17,13 +17,7 @@ metadata:
|
||||
{{- include "element-io.syn2mas.labels" (dict "root" $ "context" .) | nindent 4 }}
|
||||
annotations:
|
||||
"helm.sh/hook": pre-install,pre-upgrade
|
||||
{{- /*
|
||||
Hook Weights are
|
||||
- -10 : The initSecret hook generating secrets used by the syn2mas job
|
||||
- -5 : The MAS & synapse secret & configMap for the hook, so that they are created before the job
|
||||
- 0 : The job itself, so that it is run after the secrets and configs are created
|
||||
*/}}
|
||||
"helm.sh/hook-weight": "0"
|
||||
"helm.sh/hook-weight": "-1"
|
||||
roleRef:
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
kind: Role
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ SPDX-License-Identifier: AGPL-3.0-only
|
||||
{{- with .Values.matrixAuthenticationService -}}
|
||||
{{- if and .enabled .syn2mas.enabled $.Values.synapse.enabled -}}
|
||||
{{- with .syn2mas -}}
|
||||
{{- include "element-io.ess-library.serviceAccount" (dict "root" $ "context" (dict "componentValues" . "nameSuffix" "syn2mas" "extraAnnotations" (dict "helm.sh/hook" "pre-install,pre-upgrade" "helm.sh/hook-weight" "0"))) }}
|
||||
{{- include "element-io.ess-library.serviceAccount" (dict "root" $ "context" (dict "componentValues" . "nameSuffix" "syn2mas" "extraAnnotations" (dict "helm.sh/hook" "pre-install,pre-upgrade" "helm.sh/hook-weight" "-1"))) }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
@@ -17,12 +17,6 @@ metadata:
|
||||
namespace: {{ $.Release.Namespace }}
|
||||
annotations:
|
||||
"helm.sh/hook": pre-install,pre-upgrade
|
||||
{{- /*
|
||||
Hook Weights are
|
||||
- -10 : The initSecret hook generating secrets used by the check config job
|
||||
- -5 : The synapse secret & configMap for the hook, so that they are created before the job
|
||||
- 0 : The job itself, so that it is run after the secrets and configs are created &
|
||||
*/}}
|
||||
"helm.sh/hook-weight": "0"
|
||||
{{- with .checkConfigHook.annotations }}
|
||||
{{- toYaml . | nindent 4 }}
|
||||
|
||||
@@ -16,7 +16,7 @@ metadata:
|
||||
{{- include "element-io.synapse-check-config.labels" (dict "root" $ "context" .) | nindent 4 }}
|
||||
annotations:
|
||||
"helm.sh/hook": pre-install,pre-upgrade
|
||||
"helm.sh/hook-weight": "-5"
|
||||
"helm.sh/hook-weight": "-1"
|
||||
name: {{ include "element-io.synapse.configmap-name" (dict "root" $ "context" (dict "isHook" true)) }}
|
||||
namespace: {{ $.Release.Namespace }}
|
||||
data:
|
||||
|
||||
@@ -19,7 +19,7 @@ metadata:
|
||||
namespace: {{ $.Release.Namespace }}
|
||||
annotations:
|
||||
"helm.sh/hook": pre-install,pre-upgrade
|
||||
"helm.sh/hook-weight": "-5"
|
||||
"helm.sh/hook-weight": "-1"
|
||||
{{- include "element-io.synapse.secret-data" (dict "root" $ "context" .) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
@@ -9,7 +9,7 @@ SPDX-License-Identifier: AGPL-3.0-only
|
||||
{{- if .enabled }}
|
||||
{{- with .checkConfigHook }}
|
||||
{{ if and .enabled -}}
|
||||
{{- include "element-io.ess-library.serviceAccount" (dict "root" $ "context" (dict "componentValues" . "nameSuffix" "synapse-check-config" "extraAnnotations" (dict "helm.sh/hook" "pre-install,pre-upgrade" "helm.sh/hook-weight" "0"))) }}
|
||||
{{- include "element-io.ess-library.serviceAccount" (dict "root" $ "context" (dict "componentValues" . "nameSuffix" "synapse-check-config" "extraAnnotations" (dict "helm.sh/hook" "pre-install,pre-upgrade" "helm.sh/hook-weight" "-1"))) }}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
Harmonise the hook weights and reduce the number of distinct hook weight values.
|
||||
|
||||
This should speed up installs and upgrades as now there are only 2 distinct pre-install/pre-upgrade hook weights.
|
||||
@@ -13,7 +13,6 @@ from .utils import template_id, template_to_deployable_details
|
||||
@pytest.mark.parametrize("values_file", values_files_to_test)
|
||||
@pytest.mark.asyncio_cooperative
|
||||
async def test_hook_weight_is_specified_if_manifest_is_hook(templates):
|
||||
hook_weight_by_deployable_hook = {}
|
||||
for template in templates:
|
||||
annotations = template["metadata"].get("annotations", {})
|
||||
|
||||
@@ -22,14 +21,6 @@ async def test_hook_weight_is_specified_if_manifest_is_hook(templates):
|
||||
assert "helm.sh/hook-weight" in annotations, (
|
||||
f"{template_id(template)} is a hook ({annotations['helm.sh/hook']}) but doesn't set a hook weight"
|
||||
)
|
||||
deployable_details = template_to_deployable_details(template)
|
||||
hook_id = f"{deployable_details.name}-{annotations['helm.sh/hook']}"
|
||||
if hook_id in hook_weight_by_deployable_hook:
|
||||
assert hook_weight_by_deployable_hook[hook_id] == int(annotations["helm.sh/hook-weight"]), (
|
||||
f"{template_id(template)} has a different hook weight than other manifests for the same deployable"
|
||||
)
|
||||
else:
|
||||
hook_weight_by_deployable_hook[hook_id] = int(annotations["helm.sh/hook-weight"])
|
||||
else:
|
||||
assert "helm.sh/hook-weight" not in annotations, (
|
||||
f"{template_id(template)} is not a hook but has set a hook weight"
|
||||
@@ -53,3 +44,45 @@ async def test_sets_both_install_upgrade_hooks(templates):
|
||||
assert ("pre-install" in hooks and "pre-upgrade" in hooks) or (
|
||||
"post-install" in hooks and "post-upgrade" in hooks
|
||||
), f"{template_id(template)} didn't set both the install and upgrade hook: {','.join(hooks)}"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("values_file", values_files_to_test)
|
||||
@pytest.mark.asyncio_cooperative
|
||||
async def test_hook_weights_are_well_known(templates):
|
||||
for template in templates:
|
||||
annotations = template["metadata"].get("annotations", {})
|
||||
|
||||
if "helm.sh/hook-weight" not in annotations:
|
||||
continue
|
||||
|
||||
# Manifest install order by hook weight.
|
||||
# The kind order of manifests within the same weight is not respected, despire being documented as doing so
|
||||
# - https://github.com/helm/helm/issues/12414
|
||||
# - https://github.com/helm/helm-www/pull/1520
|
||||
# As such the weights for Jobs are given below, and then weight for non-Jobs are -1
|
||||
#
|
||||
# PRE INSTALL/UPGRADE
|
||||
# -10: init secrets, pre-deployment markers
|
||||
# 0: config check, syn2mas actual migration
|
||||
#
|
||||
# NON-HOOKS
|
||||
#
|
||||
# POST INSTALL/UPGRADE
|
||||
# 0: syn2mas dry-run
|
||||
# 10: post-deployment markers
|
||||
hook_weight = int(annotations["helm.sh/hook-weight"])
|
||||
weight_adjustment = 0 if template["kind"] == "Job" else 1
|
||||
hook_weight += weight_adjustment
|
||||
assert hook_weight in [-10, 0, 10], f"{template_id(template)} had an unexpected hook weight"
|
||||
|
||||
deployable_details = template_to_deployable_details(template)
|
||||
template_name = template["metadata"]["name"]
|
||||
if deployable_details.name == "deployment-markers":
|
||||
if template_name.endswith("-pre"):
|
||||
assert hook_weight == -10, f"{template_id(template)} should have a weight of {-10 - weight_adjustment}"
|
||||
else:
|
||||
assert hook_weight == 10, f"{template_id(template)} should have a weight of {10 - weight_adjustment}"
|
||||
elif deployable_details.name == "init-secrets":
|
||||
assert hook_weight == -10, f"{template_id(template)} should have a weight of {-10 - weight_adjustment}"
|
||||
else:
|
||||
assert hook_weight == 0, f"{template_id(template)} should have a weight of {0 - weight_adjustment}"
|
||||
@@ -126,7 +126,7 @@ def generated_secrets(release_name: str, values: dict[str, Any], helm_generated_
|
||||
# We simulate the fact that it exists after initSecret
|
||||
# using the hook weight.
|
||||
# Actually it does not have any
|
||||
# but this is necessary for tests/manifests/test_configs_and_mounts_consistency.py
|
||||
# but this is necessary for tests/manifests/test_configs_consistency.py
|
||||
"helm.sh/hook-weight": "-9"
|
||||
},
|
||||
},
|
||||
@@ -171,7 +171,7 @@ def external_secrets(release_name, values):
|
||||
# We simulate the fact that it exists before the chart deployment
|
||||
# using the hook weight.
|
||||
# Actually it does not have any
|
||||
# but this is necessary for tests/manifests/test_configs_and_mounts_consistency.py
|
||||
# but this is necessary for tests/manifests/test_configs_consistency.py
|
||||
"helm.sh/hook-weight": "-100"
|
||||
},
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user