Skip to content

Commit d76ba61

Browse files
authored
upgrade to vm operator api version a1alpha5 (#3567)
1 parent 805eec7 commit d76ba61

File tree

17 files changed

+488
-195
lines changed

17 files changed

+488
-195
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ require (
2323
github.com/pkg/sftp v1.13.6
2424
github.com/prometheus/client_golang v1.22.0
2525
github.com/stretchr/testify v1.10.0
26-
github.com/vmware-tanzu/vm-operator/api v1.8.7-0.20250729185616-b3910fb93c83
26+
github.com/vmware-tanzu/vm-operator/api v1.8.7-0.20250820184450-53a697d52f9c
2727
github.com/vmware-tanzu/vm-operator/external/byok v0.0.0-20250509154507-b93e51fc90fa
2828
github.com/vmware/govmomi v0.52.0-alpha.0.0.20250807230438-0eee109f1f2c
2929
go.uber.org/zap v1.27.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,8 @@ github.com/thecodeteam/gofsutil v0.1.2 h1:FL87mBzZeeuDMZm8hpYLFcYylQdq6bbm8UQ1oc
289289
github.com/thecodeteam/gofsutil v0.1.2/go.mod h1:7bDOpr2aMnmdm9RTdxBEeqdOr+8RpnQhsB/VUEI3DgM=
290290
github.com/tmc/grpc-websocket-proxy v0.0.0-20220101234140-673ab2c3ae75 h1:6fotK7otjonDflCTK0BCfls4SPy3NcCVb5dqqmbRknE=
291291
github.com/tmc/grpc-websocket-proxy v0.0.0-20220101234140-673ab2c3ae75/go.mod h1:KO6IkyS8Y3j8OdNO85qEYBsRPuteD+YciPomcXdrMnk=
292-
github.com/vmware-tanzu/vm-operator/api v1.8.7-0.20250729185616-b3910fb93c83 h1:EvjDjVpO5x4W/ITTjkfzdABa0NHxaqXGaasvOQfCJ2g=
293-
github.com/vmware-tanzu/vm-operator/api v1.8.7-0.20250729185616-b3910fb93c83/go.mod h1:f2zOJg30nPEsBBF0SlSw5hin1cZs2L5lDdB1t0gzqnc=
292+
github.com/vmware-tanzu/vm-operator/api v1.8.7-0.20250820184450-53a697d52f9c h1:+lECoxyxQcMsxU2CJ53YvaLEwqfGduS/3yQaLLRDYDo=
293+
github.com/vmware-tanzu/vm-operator/api v1.8.7-0.20250820184450-53a697d52f9c/go.mod h1:hkc/QZCSHcosWWMPS6VWWR12WenZcNE3BaTJ/8A8sNE=
294294
github.com/vmware-tanzu/vm-operator/external/byok v0.0.0-20250509154507-b93e51fc90fa h1:4MKu14YJ7J54O6QKmT4ds5EUpysWLLtQRMff73cVkmU=
295295
github.com/vmware-tanzu/vm-operator/external/byok v0.0.0-20250509154507-b93e51fc90fa/go.mod h1:8tiuyYslzjLIUmOlXZuGKQdQP2ZgWGCVhVeyptmZYnk=
296296
github.com/vmware/govmomi v0.52.0-alpha.0.0.20250807230438-0eee109f1f2c h1:1nMVFr1CBMSNLLjsfx3QPfZ5k0R1/O29QX/A2X0w3RQ=

pkg/common/utils/utils.go

Lines changed: 261 additions & 95 deletions
Large diffs are not rendered by default.

pkg/common/utils/utils_test.go

Lines changed: 112 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
vmoperatorv1alpha2 "github.com/vmware-tanzu/vm-operator/api/v1alpha2"
1616
vmoperatorv1alpha3 "github.com/vmware-tanzu/vm-operator/api/v1alpha3"
1717
vmoperatorv1alpha4 "github.com/vmware-tanzu/vm-operator/api/v1alpha4"
18+
vmoperatorv1alpha5 "github.com/vmware-tanzu/vm-operator/api/v1alpha5"
1819
cnssim "github.com/vmware/govmomi/cns/simulator"
1920
"github.com/vmware/govmomi/cns/types"
2021
"github.com/vmware/govmomi/simulator"
@@ -298,22 +299,22 @@ func TestListVirtualMachines(t *testing.T) {
298299
vmoperatorv1alpha1.AddToScheme,
299300
})
300301
clientBuilder.WithRuntimeObjects(namespace, otherNamespace, vm1, vm2, vm3)
301-
v1Alpha4VM1 := vmoperatorv1alpha4.VirtualMachine{
302+
v1Alpha4VM1 := vmoperatorv1alpha5.VirtualMachine{
302303
ObjectMeta: metav1.ObjectMeta{
303304
Name: "vm1",
304305
Namespace: namespace.Name,
305306
},
306307
}
307-
v1Alpha4VM2 := vmoperatorv1alpha4.VirtualMachine{
308+
v1Alpha4VM2 := vmoperatorv1alpha5.VirtualMachine{
308309
ObjectMeta: metav1.ObjectMeta{
309310
Name: "vm2",
310311
Namespace: namespace.Name,
311312
},
312313
}
313-
exp := vmoperatorv1alpha4.VirtualMachineList{
314+
exp := vmoperatorv1alpha5.VirtualMachineList{
314315
TypeMeta: metav1.TypeMeta{},
315316
ListMeta: metav1.ListMeta{},
316-
Items: []vmoperatorv1alpha4.VirtualMachine{
317+
Items: []vmoperatorv1alpha5.VirtualMachine{
317318
v1Alpha4VM1,
318319
v1Alpha4VM2,
319320
},
@@ -394,22 +395,22 @@ func TestListVirtualMachines(t *testing.T) {
394395
vmoperatorv1alpha2.AddToScheme,
395396
})
396397
clientBuilder.WithRuntimeObjects(namespace, vm1, vm2)
397-
v1Alpha4VM1 := vmoperatorv1alpha4.VirtualMachine{
398+
v1Alpha4VM1 := vmoperatorv1alpha5.VirtualMachine{
398399
ObjectMeta: metav1.ObjectMeta{
399400
Name: "vm1",
400401
Namespace: namespace.Name,
401402
},
402403
}
403-
v1Alpha4VM2 := vmoperatorv1alpha4.VirtualMachine{
404+
v1Alpha4VM2 := vmoperatorv1alpha5.VirtualMachine{
404405
ObjectMeta: metav1.ObjectMeta{
405406
Name: "vm2",
406407
Namespace: namespace.Name,
407408
},
408409
}
409-
exp := vmoperatorv1alpha4.VirtualMachineList{
410+
exp := vmoperatorv1alpha5.VirtualMachineList{
410411
TypeMeta: metav1.TypeMeta{},
411412
ListMeta: metav1.ListMeta{},
412-
Items: []vmoperatorv1alpha4.VirtualMachine{
413+
Items: []vmoperatorv1alpha5.VirtualMachine{
413414
v1Alpha4VM1,
414415
v1Alpha4VM2,
415416
},
@@ -490,22 +491,22 @@ func TestListVirtualMachines(t *testing.T) {
490491
vmoperatorv1alpha3.AddToScheme,
491492
})
492493
clientBuilder.WithRuntimeObjects(namespace, vm1, vm2)
493-
v1Alpha4VM1 := vmoperatorv1alpha4.VirtualMachine{
494+
v1Alpha4VM1 := vmoperatorv1alpha5.VirtualMachine{
494495
ObjectMeta: metav1.ObjectMeta{
495496
Name: "vm1",
496497
Namespace: namespace.Name,
497498
},
498499
}
499-
v1Alpha4VM2 := vmoperatorv1alpha4.VirtualMachine{
500+
v1Alpha4VM2 := vmoperatorv1alpha5.VirtualMachine{
500501
ObjectMeta: metav1.ObjectMeta{
501502
Name: "vm2",
502503
Namespace: namespace.Name,
503504
},
504505
}
505-
exp := vmoperatorv1alpha4.VirtualMachineList{
506+
exp := vmoperatorv1alpha5.VirtualMachineList{
506507
TypeMeta: metav1.TypeMeta{},
507508
ListMeta: metav1.ListMeta{},
508-
Items: []vmoperatorv1alpha4.VirtualMachine{
509+
Items: []vmoperatorv1alpha5.VirtualMachine{
509510
v1Alpha4VM1,
510511
v1Alpha4VM2,
511512
},
@@ -520,8 +521,7 @@ func TestListVirtualMachines(t *testing.T) {
520521
assert.True(tt, compareVirtualMachineLists(exp, *actual))
521522
})
522523
})
523-
524-
t.Run("WhenLatestCRDVersionIsV1Alpha4OrAbove", func(tt *testing.T) {
524+
t.Run("WhenLatestCRDVersionIsV1Alpha4", func(tt *testing.T) {
525525
getLatestCRDVersion = func(ctx context.Context, crdName string) (string, error) {
526526
return "v1alpha4", nil
527527
}
@@ -586,10 +586,105 @@ func TestListVirtualMachines(t *testing.T) {
586586
vmoperatorv1alpha4.AddToScheme,
587587
})
588588
clientBuilder.WithRuntimeObjects(namespace, vm1, vm2)
589-
exp := vmoperatorv1alpha4.VirtualMachineList{
589+
v1Alpha4VM1 := vmoperatorv1alpha5.VirtualMachine{
590+
ObjectMeta: metav1.ObjectMeta{
591+
Name: "vm1",
592+
Namespace: namespace.Name,
593+
},
594+
}
595+
v1Alpha4VM2 := vmoperatorv1alpha5.VirtualMachine{
596+
ObjectMeta: metav1.ObjectMeta{
597+
Name: "vm2",
598+
Namespace: namespace.Name,
599+
},
600+
}
601+
exp := vmoperatorv1alpha5.VirtualMachineList{
602+
TypeMeta: metav1.TypeMeta{},
603+
ListMeta: metav1.ListMeta{},
604+
Items: []vmoperatorv1alpha5.VirtualMachine{
605+
v1Alpha4VM1,
606+
v1Alpha4VM2,
607+
},
608+
}
609+
610+
// Execute
611+
actual, err := ListVirtualMachines(context.Background(), clientBuilder.Build(), namespace.Name)
612+
613+
// Assert
614+
assert.Nil(tt, err)
615+
assert.NotNil(tt, actual)
616+
assert.True(tt, compareVirtualMachineLists(exp, *actual))
617+
})
618+
})
619+
t.Run("WhenLatestCRDVersionIsV1Alpha5OrAbove", func(tt *testing.T) {
620+
getLatestCRDVersion = func(ctx context.Context, crdName string) (string, error) {
621+
return "v1alpha5", nil
622+
}
623+
tt.Run("WhenListFails", func(ttt *testing.T) {
624+
// Setup
625+
clientBuilder := fake.NewClientBuilder()
626+
clientBuilder.WithInterceptorFuncs(
627+
interceptor.Funcs{
628+
List: func(ctx context.Context, client client.WithWatch, list client.ObjectList,
629+
opts ...client.ListOption) error {
630+
return fmt.Errorf("failing list for testing purposes")
631+
}})
632+
633+
// Execute
634+
_, err := ListVirtualMachines(context.Background(), clientBuilder.Build(), "")
635+
636+
// Assert
637+
assert.NotNil(ttt, err)
638+
})
639+
tt.Run("WhenListSucceeds", func(ttt *testing.T) {
640+
// Setup
641+
namespace := &v1.Namespace{
642+
TypeMeta: metav1.TypeMeta{
643+
Kind: "Namespace",
644+
},
645+
ObjectMeta: metav1.ObjectMeta{
646+
Name: "namespace",
647+
},
648+
Spec: v1.NamespaceSpec{
649+
Finalizers: []v1.FinalizerName{
650+
v1.FinalizerKubernetes,
651+
},
652+
},
653+
Status: v1.NamespaceStatus{
654+
Phase: v1.NamespaceActive,
655+
},
656+
}
657+
vm1 := &vmoperatorv1alpha5.VirtualMachine{
658+
TypeMeta: metav1.TypeMeta{
659+
Kind: "VirtualMachine",
660+
APIVersion: "vmoperator.vmware.com/v1alpha5",
661+
},
662+
ObjectMeta: metav1.ObjectMeta{
663+
Name: "vm1",
664+
Namespace: namespace.Name,
665+
},
666+
}
667+
vm2 := &vmoperatorv1alpha5.VirtualMachine{
668+
TypeMeta: metav1.TypeMeta{
669+
Kind: "VirtualMachine",
670+
APIVersion: "vmoperator.vmware.com/v1alpha5",
671+
},
672+
ObjectMeta: metav1.ObjectMeta{
673+
Name: "vm2",
674+
Namespace: namespace.Name,
675+
},
676+
}
677+
clientBuilder := fake.NewClientBuilder()
678+
scheme := runtime.NewScheme()
679+
clientBuilder = registerSchemes(context.Background(), clientBuilder, scheme, runtime.SchemeBuilder{
680+
v1.AddToScheme,
681+
vmoperatorv1alpha5.AddToScheme,
682+
})
683+
clientBuilder.WithRuntimeObjects(namespace, vm1, vm2)
684+
exp := vmoperatorv1alpha5.VirtualMachineList{
590685
TypeMeta: metav1.TypeMeta{},
591686
ListMeta: metav1.ListMeta{},
592-
Items: []vmoperatorv1alpha4.VirtualMachine{
687+
Items: []vmoperatorv1alpha5.VirtualMachine{
593688
*vm1,
594689
*vm2,
595690
},
@@ -617,7 +712,7 @@ func registerSchemes(ctx context.Context, clientBuilder *fake.ClientBuilder, sch
617712
return clientBuilder
618713
}
619714

620-
func compareVirtualMachineLists(exp, actual vmoperatorv1alpha4.VirtualMachineList) bool {
715+
func compareVirtualMachineLists(exp, actual vmoperatorv1alpha5.VirtualMachineList) bool {
621716
// since the list output may not be in the same order, we will compare the items
622717
// using brute force.
623718
if len(exp.Items) != len(actual.Items) {

pkg/csi/service/wcp/controller_helper.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
"strings"
2525

2626
"github.com/container-storage-interface/spec/lib/go/csi"
27-
vmoperatorv1alpha4 "github.com/vmware-tanzu/vm-operator/api/v1alpha4"
27+
vmoperatorv1alpha5 "github.com/vmware-tanzu/vm-operator/api/v1alpha5"
2828
"github.com/vmware/govmomi/object"
2929
"github.com/vmware/govmomi/property"
3030
"github.com/vmware/govmomi/vim25/mo"
@@ -215,10 +215,10 @@ func validateWCPControllerExpandVolumeRequest(ctx context.Context, req *csi.Cont
215215
return logger.LogNewErrorCodef(log, codes.Internal,
216216
"failed to get config with error: %+v", err)
217217
}
218-
vmOperatorClient, err := k8s.NewClientForGroup(ctx, cfg, vmoperatorv1alpha4.GroupName)
218+
vmOperatorClient, err := k8s.NewClientForGroup(ctx, cfg, vmoperatorv1alpha5.GroupName)
219219
if err != nil {
220220
return logger.LogNewErrorCodef(log, codes.Internal,
221-
"failed to get client for group %s with error: %+v", vmoperatorv1alpha4.GroupName, err)
221+
"failed to get client for group %s with error: %+v", vmoperatorv1alpha5.GroupName, err)
222222
}
223223
vmList, err := utils.ListVirtualMachines(ctx, vmOperatorClient, "")
224224
if err != nil {

0 commit comments

Comments
 (0)