diff --git a/tasks/longhorn.yml b/tasks/longhorn.yml index 7bac9ee..9e468bb 100644 --- a/tasks/longhorn.yml +++ b/tasks/longhorn.yml @@ -14,26 +14,22 @@ create_namespace: yes release_namespace: "{{ storage_longhorn.namespace }}" values: -# persistence: -# defaultClass: true + persistence: + defaultClass: true # defaultClassReplicaCount: 3 # reclaimPolicy: Delete -# recurringJobs: -# enable: true -# jobList: [ -# { -# "name":"snap", -# "task":"snapshot", -# "cron":"*/1 * * * *", -# "retain":1 -# }, -# { -# "name":"backup", -# "task":"backup", -# "cron":"*/2 * * * *", -# "retain":1 -# } -# ] + recurringJobSelector: + enable: true + jobList: '[ + { + "name":"snapshot", + "isGroup":true, + }, + { + "name":"backup-daily", + "isGroup":true, + } + ]' defaultSettings: defaultDataPath: "/var/lib/longhorn/" backupTarget: "nfs://longhorn-test-nfs-svc.default:/opt/backupstore" @@ -91,6 +87,27 @@ value: "best-effort" } + - name: Install longhorn Recurring Jobs + kubernetes.core.k8s: + state: present + context: "{{ my_context }}" + apply: true + namespace: "{{ storage_longhorn.namespace }}" + resource_definition: "{{ lookup('template', 'longhorn/longhorn/longhorn_recurringjob.yml.j2') | from_yaml }}" + with_items: + - { + name: "snapshot", + cron: "1 * * * *", + task: "snapshot", + retain: 25 + } + - { + name: "backup-daily", + cron: "0 1 * * *", + task: "backup", + retain: 8 + } + # - name: Install longhorn UI Ingress # kubernetes.core.k8s: # state: present diff --git a/templates/longhorn/longhorn_recurringjob.yml.j2 b/templates/longhorn/longhorn_recurringjob.yml.j2 new file mode 100644 index 0000000..2162ede --- /dev/null +++ b/templates/longhorn/longhorn_recurringjob.yml.j2 @@ -0,0 +1,15 @@ +apiVersion: longhorn.io/v1beta1 +kind: RecurringJob +metadata: + name: "{{ item.name }}" + namespace: "{{ storage_longhorn.namespace }}" +spec: + cron: "{{ item.cron }}" + task: "{{ item.task }}" + groups: + - default + retain: {{ item.retain }} + concurrency: 2 +# labels: +# label/1: a +# label/2: b