From 840510df662ee778290cf021a82c804c76abd3ee Mon Sep 17 00:00:00 2001 From: Nicolas Marcq Date: Wed, 6 Dec 2023 18:28:27 +0100 Subject: [PATCH] one shot backup --- k8s/backup.yml | 60 ++++++++++++++++ .../files/redis.operator.v1.2.4.yml | 68 +++++++++---------- 2 files changed, 94 insertions(+), 34 deletions(-) create mode 100644 k8s/backup.yml diff --git a/k8s/backup.yml b/k8s/backup.yml new file mode 100644 index 000000000..4c9562ee8 --- /dev/null +++ b/k8s/backup.yml @@ -0,0 +1,60 @@ +- name: "Execute a one shot backup of Squest" + hosts: localhost + gather_facts: true + + tasks: + - name: Generate job name + ansible.builtin.set_fact: + job_name: backup-{{ ansible_date_time.date }} + + - name: Create Job from backup cronjob + shell: "kubectl --namespace {{ squest_namespace }} create job --from=cronjob/squest-backup {{ job_name }}" + environment: + KUBECONFIG: "{{ k8s_kubeconfig_path }}" + register: register_backup + failed_when: + - register_backup.rc != 0 + - '"already exists" not in register_backup.stdout' + + - name: Wait until backup complete + kubernetes.core.k8s_info: + kubeconfig: "{{ k8s_kubeconfig_path }}" + api_version: "batch/v1" + kind: Job + name: "{{ job_name }}" + namespace: "{{ squest_namespace }}" + wait: yes + wait_sleep: 10 + wait_timeout: 120 + wait_condition: + type: Complete + status: "True" + + - when: squest_django.externalize_backup_via_rsync.enabled + block: + - name: Generate job name + ansible.builtin.set_fact: + job_name: rsync-backup-{{ ansible_date_time.date }} + + - name: Create Job from rsync backup cronjob + shell: "kubectl --namespace {{ squest_namespace }} create job --from=cronjob/squest-rsync-backup {{ job_name }}" + environment: + KUBECONFIG: "{{ k8s_kubeconfig_path }}" + register: register_backup + failed_when: + - register_backup.rc != 0 + - '"already exists" not in register_backup.stdout' + + - name: Wait until rsync backup complete + kubernetes.core.k8s_info: + kubeconfig: "{{ k8s_kubeconfig_path }}" + api_version: "batch/v1" + kind: Job + name: "{{ job_name }}" + namespace: "{{ squest_namespace }}" + wait: yes + wait_sleep: 10 + wait_timeout: 120 + wait_condition: + type: Complete + status: "True" diff --git a/k8s/squest_k8s/files/redis.operator.v1.2.4.yml b/k8s/squest_k8s/files/redis.operator.v1.2.4.yml index ca6d125c4..551da6caa 100644 --- a/k8s/squest_k8s/files/redis.operator.v1.2.4.yml +++ b/k8s/squest_k8s/files/redis.operator.v1.2.4.yml @@ -143,37 +143,37 @@ spec: app: redisoperator --- -#apiVersion: monitoring.coreos.com/v1 -#kind: ServiceMonitor -#metadata: -# name: redis-operator-metrics -# namespace: redis-operator -# labels: -# app: redisoperator -# release: prometheus -#spec: -# selector: -# matchLabels: -# app: redisoperator -# endpoints: -# - port: metrics -# namespaceSelector: -# matchNames: -# - redis-operator -#--- -# -# -#apiVersion: monitoring.coreos.com/v1 -#kind: PodMonitor -#metadata: -# name: redisoperator -# namespace: redis-operator -# labels: -# app: redisoperator -# release: prometheus -#spec: -# selector: -# matchLabels: -# app: redisoperator -# podMetricsEndpoints: -# - port: metrics +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + name: redis-operator-metrics + namespace: redis-operator + labels: + app: redisoperator + release: prometheus +spec: + selector: + matchLabels: + app: redisoperator + endpoints: + - port: metrics + namespaceSelector: + matchNames: + - redis-operator +--- + + +apiVersion: monitoring.coreos.com/v1 +kind: PodMonitor +metadata: + name: redisoperator + namespace: redis-operator + labels: + app: redisoperator + release: prometheus +spec: + selector: + matchLabels: + app: redisoperator + podMetricsEndpoints: + - port: metrics