Assigning a Recipe

You can assign a recipe to your backup and restore operations.

  1. Assign a recipe with a backup policy assignment CR for backup and restore operations as follows:
    Assign a recipe for backup operations
    You can assign a recipe to an application or applications by specify the recipe in the PolicyAssignment CR to assign it to one or more applications. You can specify a single recipe in a PolicyAssignment CR.
    To assign a recipe to an application, you can fix the PolicyAssignment CR by using the following example:
    oc -n ibm-spectrum-fusion-ns patch policyassignment POLICY-ASSIGNMENT-NAME --type merge -p '{"spec":{"recipe":{"name":"RECIPE_NAME", "namespace":"RECIPE_NAMESPACE", "apiVersion":"spp-data-protection.isf.ibm.com/v1alpha1"}}}'
    • POLICY_ASSIGNMENT-NAME is the name as specified in the PolicyAssignment CR.
    • RECIPE_NAME is the name of the recipe as specified in the Recipe CR.
    • RECIPE_NAMESPACE is the namespace where the Recipe CR is located.
    Assign a recipe for restore operations when restoring to the original namespace
    During a restore operation, a recipe must be started with the following precedence:
    • If there is a Recipe CR with the same name and in the same namespace as the Recipe CR that was used during the backup operation, it must take precedence. It can be helpful in situations when you want to specify a different workflow or different hooks during the restore.
    • If there is no Recipe CR with the same name and in the same namespace, the recipe that was used during the backup operation must be run. This information is stored as part of the backup metadata.
    Assign a recipe for restore operations when restoring to a different namespace
    If you are restoring to an alternative namespace, any namespaces that are specified in a hook cannot be run correctly as they refer to the original namespace. If you want the hooks to run in the alternative namespace, change the Recipe CR as mentioned in Assign a recipe for restore operations when restoring to the original namespace. So that any hook namespaces are referring to the alternative namespace.
  2. Assign a recipe CR with an application CR as follows:
    Working with application CRs for single namespace
    For applications that only has a single namespace, there are no changes that are required in the application CR to support a recipe. The recipe is associated with the application, in this case with the PoliyAssignment CR, as defined in the Assign a recipe for backup operations.
    Working with application CRs for applications that span multiple namespaces
    If you have an application that spans multiple namespaces and want to use a recipe for the application, you need to specify all of the namespaces included in the application that is in the application CR.
    • Using variable substitutions:
      • Variables can be used to permit a single recipe to be used in multiple, similar applications. Variables are defined in the application CR, and any number of variables can be defined.
        - variables:
           - name: <variable name>
               value: <variable value>
      • The variables that can be referenced within the Recipe CR.
        ${<variable name>}

        Valid characters for variables are: a-zA-Z0-9_-

      • Each group exposes to the following variables automatically.
        • Effective namespaces
          These can be used within recipe by these patterns.
          ${GROUP.<groupname>.namespaces} - effective namespaces of group
          ${GROUP.<groupname>.namespace}  - effective namespace of group - single namespace enforced, (runtime) validation error otherwise
      • Variables can solely be used for the following fields:
        • Namespace field of hooks.
        • Within commands of exec hooks.
      Tip: When creating a Recipe CR, place the Recipe CR in the ibm-spectrum-fusion-ns (or another common namespace). During a restore operation, you might need to change the recipe and don’t want the recipe CR to be in the application namespace, as this namespace might not be available during restore.
      For example,
      apiVersion: application.isf.ibm.com/v1aplha1
      kind: Application
      metadata:
        name: wp-app1
        namespace: ibm-spectrum-fusion-ns
      spec:
        appType: wordpress
        includedNamespaces: 
          - wordpress
        variables: 
        - name: WORDPRESS_NAMESPACE
          value: wordpress
      ---
      
      apiVersion: spp-data-protection.isf.ibm.com/v1alpha1
      kind: Recipe
      metadata:
        name: wp-recipe
        namespace: wordpress
      spec:
        appType: wordpress
        groups:
          - name: mysql_data
            type: volume
            labelSelector: app=wordpress
          - name: frontend
            type: resource
            labelSelector: tier in (frontend),app=wordpress
          - name: backend
            type: resource
            labelSelector: tier notin (frontend)
        hooks:
        - name: demoexechook
          type: exec
          namespace: ${WORDPRESS_NAMESPACE}
          nameSelector: wordpress-mysql.*
          ops:
          - name: pre
            command: >
              ["/bin/bash", "-c", "echo 'This is pretest' > /tmp/cfg_map_pre.txt"]
            container: mysql
          - name: post
            command: >
              ["/bin/bash", "-c", "echo 'This is posttest' > /tmp/cfg_map_post.txt"]
            container: mysql
        - name: demoscalehook
          type: scale
          namespace: ${WORDPRESS_NAMESPACE}
          selectResource: statefulset
          nameSelector: wordpress$
        workflows:
        - name: backup
          sequence:
          - hook: demoscalehook/down
          - group: frontend
          - group: backend
          - hook: demoexechook/pre
          - group: mysql_data
          - hook: demoexechook/post
          - hook: demoscalehook/up
        - name: restore
          sequence:
          - group: mysql_data
          - group: backend
          - group: frontend