Skip to content

Commit 935b8d0

Browse files
authored
K8SPSMDB-946: Improve backup status (#1321)
1 parent 76af5fd commit 935b8d0

File tree

10 files changed

+45
-0
lines changed

10 files changed

+45
-0
lines changed

config/crd/bases/psmdb.percona.com_perconaservermongodbbackups.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ spec:
9999
type: string
100100
pbmName:
101101
type: string
102+
pbmPod:
103+
type: string
102104
replsetNames:
103105
items:
104106
type: string

config/crd/bases/psmdb.percona.com_perconaservermongodbrestores.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ spec:
6969
type: string
7070
pbmName:
7171
type: string
72+
pbmPod:
73+
type: string
7274
replsetNames:
7375
items:
7476
type: string

deploy/bundle.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ spec:
9898
type: string
9999
pbmName:
100100
type: string
101+
pbmPod:
102+
type: string
101103
replsetNames:
102104
items:
103105
type: string
@@ -227,6 +229,8 @@ spec:
227229
type: string
228230
pbmName:
229231
type: string
232+
pbmPod:
233+
type: string
230234
replsetNames:
231235
items:
232236
type: string

deploy/crd.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ spec:
9898
type: string
9999
pbmName:
100100
type: string
101+
pbmPod:
102+
type: string
101103
replsetNames:
102104
items:
103105
type: string
@@ -227,6 +229,8 @@ spec:
227229
type: string
228230
pbmName:
229231
type: string
232+
pbmPod:
233+
type: string
230234
replsetNames:
231235
items:
232236
type: string

deploy/cw-bundle.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ spec:
9898
type: string
9999
pbmName:
100100
type: string
101+
pbmPod:
102+
type: string
101103
replsetNames:
102104
items:
103105
type: string
@@ -227,6 +229,8 @@ spec:
227229
type: string
228230
pbmName:
229231
type: string
232+
pbmPod:
233+
type: string
230234
replsetNames:
231235
items:
232236
type: string

e2e-tests/version-service/conf/crd.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ spec:
9898
type: string
9999
pbmName:
100100
type: string
101+
pbmPod:
102+
type: string
101103
replsetNames:
102104
items:
103105
type: string
@@ -227,6 +229,8 @@ spec:
227229
type: string
228230
pbmName:
229231
type: string
232+
pbmPod:
233+
type: string
230234
replsetNames:
231235
items:
232236
type: string

pkg/apis/psmdb/v1/perconaservermongodbbackup_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ type PerconaServerMongoDBBackupStatus struct {
4545
Azure *BackupStorageAzureSpec `json:"azure,omitempty"`
4646
ReplsetNames []string `json:"replsetNames,omitempty"`
4747
PBMname string `json:"pbmName,omitempty"`
48+
PBMPod string `json:"pbmPod,omitempty"`
4849
Error string `json:"error,omitempty"`
4950
}
5051

pkg/controller/perconaservermongodbbackup/backup.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,12 @@ func (b *Backup) Status(ctx context.Context, cr *api.PerconaServerMongoDBBackup)
164164
}
165165
status.Type = cr.Spec.Type
166166

167+
node, err := b.pbm.Node()
168+
if err != nil {
169+
return status, nil
170+
}
171+
status.PBMPod = node
172+
167173
return status, nil
168174
}
169175

pkg/psmdb/backup/fake/pbm.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,7 @@ func (p *fakePBM) GetConfigVar(key string) (any, error) {
7171
func (p *fakePBM) DeleteConfigVar(key string) error {
7272
return nil
7373
}
74+
75+
func (p *fakePBM) Node() (string, error) {
76+
return "", nil
77+
}

pkg/psmdb/backup/pbm.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type pbmC struct {
3838
*pbm.PBM
3939
k8c client.Client
4040
namespace string
41+
rsName string
4142
}
4243

4344
type PBM interface {
@@ -62,6 +63,8 @@ type PBM interface {
6263
SetConfigVar(key, val string) error
6364
GetConfigVar(key string) (any, error)
6465
DeleteConfigVar(key string) error
66+
67+
Node() (string, error)
6568
}
6669

6770
func getMongoUri(ctx context.Context, k8sclient client.Client, cr *api.PerconaServerMongoDB, addrs []string) (string, error) {
@@ -159,6 +162,7 @@ func NewPBM(ctx context.Context, c client.Client, cluster *api.PerconaServerMong
159162
PBM: pbmc,
160163
k8c: c,
161164
namespace: cluster.Namespace,
165+
rsName: rs.Name,
162166
}, nil
163167
}
164168

@@ -478,3 +482,13 @@ func (b *pbmC) GetPITRChunkContains(ctx context.Context, unixTS int64) (*pbm.Opl
478482

479483
return c, nil
480484
}
485+
486+
// Node returns replset node chosen to run the backup
487+
func (p *pbmC) Node() (string, error) {
488+
lock, err := p.GetLockData(&pbm.LockHeader{Replset: p.rsName})
489+
if err != nil {
490+
return "", err
491+
}
492+
493+
return strings.Split(lock.Node, ".")[0], nil
494+
}

0 commit comments

Comments
 (0)