Skip to content

Commit 1160ce9

Browse files
committed
Fix UT errors
Signed-off-by: Gong Zhang <[email protected]>
1 parent 8cc8e8a commit 1160ce9

File tree

4 files changed

+33
-10
lines changed

4 files changed

+33
-10
lines changed

controllers/vmware/virtualmachinegroup_reconciler_test.go

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2025 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
package vmware
218

319
import (
@@ -23,8 +39,6 @@ import (
2339
"sigs.k8s.io/controller-runtime/pkg/reconcile"
2440
)
2541

26-
var s = runtime.NewScheme()
27-
2842
const (
2943
clusterName = "test-cluster"
3044
clusterNamespace = "test-ns"
@@ -38,6 +52,9 @@ func TestGetExpectedVSphereMachines(t *testing.T) {
3852
g := NewWithT(t)
3953
ctx := context.Background()
4054

55+
scheme := runtime.NewScheme()
56+
g.Expect(clusterv1.AddToScheme(scheme)).To(Succeed())
57+
4158
tests := []struct {
4259
name string
4360
cluster *clusterv1.Cluster
@@ -65,7 +82,7 @@ func TestGetExpectedVSphereMachines(t *testing.T) {
6582
}
6683

6784
for _, tt := range tests {
68-
fakeClient := fake.NewClientBuilder().WithScheme(s).WithObjects(tt.cluster).Build()
85+
fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(tt.cluster).Build()
6986
t.Run(tt.name, func(t *testing.T) {
7087
g.Expect(getExpectedVSphereMachines(ctx, fakeClient, tt.cluster)).To(Equal(tt.expected))
7188
})
@@ -76,6 +93,9 @@ func TestGetCurrentVSphereMachines(t *testing.T) {
7693
g := NewWithT(t)
7794
ctx := context.Background()
7895

96+
scheme := runtime.NewScheme()
97+
g.Expect(vmwarev1.AddToScheme(scheme)).To(Succeed())
98+
7999
// VM names are based on CAPI Machine names, not VSphereMachine names, but we use VSphereMachine here.
80100
vsm1 := newVSphereMachine("vsm-1", mdName1, false, nil)
81101
vsm2 := newVSphereMachine("vsm-2", mdName2, false, nil)
@@ -107,7 +127,7 @@ func TestGetCurrentVSphereMachines(t *testing.T) {
107127

108128
for _, tt := range tests {
109129
t.Run(tt.name, func(t *testing.T) {
110-
fakeClient := fake.NewClientBuilder().WithScheme(s).WithObjects(tt.objects...).Build()
130+
fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(tt.objects...).Build()
111131
got, err := getCurrentVSphereMachines(ctx, fakeClient, clusterNamespace, clusterName)
112132
g.Expect(err).NotTo(HaveOccurred())
113133
g.Expect(len(got)).To(Equal(tt.want))
@@ -240,6 +260,10 @@ func TestVirtualMachineGroupReconciler_ReconcileFlow(t *testing.T) {
240260
g := NewWithT(t)
241261
ctx := context.Background()
242262

263+
scheme := runtime.NewScheme()
264+
g.Expect(clusterv1.AddToScheme(scheme)).To(Succeed())
265+
g.Expect(vmwarev1.AddToScheme(scheme)).To(Succeed())
266+
243267
// Initial objects for the successful VMG creation path (Expected: 1, Current: 1)
244268
cluster := newCluster(clusterName, clusterNamespace, true, 1, 0)
245269
vsm1 := newVSphereMachine("vsm-1", mdName1, false, nil)
@@ -313,7 +337,7 @@ func TestVirtualMachineGroupReconciler_ReconcileFlow(t *testing.T) {
313337

314338
for _, tt := range tests {
315339
t.Run(tt.name, func(t *testing.T) {
316-
fakeClient := fake.NewClientBuilder().WithScheme(s).WithObjects(tt.initialObjects...).Build()
340+
fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(tt.initialObjects...).Build()
317341
reconciler := &VirtualMachineGroupReconciler{
318342
Client: fakeClient,
319343
Recorder: record.NewFakeRecorder(1),

controllers/vspherecluster_reconciler.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,6 @@ func (r *clusterReconciler) reconcileDeploymentZones(ctx context.Context, cluste
427427
failureDomains := clusterv1beta1.FailureDomains{}
428428
for _, zone := range deploymentZoneList.Items {
429429
if zone.Spec.Server != clusterCtx.VSphereCluster.Spec.Server {
430-
431430
continue
432431
}
433432

test/go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ replace sigs.k8s.io/cluster-api-provider-vsphere => ../
1010

1111
replace github.com/vmware-tanzu/vm-operator/pkg/constants/testlabels => github.com/vmware-tanzu/vm-operator/pkg/constants/testlabels v1.9.1-0.20251003150112-9b458d311c4c
1212

13-
// The version of vm-operator should be kept in sync with the manifests at: config/deployments/integration-testsz
14-
replace github.com/vmware-tanzu/vm-operator/api => github.com/vmware-tanzu/vm-operator/api v1.8.6
13+
// The version of vm-operator should be kept in sync with the manifests at: config/deployments/integration-tests
14+
replace github.com/vmware-tanzu/vm-operator/api => github.com/vmware-tanzu/vm-operator/api v1.9.1-0.20251003150112-9b458d311c4c
1515

1616
require (
1717
github.com/vmware-tanzu/net-operator-api v0.0.0-20240326163340-1f32d6bf7f9d

test/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,8 @@ github.com/vmware-tanzu/net-operator-api v0.0.0-20240326163340-1f32d6bf7f9d h1:c
360360
github.com/vmware-tanzu/net-operator-api v0.0.0-20240326163340-1f32d6bf7f9d/go.mod h1:JbFOh22iDsT5BowJe0GgpMI5e2/S7cWaJlv9LdURVQM=
361361
github.com/vmware-tanzu/nsx-operator/pkg/apis v0.0.0-20241112044858-9da8637c1b0d h1:z9lrzKVtNlujduv9BilzPxuge/LE2F0N1ms3TP4JZvw=
362362
github.com/vmware-tanzu/nsx-operator/pkg/apis v0.0.0-20241112044858-9da8637c1b0d/go.mod h1:Q4JzNkNMvjo7pXtlB5/R3oME4Nhah7fAObWgghVmtxk=
363-
github.com/vmware-tanzu/vm-operator/api v1.8.6 h1:NIndORjcnSmIlQsCMIewpIwg/ocRVDh2lYjOroTVLrU=
364-
github.com/vmware-tanzu/vm-operator/api v1.8.6/go.mod h1:HHA2SNI9B5Yqtyp5t+Gt9WTWBi/fIkM6+MukDDSf11A=
363+
github.com/vmware-tanzu/vm-operator/api v1.9.1-0.20251003150112-9b458d311c4c h1:XISTT0dw/XwMlyyiOPHPsXCxfI1Ro2Zuozi6eIacXGo=
364+
github.com/vmware-tanzu/vm-operator/api v1.9.1-0.20251003150112-9b458d311c4c/go.mod h1:nWTPpxfe4gHuuYuFcrs86+NMxfkqPk3a3IlvI8TCWak=
365365
github.com/vmware-tanzu/vm-operator/external/ncp v0.0.0-20240404200847-de75746a9505 h1:y4wXx1FUFqqSgJ/xUOEM1DLS2Uu0KaeLADWpzpioGTU=
366366
github.com/vmware-tanzu/vm-operator/external/ncp v0.0.0-20240404200847-de75746a9505/go.mod h1:5rqRJ9zGR+KnKbkGx373WgN8xJpvAj99kHnfoDYRO5I=
367367
github.com/vmware/govmomi v0.52.0 h1:JyxQ1IQdllrY7PJbv2am9mRsv3p9xWlIQ66bv+XnyLw=

0 commit comments

Comments
 (0)