Home / Technology / Managing Kiali Instance Finalizers During Helm Chart Uninstallation in Kiali-Operator

Managing Kiali Instance Finalizers During Helm Chart Uninstallation in Kiali-Operator

When deploying the Kiali-operator using the Helm chart from Kiali’s GitHub repository, you might configure it to create a Kiali instance after the operator is deployed. In such cases, you may use the Custom Resource (CR) value provided in the Helm chart: Kiali-Operator Values.yaml.

However, an issue arises when you try to uninstall the Kiali-operator Helm chart. The Kiali instance will have a finalizer attached to it, which prevents its deletion. This results in the successful uninstallation of the operator, but the Kiali instance remains running in your cluster.

To resolve this, you have two options:

  1. Manually avoid using the CR object in the Helm values and create your own Kiali instance manifest. This way, you can manage the Kiali instance directly, avoiding the Helm chart’s default behavior.
  2. Automate the deletion of the Kiali instance by adding a Helm hook job that will run before the operator is uninstalled. This job will patch the Kiali instance to remove the finalizer and then delete the instance, ensuring the operator is fully removed.

Here’s how you can define a Helm hook job to handle this:

apiVersion: batch/v1
kind: Job
metadata:
  name: "delete-kiali-cr"
  namespace: "{{ .Release.Namespace }}"
  labels:
    app: "kiali-operator"
  annotations:
    "helm.sh/hook": pre-delete
    "helm.sh/hook-weight": "-1"
    "helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
spec:
  template:
    spec:
      serviceAccount: {{ include "kiali-operator.fullname" . }}
      serviceAccountName: {{ include "kiali-operator.fullname" . }}  # Use the service account defined above
      containers:
        - name: "kubectl"
          image: "bitnami/kubectl:latest"
          command:
            - "/bin/sh"
            - "-c"
            - |
              kubectl patch kiali kiali -p '{"metadata":{"finalizers":null}}' --type=merge -n "{{ .Values.cr.namespace }}"
              kubectl delete kiali kiali -n "{{ .Values.cr.namespace }}"
      restartPolicy: Never
      {{- if .Values.tolerations }}
      tolerations:
      {{- toYaml .Values.tolerations | nindent 8 }}
      {{- end }}
      {{- if .Values.nodeSelector }}
      nodeSelector:
      {{- toYaml .Values.nodeSelector | nindent 8 }}
      {{- end }}

In this post, we explore the challenges that arise when deploying the Kiali-operator with Helm and creating a Kiali instance, especially when uninstalling the operator. We’ll walk through two solutions for dealing with the Kiali instance finalizer issue and ensuring smooth removal of the operator and associated resources.