Skip to content

Commit

Permalink
Don't error on namespace mismatch when deleting stale VM migrations (#…
Browse files Browse the repository at this point in the history
…1384)

If there is a mismatch between the namespaces then
we don't have to clean up migrations since they are
not allowed in that scenario.

Signed-off-by: Alexander Wels <[email protected]>
  • Loading branch information
awels authored Aug 20, 2024
1 parent 16695e0 commit 0977c78
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
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

0 comments on commit 0977c78

Please sign in to comment.