Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't error on namespace mismatch when deleting stale VM migrations #1384

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions pkg/controller/directvolumemigration/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ const (
progressQuery = "kubevirt_vmi_migration_data_processed_bytes{name=\"%s\"} / (kubevirt_vmi_migration_data_processed_bytes{name=\"%s\"} + kubevirt_vmi_migration_data_remaining_bytes{name=\"%s\"}) * 100"
)

var ErrVolumesDoNotMatch = errors.New("volumes do not match")
var (
ErrVolumesDoNotMatch = errors.New("volumes do not match")
ErrNamespacesDoNotMatch = errors.New("source and target namespaces must match")
)

type vmVolumes struct {
sourceVolumes []string
Expand Down Expand Up @@ -91,7 +94,7 @@ func getNamespace(colonDelimitedString string) (string, error) {
return "", fmt.Errorf("invalid namespace pair: %s", colonDelimitedString)
}
if namespacePair[0] != namespacePair[1] && namespacePair[0] != "" {
return "", fmt.Errorf("source and target namespaces must match: %s", colonDelimitedString)
return "", ErrNamespacesDoNotMatch
}
return namespacePair[0], nil
}
Expand Down Expand Up @@ -545,8 +548,10 @@ func (t *Task) deleteStaleVirtualMachineInstanceMigrations() error {

for namespacePair := range pvcMap {
namespace, err := getNamespace(namespacePair)
if err != nil {
if err != nil && !errors.Is(err, ErrNamespacesDoNotMatch) {
return err
} else if errors.Is(err, ErrNamespacesDoNotMatch) {
continue
}
vmMap, err := getVMNamesInNamespace(t.sourceClient, namespace)
if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions pkg/controller/directvolumemigration/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestTask_startLiveMigrations(t *testing.T) {
},
},
wantErr: true,
expectedReasons: []string{"source and target namespaces must match: test-namespace:test-namespace2"},
expectedReasons: []string{"source and target namespaces must match"},
},
{
name: "running VM, no volumes",
Expand Down Expand Up @@ -1425,8 +1425,7 @@ func TestTaskDeleteStaleVirtualMachineInstanceMigrations(t *testing.T) {
},
},
},
expectedError: true,
expectedMsg: "source and target namespaces must match",
expectedError: false,
},
{
name: "PVCs in same namespace, and persistent volume claims in DVM, but no VMs or VMIMs, should not return error",
Expand Down
Loading