Additional hooks

Use this section to understand the additional hooks and guidelines on how to create additional hooks.

The following newly added additional hooks in the IBM Fusion recipe improve its ability to perform application backup and restore operations.

Job hook

A job hook supports to run custom operations during specific events, such as backups, restores or other workflows. It provides a flexible way to run long-running commands, provide dedicated environments for tasks, or perform batch processing and one-time tasks.

Note: Make sure that you use job string format either JSON or YAML.
Sample JobHook: JobSpec as YAML string:
hooks:
    - jobs:
        - forceCreate: true
          name: my-job1
          onError: fail
          timeout: 60
          inverseOp: ""
      name: job-hook-test1
      namespace: workload
      onError: fail
      timeout: 60
      type: job
  jobs:
    - my-job1: |
        apiVersion: batch/v1
        kind: Job 
        metadata:
          name: sample-job
          labels:
            label-key1: value1
          annotations:
            annotation-key1: value2
        spec:
          template:
            spec:
              containers:
              - command:
                - perl
                - --version
                image: perl:5.34.0
                name: perl-version
              restartPolicy: Never
Sample JobHook: JobSpec as JSON string:
hooks:
    - jobs:
        - forceCreate: true
          name: my-job1
          onError: fail
          timeout: 60
          inverseOp: ""
      name: job-hook-test1
      namespace: workload
      onError: fail
      timeout: 60
      type: job
  jobs:
    - my-job1: |
            {
              "apiVersion": "batch/v1",
              "kind": "Job",
              "metadata": {
                "name": "sample-job",
                "labels": {
                  "label-key1": "value1"
                },
                "annotations": {
                  "annotation-key1": "value2"
                }
              },
              "spec": {
                "template": {
                  "spec": {
                    "containers": [
                      {
                        "command": [
                          "perl",
                          "--version"
                        ],
                        "image": "perl:5.34.0",
                        "name": "perl-version"
                      }
                    ],
                    "restartPolicy": "Never"
                  }
                }
              }
            }
The default fields for creating a job hook:
  • Job hook jobs forceCreate: defaults to false
  • Job hook jobs timeout: if not present, defaults to job hook timeout
  • Job hook jobs onError: defaults to fail
  • Job hook timeout: defaults to 864000 seconds
  • Job string name: defaults to job hook job name
  • Job string namespace: defaults to job hook namespace
  • Job string apiVersion: defaults to batch/v1
  • Job string kind: defaults to Job
  • Job string missing backoffLimit value: defaults to 0

Label hook

A label hook modifies a resource by applying a new label or removing an existing one.

Sample LabelHook:
 hooks:
    - name: add-labels
      nameSelector: filebrowser*
      namespace: workload
      onError: fail
      timeout: 60
      ops:
        - labels: for-backup=true,myapp.io/app-name=filebrowser                # add labels
          name: filebrowser-resources-add-labels
          onError: fail
          overwrite: true
          timeout: 60
          inverseOp: filebrowser-resources-remove-labels   
        - labels: for-backup-,myapp.io/app-name-                               # remove labels
          name: filebrowser-resources-remove-labels
          onError: fail
          overwrite: true
          timeout: 60
      selectResource: pod
      type: label
The default fields for creating a label hook:
  • Ops timeout: defaults to label hook timeout
  • Ops onError: defaults to fail
  • Ops overwrite: defaults to false
  • Label hook timeout: defaults to 864000 seconds
  • Label hook onError: defaults to fail

Annotation hook

An annotation hook modifies a resource by applying a new annotation or removing an existing one.

Sample AnnotationHook:
hooks:
    - labelSelector: app=fb
      name: add-annotations
      namespace: workload
      onError: fail
      timeout: 60
      ops:
        - annotations: for-backup=true,myapp.io/app-name=filebrowser-workload         # add annotations
          name: filebrowser-resources-add-annotations
          onError: fail
          overwrite: true
          timeout: 60
          inverseOp: filebrowser-resources-remove-annotations
        - annotations: for-backup-,myapp.io/app-name-                                 # remove annotations
          name: filebrowser-resources-remove-annotations
          onError: fail
          overwrite: true
          timeout: 60
      selectResource: pod
      type: annotation
The default fields for creating an annotation hook:
  • Ops timeout: defaults to annotation hook timeout
  • Ops onError: defaults to fail
  • Ops overwrite: defaults to false
  • Annotation hook timeout: defaults to 864000 seconds
  • Annotation hook onError: defaults to fail