kuberneteshelmcd

Helmfile Postsync Hook for Handling Rollout Status

author

Ahmad Lukman Hakim

14 Agustus 2024

In this article, I wanna share about Helmfile postsync Hook. The problem is when I use Helmfile with Kustomization, the result of deployment always throws success. I don't know the exact rollout status for the new deployment. So, to handle this case, a Hook can be applied to the helmfile.yaml.

...

releases:
  - name: example-release
    chart: ./backend
    jsonPatches:
    - ./backend/deployment.yaml.gotmpl
    hooks:
      - events: ["postsync"]
        showlogs: true
        command: "sh"
        args: ["-c", "./script.sh {{`{{`}} .Release.Name {{`}}`}} {{`{{`}} .Release.Namespace {{`}}`}}"]

script.sh

#!/bin/sh

RELEASE_NAME=$1
NAMESPACE=$2

DEPLOYMENT_NAME=$(kubectl get deployment -n $NAMESPACE -l "app=$RELEASE_NAME" -o jsonpath='{.items[0].metadata.name}')

kubectl rollout status deployment/$DEPLOYMENT_NAME -n $NAMESPACE --timeout=60s

if [ $? -ne 0 ]; then
  echo "Deployment $DEPLOYMENT_NAME failed."
  exit 1
else
  echo "Deployment succeeded."
fi