Skip to content

Commit

Permalink
Merge branch 'main' into remove-s3-dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
fabio-silva authored May 23, 2024
2 parents 15d3180 + 1432e63 commit 6e551fa
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
21 changes: 21 additions & 0 deletions api/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ var (
errInvalidVersion = errors.New("invalid database engine version provided")
errDBEngineMajorVersionUpgrade = errors.New("database engine cannot be upgraded to a major version")
errDBEngineDowngrade = errors.New("database engine version cannot be downgraded")
errDuplicatedSchedules = errors.New("duplicated backup schedules are not allowed")

//nolint:gochecknoglobals
operatorEngine = map[everestv1alpha1.EngineType]string{
Expand Down Expand Up @@ -747,6 +748,26 @@ func validateBackupSpec(cluster *DatabaseCluster) error {
return errScheduleNoBackupStorageName
}
}
return checkDuplicateSchedules(*cluster.Spec.Backup.Schedules)
}

type apiSchedule []struct {
BackupStorageName string `json:"backupStorageName"`
Enabled bool `json:"enabled"`
Name string `json:"name"`
RetentionCopies *int32 `json:"retentionCopies,omitempty"`
Schedule string `json:"schedule"`
}

func checkDuplicateSchedules(schedules apiSchedule) error {
m := make(map[string]struct{})
for _, s := range schedules {
key := s.Schedule + s.BackupStorageName
if _, ok := m[key]; ok {
return errDuplicatedSchedules
}
m[key] = struct{}{}
}
return nil
}

Expand Down
5 changes: 5 additions & 0 deletions api/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,11 @@ func TestValidateBackupSpec(t *testing.T) {
cluster: []byte(`{"spec": {"backup": {"enabled": true, "schedules": [{"enabled": true, "name": "name"}]}}}`),
err: errScheduleNoBackupStorageName,
},
{
name: "errDuplicatedSchedules",
cluster: []byte(`{"spec": {"backup": {"enabled": true, "schedules": [{"schedule": "0 0 * * *", "name": "name"}, {"schedule": "0 0 * * *", "name": "name"}]}}}`),
err: errDuplicatedSchedules,
},
{
name: "valid spec",
cluster: []byte(`{"spec": {"backup": {"enabled": true, "schedules": [{"enabled": true, "name": "name", "backupStorageName": "some"}]}}}`),
Expand Down

0 comments on commit 6e551fa

Please sign in to comment.