Skip to content

Commit

Permalink
docs: Rework OCP blueprints to separate DB tools image and kanister-t…
Browse files Browse the repository at this point in the history
…ools image

Follow up to #3284

Signed-off-by: Daniil Fedotov <[email protected]>
  • Loading branch information
hairyhum committed Dec 13, 2024
1 parent 67ba19a commit e250d70
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,39 @@ actions:
kando output etcdPod $ETCD_POD
kando output etcdNS $etcdns
- func: KubeTask
- func: MultiContainerRun
name: uploadSnapshot
args:
image: ghcr.io/kanisterio/kanister-kubectl-1.18:0.112.0
command:
sharedVolumeMedium: Memory

initImage: '{{if index .Options "kanisterImage" }} {{- .Options.kanisterImage -}} {{else -}} ghcr.io/kanisterio/kanister-tools:0.112.0 {{- end}}'
initCommand: ["bash", "-o", "errexit", "-o", "pipefail", "-c", "mkfifo /tmp/data; chmod 777 /tmp/data"]

backgroundImage: ghcr.io/kanisterio/kanister-kubectl-1.18:0.112.0
backgroundCommand:
- sh
- -o
- errexit
- -o
- pipefail
- -c
- |
BACKUP_LOCATION='etcd-backup.db.gz'
kubectl cp -c etcd {{ .Phases.takeSnapshot.Output.etcdNS }}/{{ .Phases.takeSnapshot.Output.etcdPod }}:/tmp/etcd-backup.db /tmp/etcd-backup.db
gzip -c /tmp/etcd-backup.db | kando location push --profile '{{ toJson .Profile }}' --path "${BACKUP_LOCATION}" --output-name "kopiaOutput" -
gzip -c /tmp/etcd-backup.db > /tmp/data
outputImage: '{{if index .Options "kanisterImage" }} {{- .Options.kanisterImage -}} {{else -}} ghcr.io/kanisterio/kanister-tools:0.112.0 {{- end}}'
outputCommand:
- sh
- -o
- errexit
- -o
- pipefail
- -c
- |
BACKUP_LOCATION='etcd-backup.db.gz'
cat /tmp/data | kando location push --profile '{{ toJson .Profile }}' --path "${BACKUP_LOCATION}" --output-name "kopiaOutput" -
kando output backupLocation $BACKUP_LOCATION
- func: KubeTask
name: removeSnapshot
Expand All @@ -66,14 +84,14 @@ actions:
# having label `etcd-restore`. The pod is used to download the backup file from the
# object store and copy it to the /mnt/data location of the PV mapped to PVC `pvc-etcd`.
# The PV's mount path is /mnt/data on leader node where the cluster-ocp-restore.sh
# script would be executed.
# script would be executed.
inputArtifactNames:
- etcdBackup
phases:
- func: PrepareData
name: copyFromObjectStore
args:
image: "ghcr.io/kanisterio/kanister-tools:0.112.0"
image: '{{if index .Options "kanisterImage" }} {{- .Options.kanisterImage -}} {{else -}} ghcr.io/kanisterio/kanister-tools:0.112.0 {{- end}}'
namespace: "{{ .Object.metadata.namespace }}"
podOverride:
nodeSelector:
Expand All @@ -84,7 +102,7 @@ actions:
effect: "NoSchedule"
containers:
- name: container
securityContext:
securityContext:
privileged: true
volumes:
pvc-etcd: "/mnt/data"
Expand All @@ -108,7 +126,7 @@ actions:
name: deleteFromObjectStore
args:
namespace: "{{ .Namespace.Name }}"
image: "ghcr.io/kanisterio/kanister-tools:0.112.0"
image: '{{if index .Options "kanisterImage" }} {{- .Options.kanisterImage -}} {{else -}} ghcr.io/kanisterio/kanister-tools:0.112.0 {{- end}}'
command:
- bash
- -o
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ actions:
# `kopiaOutput` is the name provided to kando using `--output-name` flag
kopiaSnapshot: "{{ .Phases.mongoDump.Output.kopiaOutput }}"
phases:
- func: KubeTask
- func: MultiContainerRun
name: mongoDump
objects:
mongosecret:
Expand All @@ -20,8 +20,13 @@ actions:
namespace: "{{ .DeploymentConfig.Namespace }}"
args:
namespace: "{{ .DeploymentConfig.Namespace }}"
image: ghcr.io/kanisterio/mongodb:0.112.0
command:
sharedVolumeMedium: Memory

initImage: '{{if index .Options "kanisterImage" }} {{- .Options.kanisterImage -}} {{else -}} ghcr.io/kanisterio/kanister-tools:0.112.0 {{- end}}'
initCommand: ["bash", "-o", "errexit", "-o", "pipefail", "-c", "mkfifo /tmp/data; chmod 777 /tmp/data"]

backgroundImage: bitnami/mongodb:7.0-debian-12
backgroundCommand:
- bash
- -o
- errexit
Expand All @@ -33,15 +38,26 @@ actions:
dbPassword='{{ index .Phases.mongoDump.Secrets.mongosecret.Data "database-admin-password" | toString }}'
dump_cmd="mongodump --gzip --archive --host ${host} -u admin -p ${dbPassword}"
echo $dump_cmd
${dump_cmd} > /tmp/data
outputImage: '{{if index .Options "kanisterImage" }} {{- .Options.kanisterImage -}} {{else -}} ghcr.io/kanisterio/kanister-tools:0.112.0 {{- end}}'
outputCommand:
- bash
- -o
- errexit
- -o
- pipefail
- -c
- |
backup_file_path='rs_backup.gz'
${dump_cmd} | kando location push --profile '{{ toJson .Profile }}' --path "${backup_file_path}" --output-name "kopiaOutput" -
cat /tmp/data | kando location push --profile '{{ toJson .Profile }}' --path "${backup_file_path}" --output-name "kopiaOutput" -
restore:
inputArtifactNames:
# The kopia snapshot info created in backup phase can be used here
# Use the `--kopia-snapshot` flag in kando to pass in `mongoBackup.KopiaSnapshot`
- mongoBackup
phases:
- func: KubeTask
- func: MultiContainerRun
name: pullFromStore
objects:
mongosecret:
Expand All @@ -50,8 +66,26 @@ actions:
namespace: "{{ .DeploymentConfig.Namespace }}"
args:
namespace: "{{ .DeploymentConfig.Namespace }}"
image: ghcr.io/kanisterio/mongodb:0.112.0
command:
sharedVolumeMedium: Memory

initImage: '{{if index .Options "kanisterImage" }} {{- .Options.kanisterImage -}} {{else -}} ghcr.io/kanisterio/kanister-tools:0.112.0 {{- end}}'
initCommand: ["bash", "-o", "errexit", "-o", "pipefail", "-c", "mkfifo /tmp/data; chmod 777 /tmp/data"]

backgroundImage: '{{if index .Options "kanisterImage" }} {{- .Options.kanisterImage -}} {{else -}} ghcr.io/kanisterio/kanister-tools:0.112.0 {{- end}}'
backgroundCommand:
- bash
- -o
- errexit
- -o
- pipefail
- -c
- |
backup_file_path='rs_backup.gz'
kopia_snap='{{ .ArtifactsIn.mongoBackup.KopiaSnapshot }}'
kando location pull --profile '{{ toJson .Profile }}' --path "${backup_file_path}" --kopia-snapshot "${kopia_snap}" - > /tmp/data
outputImage: bitnami/mongodb:7.0-debian-12
outputCommand:
- bash
- -o
- errexit
Expand All @@ -62,9 +96,7 @@ actions:
host="{{ .DeploymentConfig.Name }}.{{ .DeploymentConfig.Namespace }}.svc.cluster.local"
dbPassword='{{ index .Phases.pullFromStore.Secrets.mongosecret.Data "database-admin-password" | toString }}'
restore_cmd="mongorestore --gzip --archive --drop --host ${host} -u admin -p ${dbPassword}"
backup_file_path='rs_backup.gz'
kopia_snap='{{ .ArtifactsIn.mongoBackup.KopiaSnapshot }}'
kando location pull --profile '{{ toJson .Profile }}' --path "${backup_file_path}" --kopia-snapshot "${kopia_snap}" - | ${restore_cmd}
cat /tmp/data | ${restore_cmd}
delete:
inputArtifactNames:
# The kopia snapshot info created in backup phase can be used here
Expand All @@ -75,7 +107,7 @@ actions:
name: deleteFromStore
args:
namespace: "{{ .Namespace.Name }}"
image: ghcr.io/kanisterio/mongodb:0.112.0
image: '{{if index .Options "kanisterImage" }} {{- .Options.kanisterImage -}} {{else -}} ghcr.io/kanisterio/kanister-tools:0.112.0 {{- end}}'
command:
- bash
- -o
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,45 +11,68 @@ actions:
# `kopiaOutput` is the name provided to kando using `--output-name` flag
kopiaSnapshot: "{{ .Phases.dumpToStore.Output.kopiaOutput }}"
phases:
- func: KubeTask
- func: MultiContainerRun
name: dumpToStore
objects:
mysqlsecret:
kind: Secret
name: "{{ .DeploymentConfig.Name }}"
namespace: "{{ .DeploymentConfig.Namespace }}"
args:
image: ghcr.io/kanisterio/mysql-sidecar:0.112.0
namespace: "{{ .DeploymentConfig.Namespace }}"
command:
sharedVolumeMedium: Memory
initImage: '{{if index .Options "kanisterImage" }} {{- .Options.kanisterImage -}} {{else -}} ghcr.io/kanisterio/kanister-tools:0.112.0 {{- end}}'
initCommand: ["bash", "-o", "errexit", "-o", "pipefail", "-c", "mkfifo /tmp/data; chmod 777 /tmp/data"]

## FIXME: do we want to use mysql 9?
backgroundImage: mysql:8
backgroundCommand:
- bash
- -o
- errexit
- -o
- pipefail
- -c
- |
backup_file_path="dump.sql"
root_password="{{ index .Phases.dumpToStore.Secrets.mysqlsecret.Data "database-root-password" | toString }}"
dump_cmd="mysqldump --column-statistics=0 -u root --password=${root_password} -h {{ .DeploymentConfig.Name }} --single-transaction --all-databases"
${dump_cmd} | kando location push --profile '{{ toJson .Profile }}' --path "${backup_file_path}" --output-name "kopiaOutput" -
${dump_cmd} > /tmp/data
outputImage: '{{if index .Options "kanisterImage" }} {{- .Options.kanisterImage -}} {{else -}} ghcr.io/kanisterio/kanister-tools:0.112.0 {{- end}}'
outputCommand:
- bash
- -o
- errexit
- -o
- pipefail
- -c
- |
backup_file_path="dump.sql"
cat /tmp/data | kando location push --profile '{{ toJson .Profile }}' --path "${backup_file_path}" --output-name "kopiaOutput" -
restore:
inputArtifactNames:
# The kopia snapshot info created in backup phase can be used here
# Use the `--kopia-snapshot` flag in kando to pass in `mysqlBackup.KopiaSnapshot`
- mysqlBackup
phases:
- func: KubeTask
- func: MultiContainerRun
name: restoreFromStore
objects:
mysqlsecret:
kind: Secret
name: "{{ .DeploymentConfig.Name }}"
namespace: "{{ .DeploymentConfig.Namespace }}"
args:
image: ghcr.io/kanisterio/mysql-sidecar:0.112.0
namespace: "{{ .DeploymentConfig.Namespace }}"
command:
sharedVolumeMedium: Memory

initImage: '{{if index .Options "kanisterImage" }} {{- .Options.kanisterImage -}} {{else -}} ghcr.io/kanisterio/kanister-tools:0.112.0 {{- end}}'
initCommand: ["bash", "-o", "errexit", "-o", "pipefail", "-c", "mkfifo /tmp/data; chmod 777 /tmp/data"]


backgroundImage: '{{if index .Options "kanisterImage" }} {{- .Options.kanisterImage -}} {{else -}} ghcr.io/kanisterio/kanister-tools:0.112.0 {{- end}}'
backgroundCommand:
- bash
- -o
- errexit
Expand All @@ -59,9 +82,22 @@ actions:
- |
backup_file_path="dump.sql"
kopia_snap='{{ .ArtifactsIn.mysqlBackup.KopiaSnapshot }}'
kando location pull --profile '{{ toJson .Profile }}' --path "${backup_file_path}" --kopia-snapshot "${kopia_snap}" - > /tmp/data
## FIXME: do we want to use mysql 9?
outputImage: mysql:8
outputCommand:
- bash
- -o
- errexit
- -o
- pipefail
- -c
- |
root_password="{{ index .Phases.restoreFromStore.Secrets.mysqlsecret.Data "database-root-password" | toString }}"
restore_cmd="mysql -u root --password=${root_password} -h {{ .DeploymentConfig.Name }}"
kando location pull --profile '{{ toJson .Profile }}' --path "${backup_file_path}" --kopia-snapshot "${kopia_snap}" - | ${restore_cmd}
cat /tmp/data | ${restore_cmd}
delete:
inputArtifactNames:
# The kopia snapshot info created in backup phase can be used here
Expand All @@ -71,7 +107,7 @@ actions:
- func: KubeTask
name: deleteFromStore
args:
image: ghcr.io/kanisterio/mysql-sidecar:0.112.0
image: '{{if index .Options "kanisterImage" }} {{- .Options.kanisterImage -}} {{else -}} ghcr.io/kanisterio/kanister-tools:0.112.0 {{- end}}'
namespace: "{{ .Namespace.Name }}"
command:
- bash
Expand Down
Loading

0 comments on commit e250d70

Please sign in to comment.