From c39319cc5bb3327ecc7a76af60b6edefab6c43d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ege=20G=C3=BCne=C5=9F?= Date: Thu, 11 Jul 2024 12:34:07 +0300 Subject: [PATCH] fix scale up --- e2e-tests/functions | 1 + e2e-tests/split-horizon/conf/some-name.yml | 33 ++++++++++++++++++++++ pkg/controller/perconaservermongodb/mgo.go | 21 ++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 e2e-tests/split-horizon/conf/some-name.yml diff --git a/e2e-tests/functions b/e2e-tests/functions index 88c5910fc2..73367f445d 100755 --- a/e2e-tests/functions +++ b/e2e-tests/functions @@ -1166,6 +1166,7 @@ wait_cluster_consistency() { echo -n . sleep 10 done + echo } run_backup() { diff --git a/e2e-tests/split-horizon/conf/some-name.yml b/e2e-tests/split-horizon/conf/some-name.yml new file mode 100644 index 0000000000..6d484eae56 --- /dev/null +++ b/e2e-tests/split-horizon/conf/some-name.yml @@ -0,0 +1,33 @@ +apiVersion: psmdb.percona.com/v1 +kind: PerconaServerMongoDB +metadata: + name: some-name +spec: + #platform: openshift + image: + imagePullPolicy: Always + backup: + enabled: false + image: perconalab/percona-server-mongodb-operator:main-backup + replsets: + - name: rs0 + size: 3 + expose: + enabled: true + exposeType: ClusterIP + affinity: + antiAffinityTopologyKey: none + resources: + limits: + cpu: 500m + memory: 0.5G + requests: + cpu: 100m + memory: 0.1G + volumeSpec: + persistentVolumeClaim: + resources: + requests: + storage: 1Gi + secrets: + users: some-users \ No newline at end of file diff --git a/pkg/controller/perconaservermongodb/mgo.go b/pkg/controller/perconaservermongodb/mgo.go index eacf2be296..71455c8dee 100644 --- a/pkg/controller/perconaservermongodb/mgo.go +++ b/pkg/controller/perconaservermongodb/mgo.go @@ -260,6 +260,15 @@ func (r *ReconcilePerconaServerMongoDB) updateConfigMembers(ctx context.Context, return 0, errors.Wrap(err, "get mongo config") } + existingHorizons := make([]string, 0) + for _, member := range cnf.Members { + if len(member.Horizons) > 0 { + for name := range member.Horizons { + existingHorizons = append(existingHorizons, name) + } + } + } + members := mongo.ConfigMembers{} for key, pod := range pods.Items { if key >= mongo.MaxMembers { @@ -294,6 +303,18 @@ func (r *ReconcilePerconaServerMongoDB) updateConfigMembers(ctx context.Context, Votes: mongo.DefaultVotes, } + if len(existingHorizons) > 0 { + for _, horizon := range existingHorizons { + if _, ok := rs.Horizons[pod.Name][horizon]; !ok { + return 0, errors.Errorf("horizon %s is missing for pod %s", horizon, pod.Name) + } + + member.Horizons = map[string]string{ + horizon: rs.Horizons[pod.Name][horizon], + } + } + } + switch pod.Labels["app.kubernetes.io/component"] { case "arbiter": member.ArbiterOnly = true