Kanister Execution HooksΒΆ

Kanister Blueprints can be used to execute arbitrary functionality after K10 Actions.

To use a Blueprint to define an execution hook, create the Blueprint in the K10 namespace and add a reference to one of the Blueprint's actions in a Policy.

These execution hooks operate on namespaces and run after the last action in a chained Policy. For export actions, the namespace will be the source namespace. For restore actions, the namespace will be the target namespace. A hook Blueprint can use this namespace via template parameters like {{ .Namespace.Name }}.

For example, the following Blueprint defines a hook which updates a label on the namespace that was snapshotted.

apiVersion: cr.kanister.io/v1alpha1
kind: Blueprint
metadata:
  name: hook-blueprint
  namespace: kasten-io
actions:
  post-export:
    kind: Namespace
    phases:
    - func: KubeTask
      name: hookPhase
      args:
        podOverride:
          serviceAccountName: "k10-k10"
        image: bitnami/kubectl
        command:
        - /bin/sh
        - -c
        - kubectl patch namespace "{{ .Namespace.Name }}" --type json -p='[{"op": "remove", "path": "/metadata/labels/migrate"}]'

A hook reference may include onSuccess, onFailure, or both. For example, the following hook reference specifies an execution hook for both the error and non-error cases:

...
hooks:
  onSuccess:
    blueprint: hook-blueprint
    actionName: post-export
  onFailure:
    blueprint: hook-blueprint
    actionName: post-export-failed
...

Look here to see how to embed hook references in API objects.