Skip to content

Commit 2db282c

Browse files
committed
vsphereparavirtual: support multiple VM Operator API versions (v1alpha2, v1alpha5)
Introduce a version-agnostic Hub Type / Hub Interface layer so that CPI business logic is decoupled from any specific VM Operator API version. The correct versioned adapter is selected at startup via the --vmop-api-version flag, enabling backward compatibility with Supervisor while supporting v1alpha5.
1 parent ff7ea2e commit 2db282c

33 files changed

+3138
-906
lines changed

go.mod

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ require (
1515
github.com/stretchr/testify v1.11.1
1616
github.com/vmware-tanzu/nsx-operator/pkg/apis v0.0.0-20240827061921-8f0982975508
1717
github.com/vmware-tanzu/nsx-operator/pkg/client v0.0.0-20240827061921-8f0982975508
18-
github.com/vmware-tanzu/vm-operator/api v1.8.6
18+
github.com/vmware-tanzu/vm-operator/api v1.9.1-0.20251029150609-93918c59a719
1919
github.com/vmware/govmomi v0.53.0
2020
github.com/vmware/vsphere-automation-sdk-go/lib v0.7.0
2121
github.com/vmware/vsphere-automation-sdk-go/runtime v0.7.0
@@ -47,8 +47,6 @@ require (
4747
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
4848
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
4949
github.com/emicklei/go-restful/v3 v3.12.2 // indirect
50-
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
51-
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
5250
github.com/felixge/httpsnoop v1.0.4 // indirect
5351
github.com/fxamacker/cbor/v2 v2.9.0 // indirect
5452
github.com/gibson042/canonicaljson-go v1.0.3 // indirect
@@ -108,7 +106,6 @@ require (
108106
golang.org/x/text v0.35.0 // indirect
109107
golang.org/x/time v0.9.0 // indirect
110108
golang.org/x/tools v0.42.0 // indirect
111-
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
112109
google.golang.org/genproto/googleapis/api v0.0.0-20250303144028-a0af3efb3deb // indirect
113110
google.golang.org/genproto/googleapis/rpc v0.0.0-20250528174236-200df99c418a // indirect
114111
google.golang.org/grpc v1.72.2 // indirect
@@ -118,7 +115,6 @@ require (
118115
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
119116
gopkg.in/warnings.v0 v0.1.2 // indirect
120117
gopkg.in/yaml.v3 v3.0.1 // indirect
121-
k8s.io/apiextensions-apiserver v0.31.0-alpha.3 // indirect
122118
k8s.io/apiserver v0.36.0-alpha.0 // indirect
123119
k8s.io/component-helpers v0.36.0-alpha.0 // indirect
124120
k8s.io/controller-manager v0.36.0-alpha.0 // indirect
@@ -127,7 +123,7 @@ require (
127123
k8s.io/kube-openapi v0.0.0-20250910181357-589584f1c912 // indirect
128124
k8s.io/utils v0.0.0-20251002143259-bc988d571ff4 // indirect
129125
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.31.2 // indirect
130-
sigs.k8s.io/controller-runtime v0.18.1-0.20240717024706-fcd2fcfc974f // indirect
126+
sigs.k8s.io/controller-runtime v0.19.0 // indirect
131127
sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730 // indirect
132128
sigs.k8s.io/randfill v1.0.0 // indirect
133129
sigs.k8s.io/structured-merge-diff/v6 v6.3.0 // indirect

go.sum

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkp
3333
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
3434
github.com/emicklei/go-restful/v3 v3.12.2 h1:DhwDP0vY3k8ZzE0RunuJy8GhNpPL6zqLkDf9B/a0/xU=
3535
github.com/emicklei/go-restful/v3 v3.12.2/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
36-
github.com/evanphx/json-patch v5.6.0+incompatible h1:jBYDEEiFBPxA0v50tFdvOzQQTCvpL6mnFh5mB2/l16U=
37-
github.com/evanphx/json-patch v5.6.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
38-
github.com/evanphx/json-patch/v5 v5.9.0 h1:kcBlZQbplgElYIlo/n1hJbls2z/1awpXxpRi0/FOJfg=
39-
github.com/evanphx/json-patch/v5 v5.9.0/go.mod h1:VNkHZ/282BpEyt/tObQO8s5CMPmYYq14uClGH4abBuQ=
4036
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
4137
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
4238
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
@@ -58,7 +54,6 @@ github.com/go-openapi/jsonreference v0.21.0 h1:Rs+Y7hSXT83Jacb7kFyjn4ijOuVGSvOdF
5854
github.com/go-openapi/jsonreference v0.21.0/go.mod h1:LmZmgsrTkVg9LG4EaHeY8cBDslNPMo06cago5JNLkm4=
5955
github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE=
6056
github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ=
61-
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
6257
github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI=
6358
github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8=
6459
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
@@ -81,15 +76,12 @@ github.com/google/gnostic-models v0.7.0/go.mod h1:whL5G0m6dmc5cPxKc5bdKdEN3UjI7O
8176
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
8277
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
8378
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
84-
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
85-
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
8679
github.com/google/pprof v0.0.0-20250403155104-27863c87afa6 h1:BHT72Gu3keYf3ZEu2J0b1vyeLSOYI8bm5wbJM/8yDe8=
8780
github.com/google/pprof v0.0.0-20250403155104-27863c87afa6/go.mod h1:boTsfXsheKC2y+lKOCMpSfarhxDeIzfZG1jqGcPl3cA=
8881
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
8982
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
9083
github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674 h1:JeSE6pjso5THxAzdVpqr6/geYxZytqFMBCOtn/ujyeo=
9184
github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674/go.mod h1:r4w70xmWCQKmi1ONH4KIaBptdivuRPyosB9RmPlGEwA=
92-
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 h1:+9834+KizmvFV7pXQGSXQTsaWhq2GjuNUt0aUU0YBYw=
9385
github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.1 h1:qnpSQwGEnkcRpTqNOIR6bJbR0gAorgP9CSALpRcKoAA=
9486
github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.1/go.mod h1:lXGCsh6c22WGtjr+qGHj1otzZpV/1kwTMAqkwZsnWRU=
9587
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.3.0 h1:FbSCl+KggFl+Ocym490i/EyXF4lPgLoUtcSWquBM0Rs=
@@ -176,8 +168,8 @@ github.com/vmware-tanzu/nsx-operator/pkg/apis v0.0.0-20240827061921-8f0982975508
176168
github.com/vmware-tanzu/nsx-operator/pkg/apis v0.0.0-20240827061921-8f0982975508/go.mod h1:Q4JzNkNMvjo7pXtlB5/R3oME4Nhah7fAObWgghVmtxk=
177169
github.com/vmware-tanzu/nsx-operator/pkg/client v0.0.0-20240827061921-8f0982975508 h1:oLcoseDTk/8eVXMu74aZQWxaiMTB/ym3CP8NNQ4qRqg=
178170
github.com/vmware-tanzu/nsx-operator/pkg/client v0.0.0-20240827061921-8f0982975508/go.mod h1:Hsn4QLNjQA6wQYGI6IlQJrTqM+29KWCVdyFgS7a2Sck=
179-
github.com/vmware-tanzu/vm-operator/api v1.8.6 h1:NIndORjcnSmIlQsCMIewpIwg/ocRVDh2lYjOroTVLrU=
180-
github.com/vmware-tanzu/vm-operator/api v1.8.6/go.mod h1:HHA2SNI9B5Yqtyp5t+Gt9WTWBi/fIkM6+MukDDSf11A=
171+
github.com/vmware-tanzu/vm-operator/api v1.9.1-0.20251029150609-93918c59a719 h1:nb/5ytRj7E/5eo9UzLfaR29JytMtbGpqMVs3hjaRwZ0=
172+
github.com/vmware-tanzu/vm-operator/api v1.9.1-0.20251029150609-93918c59a719/go.mod h1:nWTPpxfe4gHuuYuFcrs86+NMxfkqPk3a3IlvI8TCWak=
181173
github.com/vmware/govmomi v0.53.0 h1:e1bZCotAq7wm4xy95ePN2uoWwz28pNp/ewZZhpBY7/4=
182174
github.com/vmware/govmomi v0.53.0/go.mod h1:EWfuzPfxT5NV+aS2we02SLFdhvJkgeY7t7+TszgBSMY=
183175
github.com/vmware/vsphere-automation-sdk-go/lib v0.7.0 h1:pT+oqJ8FD5eUBQkl+e7LZwwtbwPvW5kDyyGXvt66gOM=
@@ -299,8 +291,6 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T
299291
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
300292
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
301293
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
302-
gomodules.xyz/jsonpatch/v2 v2.4.0 h1:Ci3iUJyx9UeRx7CeFN8ARgGbkESwJK+KB9lLcWxY/Zw=
303-
gomodules.xyz/jsonpatch/v2 v2.4.0/go.mod h1:AH3dM2RI6uoBZxn3LVrfvJ3E0/9dG4cSrbuBJT4moAY=
304294
google.golang.org/genproto/googleapis/api v0.0.0-20250303144028-a0af3efb3deb h1:p31xT4yrYrSM/G4Sn2+TNUkVhFCbG9y8itM2S6Th950=
305295
google.golang.org/genproto/googleapis/api v0.0.0-20250303144028-a0af3efb3deb/go.mod h1:jbe3Bkdp+Dh2IrslsFCklNhweNTBgSYanP1UXhJDhKg=
306296
google.golang.org/genproto/googleapis/rpc v0.0.0-20250528174236-200df99c418a h1:v2PbRU4K3llS09c7zodFpNePeamkAwG3mPrAery9VeE=
@@ -329,8 +319,6 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
329319
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
330320
k8s.io/api v0.36.0-alpha.0 h1:EoMh7rigyGIWaQMbNZqbUkxUu+sp1z4MyQUEJEQQglk=
331321
k8s.io/api v0.36.0-alpha.0/go.mod h1:jy4viX7tRTr4Z3gxfupptTBIjBA04aBH19ZGKmYIrSU=
332-
k8s.io/apiextensions-apiserver v0.31.0-alpha.3 h1:VuaSODxQf/g/4DOUolhd8Qv78Cejs9XRG+rZUwBxvzY=
333-
k8s.io/apiextensions-apiserver v0.31.0-alpha.3/go.mod h1:mpm07GF4AzUOKvRYAXWcOlaJ4qF9aQW1q4OqOFNoQ4w=
334322
k8s.io/apimachinery v0.36.0-alpha.0 h1:/i3pMBfesiJMeXuFZYgrbhBRKgGlrnsgFxyk2YnuezU=
335323
k8s.io/apimachinery v0.36.0-alpha.0/go.mod h1:dR9KPaf5L0t2p9jZg/wCGB4b3ma2sXZ2zdNqILs+Sak=
336324
k8s.io/apiserver v0.36.0-alpha.0 h1:LsNSnFS6xeuo+B9PPYQqTcQklcEMjxvZ6OEhtkIU3dc=
@@ -359,8 +347,8 @@ k8s.io/utils v0.0.0-20251002143259-bc988d571ff4 h1:SjGebBtkBqHFOli+05xYbK8YF1Dzk
359347
k8s.io/utils v0.0.0-20251002143259-bc988d571ff4/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
360348
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.31.2 h1:jpcvIRr3GLoUoEKRkHKSmGjxb6lWwrBlJsXc+eUYQHM=
361349
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.31.2/go.mod h1:Ve9uj1L+deCXFrPOk1LpFXqTg7LCFzFso6PA48q/XZw=
362-
sigs.k8s.io/controller-runtime v0.18.1-0.20240717024706-fcd2fcfc974f h1:AwR3jtHAWqPmfaXqJ5BQCcyNzAXL9ErtkgQZmEW7hMc=
363-
sigs.k8s.io/controller-runtime v0.18.1-0.20240717024706-fcd2fcfc974f/go.mod h1:QQJftk3axpHTRTO/FWVxhVL/FM+NavevE+ups8lxn6g=
350+
sigs.k8s.io/controller-runtime v0.19.0 h1:nWVM7aq+Il2ABxwiCizrVDSlmDcshi9llbaFbC0ji/Q=
351+
sigs.k8s.io/controller-runtime v0.19.0/go.mod h1:iRmWllt8IlaLjvTTDLhRBXIEtkCK6hwVBJJsYS9Ajf4=
364352
sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730 h1:IpInykpT6ceI+QxKBbEflcR5EXP7sU1kvOlxwZh5txg=
365353
sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730/go.mod h1:mdzfpAEoE6DHQEN0uh9ZbOCuHbLK5wOm7dK4ctXE9Tg=
366354
sigs.k8s.io/randfill v1.0.0 h1:JfjMILfT8A6RbawdsK2JXGBR5AQVfd+9TbzrlneTyrU=

pkg/cloudprovider/vsphereparavirtual/cloud.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ import (
2222
"fmt"
2323
"io"
2424

25+
cloudprovider "k8s.io/cloud-provider"
2526
"k8s.io/klog/v2"
2627
"sigs.k8s.io/yaml"
2728

28-
cloudprovider "k8s.io/cloud-provider"
29-
3029
"k8s.io/cloud-provider-vsphere/pkg/cloudprovider/vsphereparavirtual/config"
3130
"k8s.io/cloud-provider-vsphere/pkg/cloudprovider/vsphereparavirtual/controllers/routablepod"
31+
"k8s.io/cloud-provider-vsphere/pkg/cloudprovider/vsphereparavirtual/vmoperator/factory"
3232
"k8s.io/cloud-provider-vsphere/pkg/cloudprovider/vsphereparavirtual/vmservice"
3333
cpcfg "k8s.io/cloud-provider-vsphere/pkg/common/config"
3434
k8s "k8s.io/cloud-provider-vsphere/pkg/common/kubernetes"
@@ -66,6 +66,11 @@ var (
6666

6767
// serviceAnnotationPropagationEnabled if set to true, will propagate the service annotation to resource in supervisor cluster.
6868
serviceAnnotationPropagationEnabled bool
69+
70+
// vmopAPIVersion is the VM Operator API version to use when communicating
71+
// with the Supervisor cluster. Defaults to v1alpha2 for backward compatibility.
72+
// Controlled via the --vm-operator-api-version flag.
73+
vmopAPIVersion string
6974
)
7075

7176
func init() {
@@ -94,6 +99,7 @@ func init() {
9499
flag.BoolVar(&vpcModeEnabled, "enable-vpc-mode", false, "If true, routable pod controller will start with VPC mode. It is useful only when route controller is enabled in vsphereparavirtual mode")
95100
flag.StringVar(&podIPPoolType, "pod-ip-pool-type", "", "Specify if Pod IP address is Public or Private routable in VPC network. Valid values are Public and Private")
96101
flag.BoolVar(&serviceAnnotationPropagationEnabled, "enable-service-annotation-propagation", false, "If true, will propagate the service annotation to resource in supervisor cluster.")
102+
flag.StringVar(&vmopAPIVersion, "vm-operator-api-version", factory.V1alpha2, "the API version to use when communicating with VM Operator in supervisor mode. Valid values are: "+factory.V1alpha2+", "+factory.V1alpha5)
97103
}
98104

99105
// Creates new Controller node interface and returns
@@ -138,19 +144,25 @@ func (cp *VSphereParavirtual) Initialize(clientBuilder cloudprovider.ControllerC
138144
klog.Fatalf("Failed to get cluster namespace: %v", err)
139145
}
140146

147+
klog.Infof("Using VM Operator API version: %s", vmopAPIVersion)
148+
vmopClient, err := factory.NewAdapter(vmopAPIVersion, kcfg)
149+
if err != nil {
150+
klog.Fatalf("Failed to create VM Operator adapter for version %s: %v", vmopAPIVersion, err)
151+
}
152+
141153
routes, err := NewRoutes(clusterNS, kcfg, *cp.ownerReference, vpcModeEnabled, cp.informMgr.GetNodeLister())
142154
if err != nil {
143155
klog.Errorf("Failed to init Route: %v", err)
144156
}
145157
cp.routes = routes
146158

147-
lb, err := NewLoadBalancer(clusterNS, kcfg, cp.ownerReference, serviceAnnotationPropagationEnabled)
159+
lb, err := NewLoadBalancer(clusterNS, vmopClient, cp.ownerReference, serviceAnnotationPropagationEnabled)
148160
if err != nil {
149161
klog.Errorf("Failed to init LoadBalancer: %v", err)
150162
}
151163
cp.loadBalancer = lb
152164

153-
instances, err := NewInstances(clusterNS, kcfg)
165+
instances, err := NewInstances(clusterNS, vmopClient)
154166
if err != nil {
155167
klog.Errorf("Failed to init Instance: %v", err)
156168
}
@@ -164,7 +176,7 @@ func (cp *VSphereParavirtual) Initialize(clientBuilder cloudprovider.ControllerC
164176
}
165177
}
166178

167-
zones, err := NewZones(clusterNS, kcfg)
179+
zones, err := NewZones(clusterNS, vmopClient)
168180
if err != nil {
169181
klog.Errorf("Failed to init Zones: %v", err)
170182
}
@@ -189,8 +201,7 @@ func (cp *VSphereParavirtual) Instances() (cloudprovider.Instances, bool) {
189201
}
190202

191203
// InstancesV2 returns an implementation of cloudprovider.InstancesV2.
192-
//
193-
// TODO: implement this for v1.20
204+
// Not implemented; the CPI uses the v1 Instances interface instead.
194205
func (cp *VSphereParavirtual) InstancesV2() (cloudprovider.InstancesV2, bool) {
195206
return nil, false
196207
}

pkg/cloudprovider/vsphereparavirtual/instances.go

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,30 @@ import (
2323
"time"
2424

2525
v1 "k8s.io/api/core/v1"
26-
"k8s.io/client-go/rest"
27-
2826
"k8s.io/apimachinery/pkg/types"
2927
"k8s.io/apimachinery/pkg/util/wait"
30-
3128
cloudprovider "k8s.io/cloud-provider"
3229
"k8s.io/klog/v2"
3330

34-
vmopv1 "github.com/vmware-tanzu/vm-operator/api/v1alpha2"
3531
vmop "k8s.io/cloud-provider-vsphere/pkg/cloudprovider/vsphereparavirtual/vmoperator"
36-
"k8s.io/cloud-provider-vsphere/pkg/cloudprovider/vsphereparavirtual/vmservice"
32+
vmoptypes "k8s.io/cloud-provider-vsphere/pkg/cloudprovider/vsphereparavirtual/vmoperator/types"
3733
)
3834

3935
type instances struct {
4036
vmClient vmop.Interface
4137
namespace string
4238
}
4339

40+
// Compile-time assertion that instances implements cloudprovider.Instances.
41+
var _ cloudprovider.Instances = &instances{}
42+
4443
const (
4544
// providerPrefix is the Kubernetes cloud provider prefix for this
4645
// cloud provider.
4746
providerPrefix = ProviderName + "://"
47+
48+
// powerStateOff is the powered-off state constant from the hub types package.
49+
powerStateOff = vmoptypes.PowerStatePoweredOff
4850
)
4951

5052
// DiscoverNodeBackoff is set to be the same with https://github.com/kubernetes/kubernetes/blob/master/pkg/controller/cloud/node_controller.go#L83
@@ -62,46 +64,40 @@ func checkError(err error) bool {
6264
return err != nil
6365
}
6466

65-
// discoverNodeByProviderID takes a ProviderID and returns a VirtualMachine if one exists, or nil otherwise
67+
// discoverNodeByProviderID takes a ProviderID and returns a VirtualMachineInfo if one exists, or nil otherwise
6668
// VirtualMachine not found is not an error
67-
func (i instances) discoverNodeByProviderID(ctx context.Context, providerID string) (*vmopv1.VirtualMachine, error) {
69+
func (i instances) discoverNodeByProviderID(ctx context.Context, providerID string) (*vmoptypes.VirtualMachineInfo, error) {
6870
return discoverNodeByProviderID(ctx, providerID, i.namespace, i.vmClient)
6971
}
7072

71-
// discoverNodeByName takes a node name and returns a VirtualMachine if one exists, or nil otherwise
73+
// discoverNodeByName takes a node name and returns a VirtualMachineInfo if one exists, or nil otherwise
7274
// VirtualMachine not found is not an error
73-
func (i instances) discoverNodeByName(ctx context.Context, name types.NodeName) (*vmopv1.VirtualMachine, error) {
75+
func (i instances) discoverNodeByName(ctx context.Context, name types.NodeName) (*vmoptypes.VirtualMachineInfo, error) {
7476
return discoverNodeByName(ctx, name, i.namespace, i.vmClient)
7577
}
7678

7779
// NewInstances returns an implementation of cloudprovider.Instances
78-
func NewInstances(clusterNS string, kcfg *rest.Config) (cloudprovider.Instances, error) {
79-
vmClient, err := vmservice.GetVmopClient(kcfg)
80-
81-
if err != nil {
82-
return nil, err
83-
}
84-
80+
func NewInstances(clusterNS string, vmClient vmop.Interface) (cloudprovider.Instances, error) {
8581
return &instances{
8682
vmClient: vmClient,
8783
namespace: clusterNS,
8884
}, nil
8985
}
9086

91-
func createNodeAddresses(vm *vmopv1.VirtualMachine) []v1.NodeAddress {
87+
func createNodeAddresses(vm *vmoptypes.VirtualMachineInfo) []v1.NodeAddress {
9288
// TODO: Currently, dual-stack (IPv4 and IPv6) is not supported.
9389
// Cluster will be assumed as IPv4 Primary by default.
9490
// In the future, when dual-stack support is implemented, this code should be updated to
9591
// dynamically determine the IP format based on the cluster's IP family.
9692
// https://github.com/kubernetes/cloud-provider-vsphere/issues/1129
97-
if vm.Status.Network == nil || (vm.Status.Network.PrimaryIP4 == "" && vm.Status.Network.PrimaryIP6 == "") {
93+
if vm.PrimaryIP4 == "" && vm.PrimaryIP6 == "" {
9894
klog.V(4).Info("instance found, but no address yet")
9995
return []v1.NodeAddress{}
10096
}
10197

102-
address := vm.Status.Network.PrimaryIP4
98+
address := vm.PrimaryIP4
10399
if address == "" {
104-
address = vm.Status.Network.PrimaryIP6
100+
address = vm.PrimaryIP6
105101
}
106102

107103
return []v1.NodeAddress{
@@ -162,17 +158,17 @@ func (i *instances) InstanceID(ctx context.Context, nodeName types.NodeName) (st
162158
return "", cloudprovider.InstanceNotFound
163159
}
164160

165-
if vm.Status.BiosUUID == "" {
161+
if vm.BiosUUID == "" {
166162
return "", errBiosUUIDEmpty
167163
}
168164

169-
klog.V(4).Infof("instances.InstanceID() called to get vm: %v uuid: %v", nodeName, vm.Status.BiosUUID)
170-
return vm.Status.BiosUUID, nil
165+
klog.V(4).Infof("instances.InstanceID() called to get vm: %v uuid: %v", nodeName, vm.BiosUUID)
166+
return vm.BiosUUID, nil
171167
}
172168

173169
// InstanceType returns the type of the specified instance.
174170
func (i *instances) InstanceType(ctx context.Context, name types.NodeName) (string, error) {
175-
klog.V(4).Info("instances.InstanceTypeByProviderID() called with ", name)
171+
klog.V(4).Info("instances.InstanceType() called with ", name)
176172
return "", nil
177173
}
178174

@@ -213,7 +209,7 @@ func (i *instances) InstanceShutdownByProviderID(ctx context.Context, providerID
213209
klog.V(4).Info("instances.InstanceShutdownByProviderID() InstanceNotFound ", providerID)
214210
return false, cloudprovider.InstanceNotFound
215211
}
216-
return vm.Status.PowerState == vmopv1.VirtualMachinePowerStateOff, nil
212+
return vm.PowerState == powerStateOff, nil
217213
}
218214

219215
func (i *instances) AddSSHKeyToAllInstances(ctx context.Context, user string, keyData []byte) error {

0 commit comments

Comments
 (0)