Skip to content

Commit

Permalink
chore(local-dev): fix backups in local dev (#5063)
Browse files Browse the repository at this point in the history
  • Loading branch information
JGAntunes authored Jan 2, 2025
1 parent 0ea8718 commit a09ea3d
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ spec:
kots.io/backup: velero
annotations:
backup.velero.io/backup-volumes: backup
pre.hook.backup.velero.io/command: '["/backup.sh"]'
pre.hook.backup.velero.io/command: '["/scripts/backup.sh"]'
pre.hook.backup.velero.io/timeout: 10m
spec:
securityContext:
Expand Down Expand Up @@ -90,7 +90,7 @@ spec:
key: uri
optional: true
- name: POSTGRES_SCHEMA_DIR # this is needed for the migration
value: "/postgres/tables"
value: "/scripts/postgres/tables"
- name: RQLITE_URI
valueFrom:
secretKeyRef:
Expand Down Expand Up @@ -211,7 +211,7 @@ spec:

- name: restore-db
command:
- "/restore-db.sh"
- "/scripts/restore-db.sh"
env:
- name: RQLITE_PASSWORD
valueFrom:
Expand All @@ -232,7 +232,7 @@ spec:

- name: restore-s3
command:
- /restore-s3.sh
- /scripts/restore-s3.sh
env:
- name: S3_ENDPOINT
valueFrom:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ spec:
kots.io/backup: velero
annotations:
backup.velero.io/backup-volumes: backup
pre.hook.backup.velero.io/command: '["/backup.sh"]'
pre.hook.backup.velero.io/command: '["/scripts/backup.sh"]'
pre.hook.backup.velero.io/timeout: 10m
spec:
securityContext:
Expand Down Expand Up @@ -108,7 +108,7 @@ spec:
key: uri
optional: true
- name: POSTGRES_SCHEMA_DIR # this is needed for the migration
value: "/postgres/tables"
value: "/scripts/postgres/tables"
- name: RQLITE_URI
valueFrom:
secretKeyRef:
Expand Down Expand Up @@ -210,7 +210,7 @@ spec:

- name: restore-data
command:
- "/restore.sh"
- "/scripts/restore.sh"
env:
- name: RQLITE_PASSWORD
valueFrom:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
value:
name: migrate-s3
command:
- "/migrate-s3.sh"
- "/scripts/migrate-s3.sh"
env:
- name: S3_ENDPOINT
valueFrom:
Expand Down
13 changes: 1 addition & 12 deletions deploy/melange.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,7 @@ pipeline:
mkdir -p "${DESTDIR}"

# Scripts etc.
mv deploy/assets/backup.sh "${DESTDIR}/backup.sh"
mv deploy/assets/restore-db.sh "${DESTDIR}/restore-db.sh"
mv deploy/assets/restore-s3.sh "${DESTDIR}/restore-s3.sh"
mv deploy/assets/restore.sh "${DESTDIR}/restore.sh"
mv deploy/assets/migrate-s3.sh "${DESTDIR}/migrate-s3.sh"
mv deploy/assets/fs-minio-check.sh "${DESTDIR}/fs-minio-check.sh"
mv deploy/assets/fs-minio-reset.sh "${DESTDIR}/fs-minio-reset.sh"
mv deploy/assets/fs-minio-keys-sha.sh "${DESTDIR}/fs-minio-keys-sha.sh"
mv deploy/assets/s3-bucket-create.sh "${DESTDIR}/s3-bucket-create.sh"
mv deploy/assets/s3-bucket-head.sh "${DESTDIR}/s3-bucket-head.sh"
mv deploy/assets/kots-upgrade.sh "${DESTDIR}/kots-upgrade.sh"
mv deploy/assets/postgres "${DESTDIR}/postgres"
mv deploy/assets "${DESTDIR}/scripts"

# kotsadm and kots binaries
export VERSION=${GIT_TAG}
Expand Down
19 changes: 1 addition & 18 deletions dev/dockerfiles/kotsadm/Dockerfile.ttlsh
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,7 @@ RUN useradd -c 'kotsadm user' -m -d /home/kotsadm -s /bin/bash -u 1001 kotsadm
USER kotsadm
ENV HOME /home/kotsadm

COPY --chown=kotsadm:kotsadm ./deploy/assets/backup.sh /backup.sh
COPY --chown=kotsadm:kotsadm ./deploy/assets/restore-db.sh /restore-db.sh
COPY --chown=kotsadm:kotsadm ./deploy/assets/restore-s3.sh /restore-s3.sh
COPY --chown=kotsadm:kotsadm ./deploy/assets/restore.sh /restore.sh
COPY --chown=kotsadm:kotsadm ./deploy/assets/migrate-s3.sh /migrate-s3.sh

COPY --chown=kotsadm:kotsadm ./deploy/assets/fs-minio-check.sh /fs-minio-check.sh
COPY --chown=kotsadm:kotsadm ./deploy/assets/fs-minio-reset.sh /fs-minio-reset.sh
COPY --chown=kotsadm:kotsadm ./deploy/assets/fs-minio-keys-sha.sh /fs-minio-keys-sha.sh

COPY --chown=kotsadm:kotsadm ./deploy/assets/s3-bucket-create.sh /s3-bucket-create.sh
COPY --chown=kotsadm:kotsadm ./deploy/assets/s3-bucket-head.sh /s3-bucket-head.sh

COPY --chown=kotsadm:kotsadm ./deploy/assets/kots-upgrade.sh /kots-upgrade.sh

# only used for the migration
COPY --chown=kotsadm:kotsadm ./deploy/assets/postgres /postgres

COPY --chown=kotsadm:kotsadm ./deploy/assets /scripts
COPY --chown=kotsadm:kotsadm ./bin/kotsadm /kotsadm
COPY --chown=kotsadm:kotsadm ./bin/kots /kots

Expand Down
6 changes: 6 additions & 0 deletions dev/patches/kotsadm-up.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ spec:
hostPath:
path: {{ .Env.PROJECT_DIR }}
type: Directory
- name: scripts
hostPath:
path: {{ .Env.PROJECT_DIR }}/deploy/assets
type: Directory
{{- if .Env.EC_NODE }}
affinity:
nodeAffinity:
Expand All @@ -30,6 +34,8 @@ spec:
volumeMounts:
- name: dev
mountPath: /replicatedhq/kots # workdir in the container
- name: scripts
mountPath: /scripts
env:
# in order to serve from kotsadm-web even in embedded cluster
- name: DISABLE_SPA_SERVING
Expand Down
16 changes: 8 additions & 8 deletions pkg/kotsadm/objects/kotsadm_objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ func KotsadmDeployment(deployOptions types.DeployOptions) (*appsv1.Deployment, e
},
{
Name: "POSTGRES_SCHEMA_DIR", // this is needed for the migration
Value: "/postgres/tables",
Value: "/scripts/postgres/tables",
},
{
Name: "POD_NAMESPACE",
Expand Down Expand Up @@ -357,7 +357,7 @@ func KotsadmDeployment(deployOptions types.DeployOptions) (*appsv1.Deployment, e

podAnnotations := map[string]string{
"backup.velero.io/backup-volumes": "backup",
"pre.hook.backup.velero.io/command": `["/backup.sh"]`,
"pre.hook.backup.velero.io/command": `["/scripts/backup.sh"]`,
"pre.hook.backup.velero.io/timeout": "10m",
}
for k, v := range deployOptions.AdditionalAnnotations {
Expand Down Expand Up @@ -554,7 +554,7 @@ func KotsadmDeployment(deployOptions types.DeployOptions) (*appsv1.Deployment, e
ImagePullPolicy: corev1.PullIfNotPresent,
Name: "restore-db",
Command: []string{
"/restore-db.sh",
"/scripts/restore-db.sh",
},
VolumeMounts: []corev1.VolumeMount{
{
Expand Down Expand Up @@ -596,7 +596,7 @@ func KotsadmDeployment(deployOptions types.DeployOptions) (*appsv1.Deployment, e
ImagePullPolicy: corev1.PullIfNotPresent,
Name: "restore-s3",
Command: []string{
"/restore-s3.sh",
"/scripts/restore-s3.sh",
},
VolumeMounts: []corev1.VolumeMount{
{
Expand Down Expand Up @@ -829,7 +829,7 @@ func KotsadmStatefulSet(deployOptions types.DeployOptions, size resource.Quantit
},
{
Name: "POSTGRES_SCHEMA_DIR", // this is needed for the migration
Value: "/postgres/tables",
Value: "/scripts/postgres/tables",
},
{
Name: "POD_NAMESPACE",
Expand Down Expand Up @@ -901,7 +901,7 @@ func KotsadmStatefulSet(deployOptions types.DeployOptions, size resource.Quantit

podAnnotations := map[string]string{
"backup.velero.io/backup-volumes": "backup",
"pre.hook.backup.velero.io/command": `["/backup.sh"]`,
"pre.hook.backup.velero.io/command": `["/scripts/backup.sh"]`,
"pre.hook.backup.velero.io/timeout": "10m",
}
for k, v := range deployOptions.AdditionalAnnotations {
Expand Down Expand Up @@ -1111,7 +1111,7 @@ func KotsadmStatefulSet(deployOptions types.DeployOptions, size resource.Quantit
ImagePullPolicy: corev1.PullIfNotPresent,
Name: "restore-data",
Command: []string{
"/restore.sh",
"/scripts/restore.sh",
},
VolumeMounts: []corev1.VolumeMount{
{
Expand Down Expand Up @@ -1157,7 +1157,7 @@ func KotsadmStatefulSet(deployOptions types.DeployOptions, size resource.Quantit
ImagePullPolicy: corev1.PullIfNotPresent,
Name: "migrate-s3",
Command: []string{
"/migrate-s3.sh",
"/scripts/migrate-s3.sh",
},
VolumeMounts: []corev1.VolumeMount{
{
Expand Down
2 changes: 1 addition & 1 deletion pkg/kotsadm/updates.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func UpdateToVersion(newVersion string) error {
Name: "kotsadm-updater",
Image: fmt.Sprintf("kotsadm/kotsadm:%s", newVersion),
ImagePullPolicy: corev1.PullIfNotPresent,
Command: []string{"/kots-upgrade.sh"},
Command: []string{"/scripts/kots-upgrade.sh"},
Args: args,
Env: []corev1.EnvVar{
{
Expand Down
4 changes: 2 additions & 2 deletions pkg/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func GetConfig() *aws.Config {

// CreateS3BucketUsingAPod is helpful when trying to hit a cluster s3 service using the CLI since that could be used outside the cluster, or due to firewall restrictions
func CreateS3BucketUsingAPod(ctx context.Context, clientset kubernetes.Interface, podOptions S3OpsPodOptions) error {
command := []string{"/s3-bucket-create.sh"}
command := []string{"/scripts/s3-bucket-create.sh"}
pod, err := s3BucketPod(clientset, podOptions, command)
if err != nil {
return errors.Wrap(err, "failed to get pod resource")
Expand Down Expand Up @@ -132,7 +132,7 @@ func CreateS3BucketUsingAPod(ctx context.Context, clientset kubernetes.Interface

// HeadS3BucketUsingAPod is helpful when trying to hit a cluster s3 service using the CLI since that could be used outside the cluster, or due to firewall restrictions
func HeadS3BucketUsingAPod(ctx context.Context, clientset kubernetes.Interface, podOptions S3OpsPodOptions) error {
command := []string{"/s3-bucket-head.sh"}
command := []string{"/scripts/s3-bucket-head.sh"}
pod, err := s3BucketPod(clientset, podOptions, command)
if err != nil {
return errors.Wrap(err, "failed to get pod resource")
Expand Down
6 changes: 3 additions & 3 deletions pkg/snapshot/filesystem_minio.go
Original file line number Diff line number Diff line change
Expand Up @@ -810,17 +810,17 @@ func createFileSystemMinioKeysSHAPod(ctx context.Context, clientset kubernetes.I
}

func fileSystemMinioCheckPod(ctx context.Context, clientset kubernetes.Interface, deployOptions FileSystemDeployOptions, registryConfig kotsadmtypes.RegistryConfig) (*corev1.Pod, error) {
command := []string{"/fs-minio-check.sh"}
command := []string{"/scripts/fs-minio-check.sh"}
return fileSystemMinioConfigPod(clientset, deployOptions, registryConfig, fsMinioCheckTag, command, nil, true)
}

func fileSystemMinioResetPod(ctx context.Context, clientset kubernetes.Interface, deployOptions FileSystemDeployOptions, registryConfig kotsadmtypes.RegistryConfig) (*corev1.Pod, error) {
command := []string{"/fs-minio-reset.sh"}
command := []string{"/scripts/fs-minio-reset.sh"}
return fileSystemMinioConfigPod(clientset, deployOptions, registryConfig, fsMinioResetTag, command, nil, false)
}

func fileSystemMinioKeysSHAPod(ctx context.Context, clientset kubernetes.Interface, deployOptions FileSystemDeployOptions, registryConfig kotsadmtypes.RegistryConfig, minioKeysSHA string) (*corev1.Pod, error) {
command := []string{"/fs-minio-keys-sha.sh"}
command := []string{"/scripts/fs-minio-keys-sha.sh"}
args := []string{minioKeysSHA}
return fileSystemMinioConfigPod(clientset, deployOptions, registryConfig, fsMinioKeysSHATag, command, args, false)
}
Expand Down

0 comments on commit a09ea3d

Please sign in to comment.