Skip to content

Commit b46da99

Browse files
Merge pull request #441 from vshn/fix/redis
Fix Redis restore and pvc resize
2 parents 457bf33 + f0520bf commit b46da99

File tree

14 files changed

+54
-37
lines changed

14 files changed

+54
-37
lines changed

pkg/comp-functions/functions/vshnredis/backup.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,17 @@ func updateRelease(ctx context.Context, svc *runtime.ServiceRuntime) error {
7171
}
7272

7373
l.Info("Adding the PVC k8up annotations")
74-
if err := backup.AddPVCAnnotationToValues(values, "master", "persistence", "annotations"); err != nil {
74+
if err := backup.AddPVCAnnotationToValues(values, "replica", "persistence", "annotations"); err != nil {
7575
return err
7676
}
7777

7878
l.Info("Adding the Pod k8up annotations")
79-
if err := backup.AddPodAnnotationToValues(values, "/scripts/backup.sh", ".tar", "master", "podAnnotations"); err != nil {
79+
if err := backup.AddPodAnnotationToValues(values, "/scripts/backup.sh", ".tar", "replica", "podAnnotations"); err != nil {
8080
return err
8181
}
8282

8383
l.Info("Mounting CM into pod")
84-
if err := backup.AddBackupCMToValues(values, []string{"master", "extraVolumes"}, []string{"master", "extraVolumeMounts"}); err != nil {
84+
if err := backup.AddBackupCMToValues(values, []string{"replica", "extraVolumes"}, []string{"replica", "extraVolumeMounts"}); err != nil {
8585
return err
8686
}
8787

pkg/comp-functions/functions/vshnredis/pvcresize.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func ResizePVCs(ctx context.Context, comp *vshnv1.VSHNRedis, svc *runtime.Servic
115115
}
116116

117117
func needReleasePatch(comp *vshnv1.VSHNRedis, values map[string]interface{}) (bool, *xfnproto.Result) {
118-
releaseSizeValue, found, err := unstructured.NestedString(values, "master", "persistence", "size")
118+
releaseSizeValue, found, err := unstructured.NestedString(values, "replica", "persistence", "size")
119119
if !found {
120120
return false, runtime.NewFatalResult(fmt.Errorf("disk size not found in release"))
121121
}
@@ -183,7 +183,7 @@ func addDeletionJob(svc *runtime.ServiceRuntime, comp *vshnv1.VSHNRedis) error {
183183
Env: []corev1.EnvVar{
184184
{
185185
Name: "STS_NAME",
186-
Value: "redis-master",
186+
Value: "redis-node",
187187
},
188188
{
189189
Name: "STS_NAMESPACE",
@@ -212,17 +212,17 @@ func addDeletionJob(svc *runtime.ServiceRuntime, comp *vshnv1.VSHNRedis) error {
212212
},
213213
}
214214

215-
return svc.SetDesiredKubeObject(job, comp.Name+"-sts-deleter")
215+
return svc.SetDesiredKubeObject(job, comp.Name+"-sts-deleter", runtime.KubeOptionAllowDeletion)
216216
}
217217

218218
func addStsObserver(svc *runtime.ServiceRuntime, comp *vshnv1.VSHNRedis) error {
219219

220220
statefulset := &appsv1.StatefulSet{
221221
ObjectMeta: metav1.ObjectMeta{
222-
Name: "redis-master",
222+
Name: "redis-node",
223223
Namespace: getInstanceNamespace(comp),
224224
},
225225
}
226226

227-
return svc.SetDesiredKubeObject(statefulset, comp.Name+"-sts-observer", runtime.KubeOptionObserve)
227+
return svc.SetDesiredKubeObject(statefulset, comp.Name+"-sts-observer", runtime.KubeOptionObserve, runtime.KubeOptionAllowDeletion)
228228
}

pkg/comp-functions/functions/vshnredis/pvcresize_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func Test_needReleasePatch(t *testing.T) {
6363
},
6464
},
6565
values: map[string]interface{}{
66-
"master": map[string]interface{}{
66+
"replica": map[string]interface{}{
6767
"persistence": map[string]interface{}{
6868
"size": "15Gi",
6969
},
@@ -85,7 +85,7 @@ func Test_needReleasePatch(t *testing.T) {
8585
},
8686
},
8787
values: map[string]interface{}{
88-
"master": map[string]interface{}{
88+
"replica": map[string]interface{}{
8989
"persistence": map[string]interface{}{
9090
"size": "15Gi",
9191
},
@@ -107,7 +107,7 @@ func Test_needReleasePatch(t *testing.T) {
107107
},
108108
},
109109
values: map[string]interface{}{
110-
"master": map[string]interface{}{
110+
"replica": map[string]interface{}{
111111
"persistence": map[string]interface{}{
112112
"size": "15Gi",
113113
},
@@ -130,7 +130,7 @@ func Test_needReleasePatch(t *testing.T) {
130130
},
131131
},
132132
values: map[string]interface{}{
133-
"master": map[string]interface{}{
133+
"replica": map[string]interface{}{
134134
"persistence": map[string]interface{}{
135135
"size": "15Gi",
136136
},
@@ -153,7 +153,7 @@ func Test_needReleasePatch(t *testing.T) {
153153
},
154154
},
155155
values: map[string]interface{}{
156-
"master": map[string]interface{}{
156+
"replica": map[string]interface{}{
157157
"persistence": map[string]interface{}{
158158
"size": "foo",
159159
},
@@ -176,7 +176,7 @@ func Test_needReleasePatch(t *testing.T) {
176176
},
177177
},
178178
values: map[string]interface{}{
179-
"master": map[string]interface{}{
179+
"replica": map[string]interface{}{
180180
"persistence": map[string]interface{}{},
181181
},
182182
},

pkg/comp-functions/functions/vshnredis/restore.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func addRestoreJob(ctx context.Context, comp *vshnv1.VSHNRedis, svc *runtime.Ser
140140
Name: "data",
141141
VolumeSource: corev1.VolumeSource{
142142
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
143-
ClaimName: "redis-data-redis-master-0",
143+
ClaimName: "redis-data-redis-node-0",
144144
},
145145
},
146146
},
@@ -236,6 +236,13 @@ func addRestoreJob(ctx context.Context, comp *vshnv1.VSHNRedis, svc *runtime.Ser
236236
},
237237
}
238238

239+
if !svc.GetBoolFromCompositionConfig("isOpenshift") {
240+
fsGroup := int64(1001)
241+
job.Spec.Template.Spec.SecurityContext = &corev1.PodSecurityContext{
242+
FSGroup: &fsGroup,
243+
}
244+
}
245+
239246
return svc.SetDesiredKubeObject(job, restoreJobName)
240247
}
241248

pkg/comp-functions/functions/vshnredis/script/cleanupRestore.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ EOF
5656
fi
5757
echo "scaling up redis"
5858

59-
kubectl -n "${TARGET_NAMESPACE}" scale statefulset redis-master --replicas "${NUM_REPLICAS}"
59+
kubectl -n "${TARGET_NAMESPACE}" scale statefulset redis-node --replicas "${NUM_REPLICAS}"
6060

6161
echo "cleanup secret"
6262

pkg/comp-functions/functions/vshnredis/script/prepRestore.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ restic_password=$(kubectl -n "${source_namespace}" get secret k8up-repository-pa
1414
restic_repository=$(kubectl -n "${source_namespace}" get snapshots.k8up.io "${BACKUP_NAME}" -o jsonpath='{.spec.repository}')
1515
backup_path=$(kubectl -n "${source_namespace}" get snapshots.k8up.io "${BACKUP_NAME}" -o jsonpath='{.spec.paths[0]}')
1616
backup_name=$(kubectl -n "${source_namespace}" get snapshots.k8up.io "${BACKUP_NAME}" -o jsonpath='{.spec.id}')
17-
num_replicas=$(kubectl -n "${TARGET_NAMESPACE}" get statefulset redis-master -o jsonpath='{.spec.replicas}')
17+
num_replicas=$(kubectl -n "${TARGET_NAMESPACE}" get statefulset redis-node -o jsonpath='{.spec.replicas}')
1818
kubectl -n "${TARGET_NAMESPACE}" create secret generic "restore-credentials-${BACKUP_NAME}" --from-literal AWS_ACCESS_KEY_ID="${access_key}" --from-literal AWS_SECRET_ACCESS_KEY="${secret_key}" --from-literal RESTIC_PASSWORD="${restic_password}" --from-literal RESTIC_REPOSITORY="${restic_repository}" --from-literal BACKUP_PATH="${backup_path}" --from-literal BACKUP_NAME="${backup_name}"
1919
kubectl create secret generic "statefulset-replicas-${SOURCE_CLAIM_NAME}-${BACKUP_NAME}" --from-literal NUM_REPLICAS="${num_replicas}"
2020
echo "scaling down redis"
2121

22-
until kubectl -n "${TARGET_NAMESPACE}" get statefulset redis-master > /dev/null 2>&1
22+
until kubectl -n "${TARGET_NAMESPACE}" get statefulset redis-node > /dev/null 2>&1
2323
do
2424
sleep 1
2525
done
2626

27-
kubectl -n "${TARGET_NAMESPACE}" scale statefulset redis-master --replicas 0
27+
kubectl -n "${TARGET_NAMESPACE}" scale statefulset redis-node --replicas 0

pkg/comp-functions/functions/vshnredis/script/recreate.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ if [[ $foundsize != "$size" ]]; then
1919
# deletion with orphan doesn't go through and the sts is stuck with an orphan finalizer.
2020
# So if the delete hasn't returned after 5s we forcefully patch away the finalizer.
2121
kubectl -n "$namespace" delete sts "$name" --cascade=orphan --ignore-not-found --wait=true --timeout 5s || true
22-
kubectl -n "$namespace" patch sts redis-master -p '{"metadata":{"finalizers":null}}' || true
22+
kubectl -n "$namespace" patch sts "$name" -p '{"metadata":{"finalizers":null}}' || true
2323
# Poke the release so it tries again to create the sts
2424
# We first set it to garbage to ensure that the release is in an invalid state, we use an invalid state so it doesn't
2525
# actually deploy anything.
2626
# Then we patch the right size to enforce an upgrade
2727
# This is necessary as provider-helm doesn't actually retry failed helm deployments unless the values change.
2828
echo "Triggering sts re-creation"
29-
kubectl patch release "$release" --type merge -p "{\"spec\":{\"forProvider\":{\"values\":{\"master\":{\"persistence\":{\"size\":\"foo\"}}}}}}"
30-
kubectl patch release "$release" --type merge -p "{\"spec\":{\"forProvider\":{\"values\":{\"master\":{\"persistence\":{\"size\":\"$size\"}}}}}}"
29+
kubectl patch release "$release" --type merge -p "{\"spec\":{\"forProvider\":{\"values\":{\"replica\":{\"persistence\":{\"size\":\"foo\"}}}}}}"
30+
kubectl patch release "$release" --type merge -p "{\"spec\":{\"forProvider\":{\"values\":{\"replica\":{\"persistence\":{\"size\":\"$size\"}}}}}}"
3131
count=0
3232
while ! kubectl -n "$namespace" get sts "$name" && [[ count -lt 300 ]]; do
3333
echo "waiting for sts to re-appear"

pkg/comp-functions/functions/vshnredis/script/restore.sh

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,20 @@
22

33
set -euo pipefail
44

5-
rm -rf /data/*
6-
restic dump "${BACKUP_NAME}" "${BACKUP_PATH}" > /data/restore.tar
7-
cd /data
8-
tar xvf restore.tar
9-
mv data/* .
10-
rmdir data
11-
rm restore.tar
5+
DEST="/data"
6+
7+
echo "Starting restore process"
8+
9+
echo "Removing existing files in ${DEST}"
10+
rm -rf "${DEST:?}/"*
11+
12+
echo "Dumping restic backup '${BACKUP_NAME}' path '${BACKUP_PATH}' to ${DEST}/restore.tar"
13+
restic dump "${BACKUP_NAME}" "${BACKUP_PATH}" > "${DEST}/restore.tar"
14+
15+
echo "Extracting files from restore.tar into ${DEST}"
16+
tar xvf "${DEST}/restore.tar" --strip-components=1 -C "${DEST}"
17+
18+
echo "Removing temporary archive ${DEST}/restore.tar"
19+
rm "${DEST}/restore.tar"
20+
21+
echo "Restore completed successfully"

test/functions/vshnredis/pvcresize/01_default.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ desired:
4242
image:
4343
repository: bitnami/redis
4444
tag: 7.0.11
45-
master:
45+
replica:
4646
containerSecurityContext:
4747
enabled: true
4848
persistence:
@@ -115,7 +115,7 @@ observed:
115115
image:
116116
repository: bitnami/redis
117117
tag: "7.0"
118-
master:
118+
replica:
119119
containerSecurityContext:
120120
enabled: true
121121
extraVolumes: []

test/functions/vshnredis/pvcresize/01_job.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ desired:
4242
image:
4343
repository: bitnami/redis
4444
tag: 7.0.11
45-
master:
45+
replica:
4646
containerSecurityContext:
4747
enabled: true
4848
persistence:
@@ -169,7 +169,7 @@ observed:
169169
image:
170170
repository: bitnami/redis
171171
tag: "7.0"
172-
master:
172+
replica:
173173
containerSecurityContext:
174174
enabled: true
175175
extraVolumes: []

0 commit comments

Comments
 (0)