mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-01-08 06:15:40 +00:00
add multiple label selector support to backup API
Signed-off-by: Shubham Pampattiwar <shubhampampattiwar7@gmail.com> remove backup CLI bits Signed-off-by: Shubham Pampattiwar <shubhampampattiwar7@gmail.com> labelselectors spec option for velero restore Signed-off-by: Shubham Pampattiwar <shubhampampattiwar7@gmail.com> add changelog file Signed-off-by: Shubham Pampattiwar <shubhampampattiwar7@gmail.com> update spec name to OrLabelSelectors Signed-off-by: Shubham Pampattiwar <shubhampampattiwar7@gmail.com> minor fixes Signed-off-by: Shubham Pampattiwar <shubhampampattiwar7@gmail.com> add validations for labelSelector and orLabelSelectors Signed-off-by: Shubham Pampattiwar <shubhampampattiwar7@gmail.com> update crds.gp after fixing conflicts Signed-off-by: Shubham Pampattiwar <shubhampampattiwar7@gmail.com> fix CI and add unit tests Signed-off-by: Shubham Pampattiwar <shubhampampattiwar7@gmail.com> updated OrLabelSelector spec description and added validation failure unit tests Signed-off-by: Shubham Pampattiwar <shubhampampattiwar7@gmail.com> add comments and change log level Signed-off-by: Shubham Pampattiwar <shubhampampattiwar7@gmail.com> update site docs Signed-off-by: Shubham Pampattiwar <shubhampampattiwar7@gmail.com> wrap pager client calls in a function Signed-off-by: Shubham Pampattiwar <shubhampampattiwar7@gmail.com> resolve confilcts and update crds.go Signed-off-by: Shubham Pampattiwar <shubhampampattiwar7@gmail.com> rebase and update crds.go Signed-off-by: Shubham Pampattiwar <shubhampampattiwar7@gmail.com> combine listing items for a given label Signed-off-by: Shubham Pampattiwar <shubhampampattiwar7@gmail.com>
This commit is contained in:
@@ -461,6 +461,11 @@ func (c *backupController) prepareBackupRequest(backup *velerov1api.Backup) *pkg
|
||||
request.Status.ValidationErrors = append(request.Status.ValidationErrors, fmt.Sprintf("Invalid included/excluded namespace lists: %v", err))
|
||||
}
|
||||
|
||||
// validate that only one exists orLabelSelector or just labelSelector (singular)
|
||||
if request.Spec.OrLabelSelectors != nil && request.Spec.LabelSelector != nil {
|
||||
request.Status.ValidationErrors = append(request.Status.ValidationErrors, fmt.Sprintf("encountered labelSelector as well as orLabelSelectors in backup spec, only one can be specified"))
|
||||
}
|
||||
|
||||
return request
|
||||
}
|
||||
|
||||
|
||||
@@ -189,6 +189,13 @@ func TestProcessBackupValidationFailures(t *testing.T) {
|
||||
backupLocation: builder.ForBackupStorageLocation("velero", "read-only").AccessMode(velerov1api.BackupStorageLocationAccessModeReadOnly).Result(),
|
||||
expectedErrs: []string{"backup can't be created because backup storage location read-only is currently in read-only mode"},
|
||||
},
|
||||
{
|
||||
name: "labelSelector as well as orLabelSelectors both are specified in backup request fails validation",
|
||||
backup: defaultBackup().LabelSelector(&metav1.LabelSelector{MatchLabels: map[string]string{"a": "b"}}).OrLabelSelector([]*metav1.LabelSelector{{MatchLabels: map[string]string{"a1": "b1"}}, {MatchLabels: map[string]string{"a2": "b2"}},
|
||||
{MatchLabels: map[string]string{"a3": "b3"}}, {MatchLabels: map[string]string{"a4": "b4"}}}).Result(),
|
||||
backupLocation: defaultBackupLocation,
|
||||
expectedErrs: []string{"encountered labelSelector as well as orLabelSelectors in backup spec, only one can be specified"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
|
||||
@@ -326,6 +326,11 @@ func (c *restoreController) validateAndComplete(restore *api.Restore, pluginMana
|
||||
restore.Status.ValidationErrors = append(restore.Status.ValidationErrors, fmt.Sprintf("Invalid included/excluded namespace lists: %v", err))
|
||||
}
|
||||
|
||||
// validate that only one exists orLabelSelector or just labelSelector (singular)
|
||||
if restore.Spec.OrLabelSelectors != nil && restore.Spec.LabelSelector != nil {
|
||||
restore.Status.ValidationErrors = append(restore.Status.ValidationErrors, fmt.Sprintf("encountered labelSelector as well as orLabelSelectors in restore spec, only one can be specified"))
|
||||
}
|
||||
|
||||
// validate that exactly one of BackupName and ScheduleName have been specified
|
||||
if !backupXorScheduleProvided(restore) {
|
||||
restore.Status.ValidationErrors = append(restore.Status.ValidationErrors, "Either a backup or schedule must be specified as a source for the restore, but not both")
|
||||
|
||||
@@ -308,6 +308,15 @@ func TestProcessQueueItem(t *testing.T) {
|
||||
expectedPhase: string(velerov1api.RestorePhaseFailedValidation),
|
||||
expectedValidationErrors: []string{"Either a backup or schedule must be specified as a source for the restore, but not both"},
|
||||
},
|
||||
{
|
||||
name: "new restore with labelSelector as well as orLabelSelector fails validation",
|
||||
location: defaultStorageLocation,
|
||||
restore: NewRestore("foo", "bar", "backup-1", "ns-1", "", velerov1api.RestorePhaseNew).LabelSelector(&metav1.LabelSelector{MatchLabels: map[string]string{"a": "b"}}).OrLabelSelector([]*metav1.LabelSelector{{MatchLabels: map[string]string{"a1": "b1"}}, {MatchLabels: map[string]string{"a2": "b2"}}, {MatchLabels: map[string]string{"a3": "b3"}}, {MatchLabels: map[string]string{"a4": "b4"}}}).Result(),
|
||||
backup: defaultBackup().StorageLocation("default").Result(),
|
||||
expectedErr: false,
|
||||
expectedValidationErrors: []string{"encountered labelSelector as well as orLabelSelectors in restore spec, only one can be specified"},
|
||||
expectedPhase: string(velerov1api.RestorePhaseFailedValidation),
|
||||
},
|
||||
{
|
||||
name: "valid restore with schedule name gets executed",
|
||||
location: defaultStorageLocation,
|
||||
|
||||
Reference in New Issue
Block a user