Skip to content

Commit

Permalink
Always delete notification in upgradejobhook
Browse files Browse the repository at this point in the history
  • Loading branch information
haasad committed Nov 25, 2024
1 parent b241856 commit 4ea3bf0
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 29 deletions.
80 changes: 79 additions & 1 deletion component/notifications.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,85 @@ local nextChannelOverlay() =
date: futureChannelOverlays[0][0],
channel: futureChannelOverlays[0][1],
version: std.split(futureChannelOverlays[0][1], '-')[1],
} else {};
};

local createUpgradeNotification(overlay) = [
kube.ConfigMap('upgrade-notification-template') + namespace {
data: {
'upgrade.yaml': std.manifestYamlDoc(
makeConsoleNotification('pending-minor-upgrade', params.upgrade_notification.notification)
),
},
},

kube.ConfigMap('console-notification-script') {
metadata+: {
namespace: params.namespace,
},
data: {
'create-console-notification.sh': (importstr 'scripts/create-console-notification.sh'),
},
},

kube.Job('create-upgrade-notification') + namespace {
metadata+: {
annotations+: {
'argocd.argoproj.io/hook': 'PostSync',
'argocd.argoproj.io/hook-delete-policy': 'HookSucceeded'
},
},
spec+: {
template+: {
spec+: {
containers_+: {
notification: kube.Container('notification') {
image: '%(registry)s/%(repository)s:%(tag)s' % params.images.oc,
imagePullPolicy: 'Always', // needed for now to get tzdata, can be removed later
name: 'create-console-notification',
workingDir: '/export',
command: [ '/scripts/create-console-notification.sh' ],
env_+: {
'OVERLAY_DATE': overlay.date,
'OVERLAY_CHANNEL': overlay.channel,
'OVERLAY_VERSION': overlay.version,
'OVERLAY_VERSION_MINOR': std.split(overlay.version, '.')[1],
},
volumeMounts_+: {
'upgrade-notification-template': {
mountPath: 'export/template',
readOnly: true,
},
export: {
mountPath: '/export',
},
scripts: {
mountPath: '/scripts',
},
},
},
},
volumes_+: {
'upgrade-notification-template': {
configMap: {
name: 'upgrade-notification-template',
defaultMode: std.parseOctal('0550'),
},
},
export: {
emptyDir: {},
},
scripts: {
configMap: {
name: 'console-notification-script',
defaultMode: std.parseOctal('0550'),
},
},
},
},
},
},
},
];

local upgradeControllerNS = {
metadata+: {
Expand Down
15 changes: 2 additions & 13 deletions component/scripts/cleanup-upgrade-notification.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
#!/bin/bash
set -euo pipefail

echo "OVERLAY_VERSION_MINOR: $OVERLAY_VERSION_MINOR"
# NOTE(sg): We use 4.0.0 as fallback current version since we only care that
# the current minor is less than the overlay minor for no-op upgrades.
export CURRENT_VERSION=${JOB_spec_desiredVersion_version:-"4.0.0"}
CURRENT_MINOR=$(echo "$CURRENT_VERSION" | cut -d. -f2)
echo "CURRENT_MINOR: $CURRENT_MINOR (0 is expected for no-op jobs)"

if (( OVERLAY_VERSION_MINOR > CURRENT_MINOR )); then
echo "Minor upgrade still pending. Nothing to clean up."
else
echo "Deleting upgrade console notification"
kubectl delete consolenotifications upgrade
fi
echo "Deleting upgrade console notification"
kubectl delete consolenotifications pending-minor-upgrade
3 changes: 2 additions & 1 deletion component/scripts/create-console-notification.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ echo "OVERLAY_CHANNEL: $OVERLAY_CHANNEL"
echo "OVERLAY_VERSION: $OVERLAY_VERSION"
echo "OVERLAY_VERSION_MINOR: $OVERLAY_VERSION_MINOR"

export NEXT_MAINTENANCE=$(kubectl -n appuio-openshift-upgrade-controller get upgradeconfigs -oyaml | yq '[.items[].status.nextPossibleSchedules[].time | from_yaml | select(. > env(OVERLAY_DATE))][0] | tz("Europe/Zurich") | format_datetime("02.01.2006 15:04")')
NEXT_MAINTENANCE=$(kubectl -n appuio-openshift-upgrade-controller get upgradeconfigs -oyaml | yq '[.items[].status.nextPossibleSchedules[].time | from_yaml | select(. > env(OVERLAY_DATE))][0] | tz("Europe/Zurich") | format_datetime("02.01.2006 15:04")')
test -n "${NEXT_MAINTENANCE:-}" || (echo "No valid maintenance window found" && exit 1)
echo "NEXT_MAINTENANCE: $NEXT_MAINTENANCE"
export NEXT_MAINTENANCE

yq '(.. | select(tag == "!!str")) |= envsubst' template/upgrade.yaml > notification.yaml
cat notification.yaml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ data:
echo "OVERLAY_VERSION: $OVERLAY_VERSION"
echo "OVERLAY_VERSION_MINOR: $OVERLAY_VERSION_MINOR"
export NEXT_MAINTENANCE=$(kubectl -n appuio-openshift-upgrade-controller get upgradeconfigs -oyaml | yq '[.items[].status.nextPossibleSchedules[].time | from_yaml | select(. > env(OVERLAY_DATE))][0] | tz("Europe/Zurich") | format_datetime("02.01.2006 15:04")')
NEXT_MAINTENANCE=$(kubectl -n appuio-openshift-upgrade-controller get upgradeconfigs -oyaml | yq '[.items[].status.nextPossibleSchedules[].time | from_yaml | select(. > env(OVERLAY_DATE))][0] | tz("Europe/Zurich") | format_datetime("02.01.2006 15:04")')
test -n "${NEXT_MAINTENANCE:-}" || (echo "No valid maintenance window found" && exit 1)
echo "NEXT_MAINTENANCE: $NEXT_MAINTENANCE"
export NEXT_MAINTENANCE
yq '(.. | select(tag == "!!str")) |= envsubst' template/upgrade.yaml > notification.yaml
cat notification.yaml
Expand Down Expand Up @@ -125,19 +126,8 @@ data:
#!/bin/bash
set -euo pipefail
echo "OVERLAY_VERSION_MINOR: $OVERLAY_VERSION_MINOR"
# NOTE(sg): We use 4.0.0 as fallback current version since we only care that
# the current minor is less than the overlay minor for no-op upgrades.
export CURRENT_VERSION=${JOB_spec_desiredVersion_version:-"4.0.0"}
CURRENT_MINOR=$(echo "$CURRENT_VERSION" | cut -d. -f2)
echo "CURRENT_MINOR: $CURRENT_MINOR (0 is expected for no-op jobs)"
if (( OVERLAY_VERSION_MINOR > CURRENT_MINOR )); then
echo "Minor upgrade still pending. Nothing to clean up."
else
echo "Deleting upgrade console notification"
kubectl delete consolenotifications upgrade
fi
echo "Deleting upgrade console notification"
kubectl delete consolenotifications pending-minor-upgrade
kind: ConfigMap
metadata:
annotations: {}
Expand Down

0 comments on commit 4ea3bf0

Please sign in to comment.