Skip to content

Commit

Permalink
update labels for scheduled backups
Browse files Browse the repository at this point in the history
  • Loading branch information
pooknull committed Jul 15, 2024
1 parent 726f0c6 commit 8632ea9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
19 changes: 13 additions & 6 deletions pkg/naming/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ const (
LabelKubernetesReplset = labelKubernetesPrefix + "replset"
)

const (
LabelBackupAncestor = perconaPrefix + "backup-ancestor"
LabelBackupType = perconaPrefix + "backup-type"
LabelCluster = perconaPrefix + "cluster"
)

func ClusterLabels(cr *api.PerconaServerMongoDB) map[string]string {
return map[string]string{
LabelKubernetesName: "percona-server-mongodb",
Expand Down Expand Up @@ -68,12 +74,13 @@ func RSLabels(cr *api.PerconaServerMongoDB, replset *api.ReplsetSpec) map[string
return ls
}

func BackupFromTaskLabels(cr *api.PerconaServerMongoDB, task *api.BackupTaskSpec) map[string]string {
return map[string]string{
"ancestor": task.Name,
"cluster": cr.Name,
"type": "cron",
}
func ScheduledBackupLabels(cr *api.PerconaServerMongoDB, task *api.BackupTaskSpec) map[string]string {
ls := ClusterLabels(cr)
ls[LabelBackupAncestor] = task.Name
ls[LabelCluster] = cr.Name
ls[LabelBackupType] = "cron"

return ls
}

func NewBackupCronJobLabels(cr *api.PerconaServerMongoDB, labels map[string]string) map[string]string {
Expand Down
3 changes: 3 additions & 0 deletions pkg/naming/naming.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package naming

const perconaPrefix = "percona.com/"
2 changes: 1 addition & 1 deletion pkg/psmdb/backup/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func BackupFromTask(cr *api.PerconaServerMongoDB, task *api.BackupTaskSpec) (*ap
ObjectMeta: metav1.ObjectMeta{
Finalizers: []string{"delete-backup"},
GenerateName: "cron-" + shortClusterName + "-" + time.Now().Format("20060102150405") + "-",
Labels: naming.BackupFromTaskLabels(cr, task),
Labels: naming.ScheduledBackupLabels(cr, task),
},
Spec: api.PerconaServerMongoDBBackupSpec{
Type: backupType,
Expand Down

0 comments on commit 8632ea9

Please sign in to comment.