Skip to content

Commit af550c2

Browse files
authored
K8SPSMDB-985: All PBM backup nodes in the status (#1500)
* Get pbm nodes. * Add PBMPods. * Fix fake impl. * Refactor * Use backupMeta to get backup nodes. * Get only pod name. * Refactor
1 parent 6ff1063 commit af550c2

File tree

11 files changed

+85
-16
lines changed

11 files changed

+85
-16
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ spec:
105105
type: string
106106
pbmPod:
107107
type: string
108+
pbmPods:
109+
additionalProperties:
110+
type: string
111+
type: object
108112
replsetNames:
109113
items:
110114
type: string

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ spec:
7575
type: string
7676
pbmPod:
7777
type: string
78+
pbmPods:
79+
additionalProperties:
80+
type: string
81+
type: object
7882
replsetNames:
7983
items:
8084
type: string

deploy/bundle.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ spec:
104104
type: string
105105
pbmPod:
106106
type: string
107+
pbmPods:
108+
additionalProperties:
109+
type: string
110+
type: object
107111
replsetNames:
108112
items:
109113
type: string
@@ -234,6 +238,10 @@ spec:
234238
type: string
235239
pbmPod:
236240
type: string
241+
pbmPods:
242+
additionalProperties:
243+
type: string
244+
type: object
237245
replsetNames:
238246
items:
239247
type: string

deploy/crd.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ spec:
104104
type: string
105105
pbmPod:
106106
type: string
107+
pbmPods:
108+
additionalProperties:
109+
type: string
110+
type: object
107111
replsetNames:
108112
items:
109113
type: string
@@ -234,6 +238,10 @@ spec:
234238
type: string
235239
pbmPod:
236240
type: string
241+
pbmPods:
242+
additionalProperties:
243+
type: string
244+
type: object
237245
replsetNames:
238246
items:
239247
type: string

deploy/cw-bundle.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ spec:
104104
type: string
105105
pbmPod:
106106
type: string
107+
pbmPods:
108+
additionalProperties:
109+
type: string
110+
type: object
107111
replsetNames:
108112
items:
109113
type: string
@@ -234,6 +238,10 @@ spec:
234238
type: string
235239
pbmPod:
236240
type: string
241+
pbmPods:
242+
additionalProperties:
243+
type: string
244+
type: object
237245
replsetNames:
238246
items:
239247
type: string

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ spec:
104104
type: string
105105
pbmPod:
106106
type: string
107+
pbmPods:
108+
additionalProperties:
109+
type: string
110+
type: object
107111
replsetNames:
108112
items:
109113
type: string
@@ -234,6 +238,10 @@ spec:
234238
type: string
235239
pbmPod:
236240
type: string
241+
pbmPods:
242+
additionalProperties:
243+
type: string
244+
type: object
237245
replsetNames:
238246
items:
239247
type: string

pkg/apis/psmdb/v1/perconaservermongodbbackup_types.go

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,23 @@ const (
3535

3636
// PerconaServerMongoDBBackupStatus defines the observed state of PerconaServerMongoDBBackup
3737
type PerconaServerMongoDBBackupStatus struct {
38-
Type defs.BackupType `json:"type,omitempty"`
39-
State BackupState `json:"state,omitempty"`
40-
StartAt *metav1.Time `json:"start,omitempty"`
41-
CompletedAt *metav1.Time `json:"completed,omitempty"`
42-
LastTransition *metav1.Time `json:"lastTransition,omitempty"`
43-
Destination string `json:"destination,omitempty"`
44-
StorageName string `json:"storageName,omitempty"`
45-
S3 *BackupStorageS3Spec `json:"s3,omitempty"`
46-
Azure *BackupStorageAzureSpec `json:"azure,omitempty"`
47-
ReplsetNames []string `json:"replsetNames,omitempty"`
48-
PBMname string `json:"pbmName,omitempty"`
49-
PBMPod string `json:"pbmPod,omitempty"`
50-
Error string `json:"error,omitempty"`
51-
LatestRestorableTime *metav1.Time `json:"latestRestorableTime,omitempty"`
38+
Type defs.BackupType `json:"type,omitempty"`
39+
State BackupState `json:"state,omitempty"`
40+
StartAt *metav1.Time `json:"start,omitempty"`
41+
CompletedAt *metav1.Time `json:"completed,omitempty"`
42+
LastTransition *metav1.Time `json:"lastTransition,omitempty"`
43+
Destination string `json:"destination,omitempty"`
44+
StorageName string `json:"storageName,omitempty"`
45+
S3 *BackupStorageS3Spec `json:"s3,omitempty"`
46+
Azure *BackupStorageAzureSpec `json:"azure,omitempty"`
47+
ReplsetNames []string `json:"replsetNames,omitempty"`
48+
PBMname string `json:"pbmName,omitempty"`
49+
50+
// Deprecated: Use PBMPods instead
51+
PBMPod string `json:"pbmPod,omitempty"`
52+
PBMPods map[string]string `json:"pbmPods,omitempty"`
53+
Error string `json:"error,omitempty"`
54+
LatestRestorableTime *metav1.Time `json:"latestRestorableTime,omitempty"`
5255
}
5356

5457
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

pkg/apis/psmdb/v1/zz_generated.deepcopy.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/controller/perconaservermongodbbackup/backup.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"sigs.k8s.io/controller-runtime/pkg/client"
1212
logf "sigs.k8s.io/controller-runtime/pkg/log"
1313

14+
pbmBackup "github.com/percona/percona-backup-mongodb/pbm/backup"
1415
"github.com/percona/percona-backup-mongodb/pbm/ctrl"
1516
"github.com/percona/percona-backup-mongodb/pbm/defs"
1617
pbmErrors "github.com/percona/percona-backup-mongodb/pbm/errors"
@@ -182,9 +183,28 @@ func (b *Backup) Status(ctx context.Context, cr *api.PerconaServerMongoDBBackup)
182183
}
183184
status.PBMPod = node
184185

186+
meta, err = b.pbm.GetBackupMeta(ctx, cr.Status.PBMname)
187+
if err != nil || meta == nil || meta.Replsets == nil {
188+
return status, nil
189+
}
190+
191+
status.PBMPods = backupPods(meta.Replsets)
192+
185193
return status, nil
186194
}
187195

196+
func backupPods(replsets []pbmBackup.BackupReplset) map[string]string {
197+
pods := make(map[string]string)
198+
for _, rs := range replsets {
199+
spl := strings.Split(rs.Node, ".")
200+
if len(spl) == 0 {
201+
continue
202+
}
203+
pods[rs.Name] = spl[0]
204+
}
205+
return pods
206+
}
207+
188208
// Close closes the PBM connection
189209
func (b *Backup) Close(ctx context.Context) error {
190210
if b.pbm == nil {

pkg/psmdb/backup/fake/pbm.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ func (p *fakePBM) GetConfigVar(ctx context.Context, key string) (any, error) {
7777
func (p *fakePBM) DeleteConfigVar(ctx context.Context, key string) error {
7878
return nil
7979
}
80-
8180
func (p *fakePBM) Node(ctx context.Context) (string, error) {
8281
return "", nil
8382
}

0 commit comments

Comments
 (0)