Skip to content

Commit

Permalink
Skip migration check on single node cluster
Browse files Browse the repository at this point in the history
Signed-off-by: Arnon Gilboa <[email protected]>
  • Loading branch information
arnongilboa committed Jun 3, 2024
1 parent 1f44acf commit c82480a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/internal/checkup/checkup.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type kubeVirtStorageClient interface {
CreateDataVolume(ctx context.Context, namespace string, dv *cdiv1.DataVolume) (*cdiv1.DataVolume, error)
DeleteDataVolume(ctx context.Context, namespace, name string) error
DeletePersistentVolumeClaim(ctx context.Context, namespace, name string) error
ListNodes(ctx context.Context) (*corev1.NodeList, error)
ListNamespaces(ctx context.Context) (*corev1.NamespaceList, error)
ListStorageClasses(ctx context.Context) (*storagev1.StorageClassList, error)
ListStorageProfiles(ctx context.Context) (*cdiv1.StorageProfileList, error)
Expand Down Expand Up @@ -93,6 +94,7 @@ const (
ErrGoldenImageNoDataSource = "dataSource has no PVC or Snapshot source"
MessageSkipNoGoldenImage = "Skip check - no golden image PVC or Snapshot"
MessageSkipNoVMI = "Skip check - no VMI"
MessageSkipSingleNode = "Skip check - single node"

pollInterval = 5 * time.Second
)
Expand Down Expand Up @@ -823,6 +825,16 @@ func (c *Checkup) checkVMILiveMigration(ctx context.Context, errStr *string) err
return nil
}

nodes, err := c.client.ListNodes(ctx)
if err != nil {
return err
}
if len(nodes.Items) == 1 {
log.Print(MessageSkipSingleNode)
c.results.VMLiveMigration = MessageSkipSingleNode
return nil
}

vmi, err := c.client.GetVirtualMachineInstance(ctx, c.namespace, c.vmUnderTest.Name)
if err != nil {
return err
Expand Down
24 changes: 24 additions & 0 deletions pkg/internal/checkup/checkup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import (

const (
testNamespace = "target-ns"
testNode = "test-node"
)

var (
Expand Down Expand Up @@ -146,6 +147,11 @@ func TestCheckupShouldReturnErrorWhen(t *testing.T) {
expectedResults: map[string]string{reporter.VMLiveMigrationKey: "failed waiting for VMI \"%s\" migration completed: migration failed"},
expectedErr: "migration failed",
},
"skipMigrationOnSingleNode": {
clientConfig: clientConfig{singleNode: true},
expectedResults: map[string]string{reporter.VMLiveMigrationKey: "Skip check - single node"},
expectedErr: "",
},
}

for name, tc := range tests {
Expand Down Expand Up @@ -247,6 +253,7 @@ type clientConfig struct {
expectNoVMI bool
cloneFallback bool
failMigration bool
singleNode bool
}

type clientStub struct {
Expand Down Expand Up @@ -403,6 +410,23 @@ func (cs *clientStub) DeletePersistentVolumeClaim(ctx context.Context, namespace
return nil
}

func (cs *clientStub) ListNodes(ctx context.Context) (*corev1.NodeList, error) {
nodeList := &corev1.NodeList{}
itemCount := 2
if cs.singleNode {
itemCount = 1
}
for i := 0; i < itemCount; i++ {
nodeList.Items = append(nodeList.Items, corev1.Node{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("node-%d", i),
},
})
}

return nodeList, nil
}

func (cs *clientStub) ListNamespaces(ctx context.Context) (*corev1.NamespaceList, error) {
nsList := &corev1.NamespaceList{
Items: []corev1.Namespace{
Expand Down
4 changes: 4 additions & 0 deletions pkg/internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ func (c *Client) DeletePersistentVolumeClaim(ctx context.Context, namespace, nam
return c.CoreV1().PersistentVolumeClaims(namespace).Delete(ctx, name, metav1.DeleteOptions{})
}

func (c *Client) ListNodes(ctx context.Context) (*corev1.NodeList, error) {
return c.CoreV1().Nodes().List(ctx, metav1.ListOptions{})
}

func (c *Client) ListNamespaces(ctx context.Context) (*corev1.NamespaceList, error) {
return c.CoreV1().Namespaces().List(ctx, metav1.ListOptions{})
}
Expand Down

0 comments on commit c82480a

Please sign in to comment.