Skip to content

Commit

Permalink
fix helm post hooks for MCE (#733)
Browse files Browse the repository at this point in the history
make sure the right annotations are present on the jobs and run helm with `--wait-for-jobs` to ensure the jobs successfully run to completion once

follows up on #727
  • Loading branch information
geoberle authored Oct 18, 2024
1 parent 5615ea6 commit 0c7156b
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 17 deletions.
4 changes: 2 additions & 2 deletions acm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ POLICY_HELM_REPO = https://github.com/stolostron/mce-install-kube.git

deploy:
@kubectl create namespace ${MCE_NS} --dry-run=client -o json | kubectl apply -f -
helm upgrade --install --wait \
helm upgrade --install --wait --wait-for-jobs \
mce ${MCE_CHART_DIR} \
--namespace ${MCE_NS} \
--set imageRegistry=${REGISTRY}
helm upgrade --install --wait \
helm upgrade --install --wait --wait-for-jobs \
mce-config ${MCE_CONFIG_DIR} \
--namespace ${MCE_NS}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ kind: Job
metadata:
name: patch-hypershift-addon-adc
namespace: '{{ .Release.Namespace }}'
annotations:
"helm.sh/hook": post-install,post-upgrade
"helm.sh/hook-weight": "1"
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
spec:
activeDeadlineSeconds: 1800
backoffLimit: 3
Expand All @@ -24,4 +28,3 @@ spec:
name: patch-hypershift-addon-deploy-config-adc
restartPolicy: Never
serviceAccountName: multicluster-engine-operator
ttlSecondsAfterFinished: 60
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.15.0
creationTimestamp: null
name: multiclusterengines.multicluster.openshift.io
spec:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
capabilities: Seamless Upgrades
categories: Integration & Delivery
certified: "true"
description: Foundational components for central management of multiple OpenShift Container Platform and Kubernetes clusters
support: Red Hat
creationTimestamp: null
labels:
control-plane: backplane-operator
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
apiVersion: batch/v1
kind: Job
metadata:
annotations:
helm.sh/hook: post-install,post-upgrade
helm.sh/hook-delete-policy: before-hook-creation,hook-succeeded
helm.sh/hook-weight: "1"
name: patch-work-manager-cma
namespace: '{{ .Release.Namespace }}'
spec:
Expand All @@ -23,5 +27,4 @@ spec:
image: mcr.microsoft.com/aks/command/runtime:master.240118.1
name: patch-work-manager-cma
restartPolicy: Never
serviceAccountName: cluster-manager
ttlSecondsAfterFinished: 60
serviceAccountName: multicluster-engine-operator
5 changes: 2 additions & 3 deletions acm/scaffold/patch-work-manager-cma.job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ metadata:
annotations:
"helm.sh/hook": post-install,post-upgrade
"helm.sh/hook-weight": "1"
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
spec:
# delete 1 minute after completion
ttlSecondsAfterFinished: 60
# set deadline to 30min
activeDeadlineSeconds: 1800
backoffLimit: 3
Expand All @@ -29,4 +28,4 @@ spec:
kubectl patch clustermanagementaddon work-manager --type merge -p '{"spec":{"supportedConfigs":[{"defaultConfig":{"name":"addon-hosted-config","namespace":"multicluster-engine"},"group":"addon.open-cluster-management.io","resource":"addondeploymentconfigs"}]}}'
echo "Patch applied successfully."
restartPolicy: Never
serviceAccountName: cluster-manager
serviceAccountName: multicluster-engine-operator
16 changes: 15 additions & 1 deletion tooling/mcerepkg/internal/customize/customize.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,20 @@ func parameterizeDeployment(obj unstructured.Unstructured) (unstructured.Unstruc
}

func annotationCleaner(obj unstructured.Unstructured) (unstructured.Unstructured, map[string]string, error) {
obj.SetAnnotations(nil)
annotationToScrape := []string{"openshift.io", "operatorframework.io", "olm", "alm-examples", "createdAt"}
annotations := obj.GetAnnotations()
for k := range annotations {
for _, prefix := range annotationToScrape {
if strings.Contains(k, prefix) {
delete(annotations, k)
break
}
}
}
if len(annotations) == 0 {
obj.SetAnnotations(nil)
} else {
obj.SetAnnotations(annotations)
}
return obj, nil, nil
}
43 changes: 35 additions & 8 deletions tooling/mcerepkg/internal/customize/customize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,39 @@ func TestParameterizeDeploymentImage(t *testing.T) {
}

func TestAnnotationCleaner(t *testing.T) {
obj := unstructured.Unstructured{}
obj.SetAnnotations(map[string]string{
"some-annotation": "value",
})
modifiedObj, param, err := annotationCleaner(obj)
assert.Nil(t, err)
assert.Nil(t, param)
assert.Empty(t, modifiedObj.GetAnnotations())
for _, testCase := range []struct {
name string
annotations map[string]string
expected map[string]string
}{
{
name: "only remove unwanted annotations",
annotations: map[string]string{
"openshift.io/some-annotation": "value",
"operatorframework.io/some-annotation": "value",
"olm/some-annotation": "value",
"alm-examples/some-annotation": "value",
"some-other-annotation": "value",
},
expected: map[string]string{
"some-other-annotation": "value",
},
},
{
name: "annotations are nil if none are left after cleaning",
annotations: map[string]string{
"openshift.io/some-annotation": "value",
},
expected: nil,
},
} {
t.Run(testCase.name, func(t *testing.T) {
obj := unstructured.Unstructured{}
obj.SetAnnotations(testCase.annotations)
modifiedObj, param, err := annotationCleaner(obj)
assert.Nil(t, err)
assert.Nil(t, param)
assert.Equal(t, testCase.expected, modifiedObj.GetAnnotations())
})
}
}

0 comments on commit 0c7156b

Please sign in to comment.