Skip to content

Commit c2f5bc1

Browse files
egeguneshors
andauthored
K8SPSMDB-1366: Fix reconfiguring PBM after sharding is toggled (#1907)
* K8SPSMDB-1366: Fix reconfiguring PBM after sharding is toggled * fix init-deploy compare --------- Co-authored-by: Viacheslav Sarzhan <slava.sarzhan@percona.com>
1 parent 012a496 commit c2f5bc1

File tree

5 files changed

+133
-15
lines changed

5 files changed

+133
-15
lines changed

e2e-tests/rs-shard-migration/compare/statefulset_some-name-rs0.yml

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ spec:
5555
- --encryptionKeyFile=/etc/mongodb-encryption/encryption-key
5656
- --wiredTigerCacheSizeGB=0.25
5757
- --wiredTigerIndexPrefixCompression=true
58-
- --config=/etc/mongodb-config/mongod.conf
5958
- --quiet
6059
command:
6160
- /opt/percona/ps-entry.sh
@@ -132,8 +131,6 @@ spec:
132131
- mountPath: /etc/mongodb-ssl-internal
133132
name: ssl-internal
134133
readOnly: true
135-
- mountPath: /etc/mongodb-config
136-
name: config
137134
- mountPath: /opt/percona
138135
name: bin
139136
- mountPath: /etc/mongodb-encryption
@@ -142,6 +139,57 @@ spec:
142139
- mountPath: /etc/users-secret
143140
name: users-secret-file
144141
workingDir: /data/db
142+
- args:
143+
- pbm-agent-entrypoint
144+
command:
145+
- /opt/percona/pbm-entry.sh
146+
env:
147+
- name: PBM_AGENT_MONGODB_USERNAME
148+
valueFrom:
149+
secretKeyRef:
150+
key: MONGODB_BACKUP_USER_ESCAPED
151+
name: internal-some-name-users
152+
optional: false
153+
- name: PBM_AGENT_MONGODB_PASSWORD
154+
valueFrom:
155+
secretKeyRef:
156+
key: MONGODB_BACKUP_PASSWORD_ESCAPED
157+
name: internal-some-name-users
158+
optional: false
159+
- name: PBM_MONGODB_REPLSET
160+
value: rs0
161+
- name: PBM_MONGODB_PORT
162+
value: "27017"
163+
- name: PBM_AGENT_SIDECAR
164+
value: "true"
165+
- name: PBM_AGENT_SIDECAR_SLEEP
166+
value: "5"
167+
- name: POD_NAME
168+
valueFrom:
169+
fieldRef:
170+
apiVersion: v1
171+
fieldPath: metadata.name
172+
- name: PBM_MONGODB_URI
173+
value: mongodb://$(PBM_AGENT_MONGODB_USERNAME):$(PBM_AGENT_MONGODB_PASSWORD)@localhost:$(PBM_MONGODB_PORT)/?tls=true&tlsCertificateKeyFile=/tmp/tls.pem&tlsCAFile=/etc/mongodb-ssl/ca.crt&tlsInsecure=true
174+
- name: PBM_AGENT_TLS_ENABLED
175+
value: "true"
176+
imagePullPolicy: Always
177+
name: backup-agent
178+
resources: {}
179+
securityContext:
180+
runAsNonRoot: true
181+
runAsUser: 1001
182+
terminationMessagePath: /dev/termination-log
183+
terminationMessagePolicy: File
184+
volumeMounts:
185+
- mountPath: /etc/mongodb-ssl
186+
name: ssl
187+
readOnly: true
188+
- mountPath: /opt/percona
189+
name: bin
190+
readOnly: true
191+
- mountPath: /data/db
192+
name: mongod-data
145193
dnsPolicy: ClusterFirst
146194
initContainers:
147195
- command:
@@ -177,11 +225,6 @@ spec:
177225
secretName: some-name-mongodb-keyfile
178226
- emptyDir: {}
179227
name: bin
180-
- configMap:
181-
defaultMode: 420
182-
name: some-name-rs0-mongod
183-
optional: true
184-
name: config
185228
- name: some-name-mongodb-encryption-key
186229
secret:
187230
defaultMode: 288
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: psmdb.percona.com/v1
2+
kind: PerconaServerMongoDBBackup
3+
metadata:
4+
finalizers:
5+
- percona.com/delete-backup
6+
name: backup-minio
7+
spec:
8+
clusterName: some-name
9+
storageName: minio
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
apiVersion: psmdb.percona.com/v1
2+
kind: PerconaServerMongoDB
3+
metadata:
4+
name: some-name
5+
spec:
6+
#platform: openshift
7+
image:
8+
imagePullPolicy: Always
9+
allowUnsafeConfigurations: false
10+
backup:
11+
enabled: true
12+
image: perconalab/percona-server-mongodb-operator:0.4.0-backup
13+
storages:
14+
minio:
15+
type: s3
16+
s3:
17+
credentialsSecret: minio-secret
18+
region: us-east-1
19+
bucket: operator-testing
20+
endpointUrl: http://minio-service:9000/
21+
insecureSkipTLSVerify: false
22+
replsets:
23+
- name: rs0
24+
affinity:
25+
antiAffinityTopologyKey: none
26+
resources:
27+
limits:
28+
cpu: 500m
29+
memory: 0.5G
30+
requests:
31+
cpu: 100m
32+
memory: 0.1G
33+
volumeSpec:
34+
persistentVolumeClaim:
35+
resources:
36+
requests:
37+
storage: 1Gi
38+
size: 3
39+
secrets:
40+
users: some-users

e2e-tests/rs-shard-migration/run

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,28 @@ function get_shard_parameter() {
1515
}
1616

1717
function main() {
18+
cluster="some-name"
19+
CLUSTER_SIZE=3
20+
1821
create_infra $namespace
1922

2023
desc 'create secrets and start client'
2124
kubectl_bin apply -f $conf_dir/secrets.yml -f $conf_dir/client.yml
22-
cluster="some-name"
23-
CLUSTER_SIZE=3
2425

25-
spinup_psmdb ${cluster}-rs0 $conf_dir/${cluster}-rs0.yml
26+
apply_s3_storage_secrets
27+
deploy_minio
28+
29+
spinup_psmdb ${cluster}-rs0 ${test_dir}/conf/${cluster}.yml
2630

2731
desc 'check if statefulset created with expected config'
2832
compare_kubectl "statefulset/${cluster}-rs0"
2933

3034
desc 'write data, read from all'
3135
simple_data_check "${cluster}-rs0" ${CLUSTER_SIZE}
3236

37+
run_backup "minio" "backup-minio-1"
38+
wait_backup "backup-minio-1"
39+
3340
desc 'initiate migration from replicaset to sharded cluster'
3441
kubectl_bin patch psmdb/${cluster} --type json -p='[{"op":"add","path":"/spec/sharding","value":{"configsvrReplSet":{"size":'${CLUSTER_SIZE}',"volumeSpec":{"persistentVolumeClaim":{"resources":{"requests":{"storage":"3Gi"}}}}},"enabled":true,"mongos":{"size":1}}}]'
3542
sleep 10
@@ -58,6 +65,9 @@ function main() {
5865
exit 1
5966
fi
6067

68+
run_backup "minio" "backup-minio-2"
69+
wait_backup "backup-minio-2"
70+
6171
desc 'get back from sharded cluster to replicaset'
6272
kubectl_bin patch psmdb/${cluster} --type json -p='[{"op":"remove","path":"/spec/sharding"}]'
6373
sleep 20
@@ -74,6 +84,9 @@ function main() {
7484
exit 1
7585
fi
7686

87+
run_backup "minio" "backup-minio-3"
88+
wait_backup "backup-minio-3"
89+
7790
desc 'cleanup CRDs and RBAC'
7891
kubectl_bin delete -f "${src_dir}/deploy/crd.yaml" || :
7992
kubectl_bin delete -f "${src_dir}/deploy/rbac.yaml" || :

pkg/controller/perconaservermongodb/psmdb_controller.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -580,9 +580,13 @@ func (r *ReconcilePerconaServerMongoDB) handleShardingToggle(ctx context.Context
580580
getShardingStatus := func(cr *api.PerconaServerMongoDB) api.ConditionStatus {
581581
if cr.Spec.Sharding.Enabled {
582582
return api.ConditionTrue
583-
} else {
584-
return api.ConditionFalse
585583
}
584+
585+
return api.ConditionFalse
586+
}
587+
588+
toggleShardingStatus := func(s api.ConditionStatus) bool {
589+
return s != api.ConditionTrue
586590
}
587591

588592
condition := cr.Status.FindCondition(api.AppStateSharding)
@@ -598,7 +602,14 @@ func (r *ReconcilePerconaServerMongoDB) handleShardingToggle(ctx context.Context
598602
return nil
599603
}
600604

601-
cr.Spec.Sharding.Enabled = !cr.Spec.Sharding.Enabled
605+
log := logf.FromContext(ctx)
606+
if toggleShardingStatus(condition.Status) {
607+
log.Info("Sharding is enabled, pausing the cluster")
608+
} else {
609+
log.Info("Sharding is disabled, pausing the cluster")
610+
}
611+
612+
cr.Spec.Sharding.Enabled = toggleShardingStatus(condition.Status)
602613
cr.Spec.Pause = true
603614
if err := cr.CheckNSetDefaults(ctx, r.serverVersion.Platform); err != nil {
604615
return errors.Wrap(err, "check and set defaults")
@@ -616,8 +627,10 @@ func (r *ReconcilePerconaServerMongoDB) handleShardingToggle(ctx context.Context
616627
return nil
617628
}
618629

619-
cr.Spec.Sharding.Enabled = !cr.Spec.Sharding.Enabled
630+
cr.Spec.Sharding.Enabled = toggleShardingStatus(condition.Status)
620631
cr.Spec.Pause = false
632+
// toggling sharding status removes all PBM collections, so we need to reconfigure
633+
cr.Status.BackupConfigHash = ""
621634
if err := cr.CheckNSetDefaults(ctx, r.serverVersion.Platform); err != nil {
622635
return errors.Wrap(err, "check and set defaults")
623636
}

0 commit comments

Comments
 (0)