Skip to content

Commit

Permalink
K8SPSMDB-807: fix backups for custom replSetName (#1238)
Browse files Browse the repository at this point in the history
* fix

* fix sharding

---------

Co-authored-by: Andrii Dema <[email protected]>
  • Loading branch information
2 people authored and egegunes committed Jul 11, 2023
1 parent ca74211 commit 4553100
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
19 changes: 15 additions & 4 deletions pkg/controller/perconaservermongodb/mgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,20 +187,26 @@ func (r *ReconcilePerconaServerMongoDB) reconcileCluster(ctx context.Context, cr
return api.AppStateError, errors.Wrap(err, "set default RW concern")
}

in, err := inShard(ctx, mongosSession, replset.Name)
rsName := replset.Name
name, err := replset.CustomReplsetName()
if err == nil {
rsName = name
}

in, err := inShard(ctx, mongosSession, rsName)
if err != nil {
return api.AppStateError, errors.Wrap(err, "get shard")
}

if !in {
log.Info("adding rs to shard", "rs", replset.Name)
log.Info("adding rs to shard", "rs", rsName)

err := r.handleRsAddToShard(ctx, cr, replset, pods.Items[0], mongosPods[0])
if err != nil {
return api.AppStateError, errors.Wrap(err, "add shard")
}

log.Info("added to shard", "rs", replset.Name)
log.Info("added to shard", "rs", rsName)
}

rs := cr.Status.Replsets[replset.Name]
Expand Down Expand Up @@ -503,7 +509,12 @@ func (r *ReconcilePerconaServerMongoDB) handleRsAddToShard(ctx context.Context,
}
}()

err = mongo.AddShard(ctx, cli, replset.Name, host)
rsName := replset.Name
name, err := replset.CustomReplsetName()
if err == nil {
rsName = name
}
err = mongo.AddShard(ctx, cli, rsName, host)
if err != nil {
return errors.Wrap(err, "failed to add shard")
}
Expand Down
7 changes: 5 additions & 2 deletions pkg/controller/perconaservermongodb/psmdb_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1511,8 +1511,11 @@ func (r *ReconcilePerconaServerMongoDB) reconcileStatefulSet(
}

if cr.Spec.Backup.Enabled {
agentC := backup.AgentContainer(cr, replset.Name)
sfsSpec.Template.Spec.Containers = append(sfsSpec.Template.Spec.Containers, agentC)
rsName := replset.Name
if name, err := replset.CustomReplsetName(); err == nil {
rsName = name
}
sfsSpec.Template.Spec.Containers = append(sfsSpec.Template.Spec.Containers, backup.AgentContainer(cr, rsName))
}

pmmC := psmdb.AddPMMContainer(ctx, cr, secret, cr.Spec.PMM.MongodParams)
Expand Down

0 comments on commit 4553100

Please sign in to comment.