Skip to content

Commit b391dbd

Browse files
authored
Merge pull request #1439 from dougm/vcsim-refactor
Adjust to govmomi simulator breaking changes
2 parents 9f6fbd6 + f2896ac commit b391dbd

File tree

11 files changed

+65
-62
lines changed

11 files changed

+65
-62
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ require (
1818
github.com/vmware-tanzu/nsx-operator/pkg/apis v0.0.0-20240827061921-8f0982975508
1919
github.com/vmware-tanzu/nsx-operator/pkg/client v0.0.0-20240827061921-8f0982975508
2020
github.com/vmware-tanzu/vm-operator/api v1.8.6
21-
github.com/vmware/govmomi v0.48.0
21+
github.com/vmware/govmomi v0.49.0
2222
github.com/vmware/vsphere-automation-sdk-go/lib v0.7.0
2323
github.com/vmware/vsphere-automation-sdk-go/runtime v0.7.0
2424
github.com/vmware/vsphere-automation-sdk-go/services/nsxt v0.12.0
@@ -66,7 +66,7 @@ require (
6666
github.com/google/btree v1.0.1 // indirect
6767
github.com/google/cel-go v0.22.0 // indirect
6868
github.com/google/gnostic-models v0.6.8 // indirect
69-
github.com/google/go-cmp v0.6.0 // indirect
69+
github.com/google/go-cmp v0.7.0 // indirect
7070
github.com/google/gofuzz v1.2.0 // indirect
7171
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
7272
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ github.com/google/cel-go v0.22.0/go.mod h1:BuznPXXfQDpXKWQ9sPW3TzlAJN5zzFe+i9tIs
7979
github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I=
8080
github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U=
8181
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
82-
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
83-
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
82+
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
83+
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
8484
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
8585
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
8686
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
@@ -175,8 +175,8 @@ github.com/vmware-tanzu/nsx-operator/pkg/client v0.0.0-20240827061921-8f09829755
175175
github.com/vmware-tanzu/nsx-operator/pkg/client v0.0.0-20240827061921-8f0982975508/go.mod h1:Hsn4QLNjQA6wQYGI6IlQJrTqM+29KWCVdyFgS7a2Sck=
176176
github.com/vmware-tanzu/vm-operator/api v1.8.6 h1:NIndORjcnSmIlQsCMIewpIwg/ocRVDh2lYjOroTVLrU=
177177
github.com/vmware-tanzu/vm-operator/api v1.8.6/go.mod h1:HHA2SNI9B5Yqtyp5t+Gt9WTWBi/fIkM6+MukDDSf11A=
178-
github.com/vmware/govmomi v0.48.0 h1:CP5bCvkDNGkmn29UlcJKTWMLwDg3iusP8anrZnedWrg=
179-
github.com/vmware/govmomi v0.48.0/go.mod h1:bYwUHpGpisE4AOlDl5eph90T+cjJMIcKx/kaa5v5rQM=
178+
github.com/vmware/govmomi v0.49.0 h1:M80ExmFq3kOfeMvMJcHnXgA/4w5hUAFfYfc+Qm3lmPg=
179+
github.com/vmware/govmomi v0.49.0/go.mod h1:+oZ0tYJw/pXKoeWHLR9Egq5KENVr2hLePRzisFhEWpA=
180180
github.com/vmware/vsphere-automation-sdk-go/lib v0.7.0 h1:pT+oqJ8FD5eUBQkl+e7LZwwtbwPvW5kDyyGXvt66gOM=
181181
github.com/vmware/vsphere-automation-sdk-go/lib v0.7.0/go.mod h1:f3+6YVZpNcK2pYyiQ94BoHWmjMj9BnYav0vNFuTiDVM=
182182
github.com/vmware/vsphere-automation-sdk-go/runtime v0.7.0 h1:pSBxa9Agh6bgW8Hr0A1eQxuwnxGTnuAVox8iQb023hg=

pkg/cloudprovider/vsphere/instances_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ func TestInstance(t *testing.T) {
7575
/*
7676
* Setup
7777
*/
78-
connMgr := cm.NewConnectionManager(cfg, nil, nil)
78+
connMgr := cm.NewConnectionManager(&cfg.Config, nil, nil)
7979
nm := newMyNodeManager(connMgr)
8080
instances := newInstances(&nm.NodeManager)
8181

82-
vm := simulator.Map.Any("VirtualMachine").(*simulator.VirtualMachine)
82+
vm := cfg.Map.Any("VirtualMachine").(*simulator.VirtualMachine)
8383
name := strings.ToLower(vm.Name)
8484
vm.Guest.HostName = name
8585
vm.Guest.Net = []vimtypes.GuestNicInfo{
@@ -160,7 +160,7 @@ func TestInvalidInstance(t *testing.T) {
160160
/*
161161
* Setup
162162
*/
163-
connMgr := cm.NewConnectionManager(cfg, nil, nil)
163+
connMgr := cm.NewConnectionManager(&cfg.Config, nil, nil)
164164
nm := newMyNodeManager(connMgr)
165165
instances := newInstances(&nm.NodeManager)
166166

pkg/cloudprovider/vsphere/nodemanager_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ func TestRegUnregNode(t *testing.T) {
4141
cfg, ok := configFromEnvOrSim(true)
4242
defer ok()
4343

44-
connMgr := cm.NewConnectionManager(cfg, nil, nil)
44+
connMgr := cm.NewConnectionManager(&cfg.Config, nil, nil)
4545
defer connMgr.Logout()
4646

4747
nm := newNodeManager(nil, connMgr)
4848

49-
vm := simulator.Map.Any("VirtualMachine").(*simulator.VirtualMachine)
49+
vm := cfg.Map.Any("VirtualMachine").(*simulator.VirtualMachine)
5050
vm.Guest.HostName = vm.Name
5151
vm.Guest.Net = []vimtypes.GuestNicInfo{
5252
{
@@ -99,12 +99,12 @@ func TestDiscoverNodeByName(t *testing.T) {
9999
cfg, ok := configFromEnvOrSim(true)
100100
defer ok()
101101

102-
connMgr := cm.NewConnectionManager(cfg, nil, nil)
102+
connMgr := cm.NewConnectionManager(&cfg.Config, nil, nil)
103103
defer connMgr.Logout()
104104

105105
nm := newNodeManager(nil, connMgr)
106106

107-
vm := simulator.Map.Any("VirtualMachine").(*simulator.VirtualMachine)
107+
vm := cfg.Map.Any("VirtualMachine").(*simulator.VirtualMachine)
108108
vm.Guest.HostName = strings.ToLower(vm.Name) // simulator.SearchIndex.FindByDnsName matches against the guest.hostName property
109109
vm.Guest.Net = []vimtypes.GuestNicInfo{
110110
{
@@ -137,12 +137,12 @@ func TestDiscoverNodeByNameWithNamesClash(t *testing.T) {
137137
cfg, ok := configFromEnvOrSim(true)
138138
defer ok()
139139

140-
connMgr := cm.NewConnectionManager(cfg, nil, nil)
140+
connMgr := cm.NewConnectionManager(&cfg.Config, nil, nil)
141141
defer connMgr.Logout()
142142

143143
nm := newNodeManager(nil, connMgr)
144144

145-
vms := simulator.Map.All("VirtualMachine")
145+
vms := cfg.Map.All("VirtualMachine")
146146
vmOne := vms[0].(*simulator.VirtualMachine)
147147
vmOne.Guest.HostName = vmHostname
148148
vmTwo := vms[1].(*simulator.VirtualMachine)
@@ -167,12 +167,12 @@ func TestDiscoverNodeWithMultiIFByName(t *testing.T) {
167167
cfg, ok := configFromEnvOrSim(true)
168168
defer ok()
169169

170-
connMgr := cm.NewConnectionManager(cfg, nil, nil)
170+
connMgr := cm.NewConnectionManager(&cfg.Config, nil, nil)
171171
defer connMgr.Logout()
172172

173173
nm := newNodeManager(nil, connMgr)
174174

175-
vm := simulator.Map.Any("VirtualMachine").(*simulator.VirtualMachine)
175+
vm := cfg.Map.Any("VirtualMachine").(*simulator.VirtualMachine)
176176
vm.Guest.HostName = strings.ToLower(vm.Name) // simulator.SearchIndex.FindByDnsName matches against the guest.hostName property
177177
expectedIP := "10.10.108.12"
178178
vm.Guest.Net = []vimtypes.GuestNicInfo{
@@ -1828,12 +1828,12 @@ func TestDiscoverNodeIPs(t *testing.T) {
18281828
defer fin()
18291829

18301830
cfg.VirtualCenter[cfg.Global.VCenterIP].IPFamilyPriority = testcase.setup.ipFamilyPriority
1831-
connMgr := cm.NewConnectionManager(cfg, nil, nil)
1831+
connMgr := cm.NewConnectionManager(&cfg.Config, nil, nil)
18321832
defer connMgr.Logout()
18331833

18341834
nm := newNodeManager(testcase.setup.cpiConfig, connMgr)
18351835

1836-
vm := simulator.Map.Any("VirtualMachine").(*simulator.VirtualMachine)
1836+
vm := cfg.Map.Any("VirtualMachine").(*simulator.VirtualMachine)
18371837
vm.Guest.HostName = strings.ToLower(vm.Name) // simulator.SearchIndex.FindByDnsName matches against the guest.hostName property
18381838
vm.Guest.Net = testcase.setup.networks
18391839
if testcase.setup.guestinfo != "" {

pkg/cloudprovider/vsphere/vsphere_test.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,23 @@ bGWObufAR8Ni4QIgWpILjW8dkGg8GOUZ0zaNA6Nvt6TIv2UWGJ4v5PoV98kCIQDx
6262
rIiZs5QbKdycsv9gQJzwQAogC8o04X3Zz3dsoX+h4A==
6363
-----END RSA PRIVATE KEY-----`
6464

65+
type TestConfig struct {
66+
vcfg.Config
67+
68+
Map *simulator.Registry
69+
}
70+
6571
// configFromSim starts a vcsim instance and returns config for use against the vcsim instance.
6672
// The vcsim instance is configured with an empty tls.Config.
67-
func configFromSim(multiDc bool) (*vcfg.Config, func()) {
73+
func configFromSim(multiDc bool) (*TestConfig, func()) {
6874
return configFromSimWithTLS(new(tls.Config), true, multiDc)
6975
}
7076

7177
// configFromSimWithTLS starts a vcsim instance and returns config for use against the vcsim instance.
7278
// The vcsim instance is configured with a tls.Config. The returned client
7379
// config can be configured to allow/decline insecure connections.
74-
func configFromSimWithTLS(tlsConfig *tls.Config, insecureAllowed bool, multiDc bool) (*vcfg.Config, func()) {
75-
cfg := &vcfg.Config{}
80+
func configFromSimWithTLS(tlsConfig *tls.Config, insecureAllowed bool, multiDc bool) (*TestConfig, func()) {
81+
cfg := &TestConfig{}
7682
model := simulator.VPX()
7783

7884
if multiDc {
@@ -87,6 +93,8 @@ func configFromSimWithTLS(tlsConfig *tls.Config, insecureAllowed bool, multiDc b
8793
log.Fatal(err)
8894
}
8995

96+
cfg.Map = model.Map()
97+
9098
// Adds vAPI, STS, Lookup Service endpoints to vcsim
9199
model.Service.RegisterEndpoints = true
92100

@@ -128,7 +136,7 @@ func configFromSimWithTLS(tlsConfig *tls.Config, insecureAllowed bool, multiDc b
128136
}
129137

130138
// configFromEnvOrSim builds a config from configFromSim and overrides using configFromEnv
131-
func configFromEnvOrSim(multiDc bool) (*vcfg.Config, func()) {
139+
func configFromEnvOrSim(multiDc bool) (*TestConfig, func()) {
132140
cfg, fin := configFromSim(multiDc)
133141
if err := cfg.FromEnv(); err != nil {
134142
return nil, nil
@@ -152,7 +160,7 @@ func TestVSphereLogin(t *testing.T) {
152160
initCfg, cleanup := configFromEnvOrSim(false)
153161
defer cleanup()
154162
cfg := &ccfg.CPIConfig{}
155-
cfg.Config = *initCfg
163+
cfg.Config = initCfg.Config
156164

157165
// Create vSphere configuration object
158166
vs, err := newVSphere(cfg, nil, nil, nil)
@@ -183,7 +191,7 @@ func TestVSphereLoginByToken(t *testing.T) {
183191
initCfg, cleanup := configFromEnvOrSim(false)
184192
defer cleanup()
185193
cfg := &ccfg.CPIConfig{}
186-
cfg.Config = *initCfg
194+
cfg.Config = initCfg.Config
187195

188196
// Configure for SAML token auth
189197
cfg.Global.User = localhostCert

pkg/cloudprovider/vsphere/zones_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func TestZones(t *testing.T) {
4545
cfg.Global.Password = localhostKey
4646

4747
// Create configuration object
48-
connMgr := cm.NewConnectionManager(cfg, nil, nil)
48+
connMgr := cm.NewConnectionManager(&cfg.Config, nil, nil)
4949
defer connMgr.Logout()
5050

5151
nm := newNodeManager(nil, connMgr)
@@ -59,7 +59,7 @@ func TestZones(t *testing.T) {
5959
vsi := connMgr.VsphereInstanceMap[cfg.Global.VCenterIP]
6060

6161
// Get a simulator VM
62-
myvm := simulator.Map.Any("VirtualMachine").(*simulator.VirtualMachine)
62+
myvm := cfg.Map.Any("VirtualMachine").(*simulator.VirtualMachine)
6363
myvm.Guest.HostName = myvm.Name
6464
myvm.Guest.Net = []types.GuestNicInfo{
6565
{
@@ -72,7 +72,7 @@ func TestZones(t *testing.T) {
7272
k8sUUID := ConvertK8sUUIDtoNormal(UUID)
7373

7474
// Get a simulator DC
75-
mydc := simulator.Map.Any("Datacenter").(*simulator.Datacenter)
75+
mydc := cfg.Map.Any("Datacenter").(*simulator.Datacenter)
7676

7777
// Add the node to the NodeManager
7878
node := &v1.Node{

pkg/common/connectionmanager/list_test.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,23 @@ import (
3232
"k8s.io/cloud-provider-vsphere/pkg/common/vclib"
3333
)
3434

35+
type TestConfig struct {
36+
vcfg.Config
37+
38+
Map *simulator.Registry
39+
}
40+
3541
// configFromSim starts a vcsim instance and returns config for use against the vcsim instance.
3642
// The vcsim instance is configured with an empty tls.Config.
37-
func configFromSim(multiDc bool) (*vcfg.Config, func()) {
43+
func configFromSim(multiDc bool) (*TestConfig, func()) {
3844
return configFromSimWithTLS(new(tls.Config), true, multiDc)
3945
}
4046

4147
// configFromSimWithTLS starts a vcsim instance and returns config for use against the vcsim instance.
4248
// The vcsim instance is configured with a tls.Config. The returned client
4349
// config can be configured to allow/decline insecure connections.
44-
func configFromSimWithTLS(tlsConfig *tls.Config, insecureAllowed bool, multiDc bool) (*vcfg.Config, func()) {
45-
cfg := &vcfg.Config{}
50+
func configFromSimWithTLS(tlsConfig *tls.Config, insecureAllowed bool, multiDc bool) (*TestConfig, func()) {
51+
cfg := &TestConfig{}
4652
model := simulator.VPX()
4753

4854
if multiDc {
@@ -57,6 +63,8 @@ func configFromSimWithTLS(tlsConfig *tls.Config, insecureAllowed bool, multiDc b
5763
log.Fatal(err)
5864
}
5965

66+
cfg.Map = model.Map()
67+
6068
// Adds vAPI, STS, Lookup Service endpoints to vcsim
6169
model.Service.RegisterEndpoints = true
6270

@@ -97,7 +105,7 @@ func configFromSimWithTLS(tlsConfig *tls.Config, insecureAllowed bool, multiDc b
97105
}
98106

99107
// configFromEnvOrSim builds a config from configFromSim and overrides using configFromEnv
100-
func configFromEnvOrSim(multiDc bool) (*vcfg.Config, func()) {
108+
func configFromEnvOrSim(multiDc bool) (*TestConfig, func()) {
101109
cfg, fin := configFromSim(multiDc)
102110
if err := cfg.FromEnv(); err != nil {
103111
return nil, nil
@@ -109,7 +117,7 @@ func TestListAllVcPairs(t *testing.T) {
109117
config, cleanup := configFromEnvOrSim(true)
110118
defer cleanup()
111119

112-
connMgr := NewConnectionManager(config, nil, nil)
120+
connMgr := NewConnectionManager(&config.Config, nil, nil)
113121
defer connMgr.Logout()
114122

115123
// context

pkg/common/connectionmanager/search_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ func TestWhichVCandDCByNodeIdByUUID(t *testing.T) {
3030
config, cleanup := configFromEnvOrSim(true)
3131
defer cleanup()
3232

33-
connMgr := NewConnectionManager(config, nil, nil)
33+
connMgr := NewConnectionManager(&config.Config, nil, nil)
3434
defer connMgr.Logout()
3535

3636
// setup
37-
vm := simulator.Map.Any("VirtualMachine").(*simulator.VirtualMachine)
37+
vm := config.Map.Any("VirtualMachine").(*simulator.VirtualMachine)
3838
name := vm.Name
3939
vm.Guest.HostName = strings.ToLower(name)
4040
UUID := vm.Config.Uuid
@@ -62,11 +62,11 @@ func TestWhichVCandDCByNodeIdByName(t *testing.T) {
6262
config, cleanup := configFromEnvOrSim(true)
6363
defer cleanup()
6464

65-
connMgr := NewConnectionManager(config, nil, nil)
65+
connMgr := NewConnectionManager(&config.Config, nil, nil)
6666
defer connMgr.Logout()
6767

6868
// setup
69-
vm := simulator.Map.Any("VirtualMachine").(*simulator.VirtualMachine)
69+
vm := config.Map.Any("VirtualMachine").(*simulator.VirtualMachine)
7070
name := vm.Name
7171
vm.Guest.HostName = strings.ToLower(name)
7272
UUID := vm.Config.Uuid
@@ -94,7 +94,7 @@ func TestWhichVCandDCByFCDId(t *testing.T) {
9494
config, cleanup := configFromEnvOrSim(true)
9595
defer cleanup()
9696

97-
connMgr := NewConnectionManager(config, nil, nil)
97+
connMgr := NewConnectionManager(&config.Config, nil, nil)
9898
defer connMgr.Logout()
9999

100100
// context
@@ -104,7 +104,7 @@ func TestWhichVCandDCByFCDId(t *testing.T) {
104104
* Setup
105105
*/
106106
// Get a simulator DS
107-
myds := simulator.Map.Any("Datastore").(*simulator.Datastore)
107+
myds := config.Map.Any("Datastore").(*simulator.Datastore)
108108

109109
items, err := connMgr.ListAllVCandDCPairs(ctx)
110110
if err != nil {

pkg/common/connectionmanager/zones_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func TestWhichVCandDCByZoneSingleDC(t *testing.T) {
3333
config, cleanup := configFromEnvOrSim(false)
3434
defer cleanup()
3535

36-
connMgr := NewConnectionManager(config, nil, nil)
36+
connMgr := NewConnectionManager(&config.Config, nil, nil)
3737
defer connMgr.Logout()
3838

3939
// context
@@ -56,7 +56,7 @@ func TestWhichVCandDCByZoneMultiDC(t *testing.T) {
5656
config, cleanup := configFromEnvOrSim(true)
5757
defer cleanup()
5858

59-
connMgr := NewConnectionManager(config, nil, nil)
59+
connMgr := NewConnectionManager(&config.Config, nil, nil)
6060
defer connMgr.Logout()
6161

6262
// context
@@ -163,7 +163,7 @@ func TestLookupZoneByMoref(t *testing.T) {
163163
config, cleanup := configFromEnvOrSim(false)
164164
defer cleanup()
165165

166-
connMgr := NewConnectionManager(config, nil, nil)
166+
connMgr := NewConnectionManager(&config.Config, nil, nil)
167167
defer connMgr.Logout()
168168

169169
// context
@@ -190,7 +190,7 @@ func TestLookupZoneByMoref(t *testing.T) {
190190
* START SETUP
191191
*/
192192
// Get a simulator Host
193-
myHost := simulator.Map.Any("HostSystem").(*simulator.HostSystem)
193+
myHost := config.Map.Any("HostSystem").(*simulator.HostSystem)
194194

195195
// Create a region category
196196
regionID, err := m.CreateCategory(ctx, &tags.Category{Name: config.Labels.Region})

0 commit comments

Comments
 (0)