Skip to content

Commit f280849

Browse files
Merge pull request #1241 from vr4manta/SPLAT-1638
SPLAT-1638: Added multi vCenter support
2 parents e210626 + 5199567 commit f280849

35 files changed

+1952
-296
lines changed

go.mod

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ require (
1919
github.com/stretchr/testify v1.8.4
2020
github.com/vmware/govmomi v0.34.2
2121
golang.org/x/net v0.24.0
22-
gopkg.in/gcfg.v1 v1.2.3
2322
k8s.io/api v0.29.0
2423
k8s.io/apimachinery v0.29.0
2524
k8s.io/apiserver v0.29.0
2625
k8s.io/client-go v0.29.0
26+
k8s.io/cloud-provider-vsphere v1.28.0
2727
k8s.io/klog/v2 v2.110.1
2828
k8s.io/kubectl v0.29.0
2929
k8s.io/utils v0.0.0-20240102154912-e7106e64919e
@@ -45,7 +45,7 @@ require (
4545
github.com/Abirdcfly/dupword v0.0.11 // indirect
4646
github.com/Antonboom/errname v0.1.9 // indirect
4747
github.com/Antonboom/nilnil v0.1.3 // indirect
48-
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
48+
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
4949
github.com/BurntSushi/toml v1.2.1 // indirect
5050
github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24 // indirect
5151
github.com/GaijinEntertainment/go-exhaustruct/v2 v2.3.0 // indirect
@@ -131,7 +131,7 @@ require (
131131
github.com/hashicorp/go-version v1.6.0 // indirect
132132
github.com/hashicorp/hcl v1.0.0 // indirect
133133
github.com/hexops/gotextdiff v1.0.3 // indirect
134-
github.com/imdario/mergo v0.3.13 // indirect
134+
github.com/imdario/mergo v0.3.15 // indirect
135135
github.com/inconshreveable/mousetrap v1.1.0 // indirect
136136
github.com/jgautheron/goconst v1.5.1 // indirect
137137
github.com/jingyugao/rowserrcheck v1.1.1 // indirect
@@ -166,7 +166,7 @@ require (
166166
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
167167
github.com/mitchellh/mapstructure v1.5.0 // indirect
168168
github.com/moby/spdystream v0.2.0 // indirect
169-
github.com/moby/term v0.0.0-20221205130635-1aeaba878587 // indirect
169+
github.com/moby/term v0.5.0 // indirect
170170
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
171171
github.com/modern-go/reflect2 v1.0.2 // indirect
172172
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
@@ -246,6 +246,7 @@ require (
246246
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
247247
google.golang.org/appengine v1.6.7 // indirect
248248
google.golang.org/protobuf v1.31.0 // indirect
249+
gopkg.in/gcfg.v1 v1.2.3 // indirect
249250
gopkg.in/inf.v0 v0.9.1 // indirect
250251
gopkg.in/ini.v1 v1.67.0 // indirect
251252
gopkg.in/warnings.v0 v0.1.2 // indirect

go.sum

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ github.com/Antonboom/errname v0.1.9 h1:BZDX4r3l4TBZxZ2o2LNrlGxSHran4d1u4veZdoORT
4646
github.com/Antonboom/errname v0.1.9/go.mod h1:nLTcJzevREuAsgTbG85UsuiWpMpAqbKD1HNZ29OzE58=
4747
github.com/Antonboom/nilnil v0.1.3 h1:6RTbx3d2mcEu3Zwq9TowQpQMVpP75zugwOtqY1RTtcE=
4848
github.com/Antonboom/nilnil v0.1.3/go.mod h1:iOov/7gRcXkeEU+EMGpBu2ORih3iyVEiWjeste1SJm8=
49-
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8=
50-
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
49+
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25UVaW/CKtUDjefjrs0SPonmDGUVOYP0=
50+
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
5151
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
5252
github.com/BurntSushi/toml v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=
5353
github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
@@ -348,8 +348,8 @@ github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUq
348348
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
349349
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
350350
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
351-
github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk=
352-
github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg=
351+
github.com/imdario/mergo v0.3.15 h1:M8XP7IuFNsqUx6VPK2P9OSmsYsI/YFaGil0uD21V3dM=
352+
github.com/imdario/mergo v0.3.15/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY=
353353
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
354354
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
355355
github.com/jgautheron/goconst v1.5.1 h1:HxVbL1MhydKs8R8n/HE5NPvzfaYmQJA3o879lE4+WcM=
@@ -444,8 +444,8 @@ github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyua
444444
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
445445
github.com/moby/spdystream v0.2.0 h1:cjW1zVyyoiM0T7b6UoySUFqzXMoqRckQtXwGPiBhOM8=
446446
github.com/moby/spdystream v0.2.0/go.mod h1:f7i0iNDQJ059oMTcWxx8MA/zKFIuD/lY+0GqbN2Wy8c=
447-
github.com/moby/term v0.0.0-20221205130635-1aeaba878587 h1:HfkjXDfhgVaN5rmueG8cL8KKeFNecRCXFhaJ2qZ5SKA=
448-
github.com/moby/term v0.0.0-20221205130635-1aeaba878587/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y=
447+
github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0=
448+
github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y=
449449
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
450450
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
451451
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
@@ -1095,7 +1095,6 @@ gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
10951095
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
10961096
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
10971097
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
1098-
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
10991098
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
11001099
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
11011100
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
@@ -1119,6 +1118,8 @@ k8s.io/cli-runtime v0.29.0 h1:q2kC3cex4rOBLfPOnMSzV2BIrrQlx97gxHJs21KxKS4=
11191118
k8s.io/cli-runtime v0.29.0/go.mod h1:VKudXp3X7wR45L+nER85YUzOQIru28HQpXr0mTdeCrk=
11201119
k8s.io/client-go v0.29.0 h1:KmlDtFcrdUzOYrBhXHgKw5ycWzc3ryPX5mQe0SkG3y8=
11211120
k8s.io/client-go v0.29.0/go.mod h1:yLkXH4HKMAywcrD82KMSmfYg2DlE8mepPR4JGSo5n38=
1121+
k8s.io/cloud-provider-vsphere v1.28.0 h1:S7KyDRI3EDQ5jFimTRNY+S0IcmLV+WpiLDafeAfVK5Y=
1122+
k8s.io/cloud-provider-vsphere v1.28.0/go.mod h1:nGC4cRIj3uQkBM0gc9mIzknmepx1TjPJTSSpMZ8YKwM=
11221123
k8s.io/component-base v0.29.0 h1:T7rjd5wvLnPBV1vC4zWd/iWRbV8Mdxs+nGaoaFzGw3s=
11231124
k8s.io/component-base v0.29.0/go.mod h1:sADonFTQ9Zc9yFLghpDpmNXEdHyQmFIGbiuZbqAXQ1M=
11241125
k8s.io/klog/v2 v2.110.1 h1:U/Af64HJf7FcwMcXyKm2RPM22WZzyR7OSpYj5tg3cL0=

hack/ci-test.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ if [ "$OPENSHIFT_CI" == "true" ] && [ -n "$ARTIFACT_DIR" ] && [ -d "$ARTIFACT_DI
3737
GINKGO_ARGS="${GINKGO_ARGS} --junit-report=junit_machine_api_operator.xml --cover --coverprofile=test-unit-coverage.out --output-dir=${ARTIFACT_DIR}"
3838
fi
3939

40+
TEST_PACKAGES=${TEST_PACKAGES:-$(go list -f "{{ .Dir }}" ./...)}
41+
4042
# Print the command we are going to run as Make would.
41-
echo ${GINKGO} ${GINKGO_ARGS} ${GINKGO_EXTRA_ARGS} ./...
42-
${GINKGO} ${GINKGO_ARGS} ${GINKGO_EXTRA_ARGS} ./...
43+
echo ${GINKGO} ${GINKGO_ARGS} ${GINKGO_EXTRA_ARGS} "<omitted>"
44+
${GINKGO} ${GINKGO_ARGS} ${GINKGO_EXTRA_ARGS} ${TEST_PACKAGES}
4345
# Capture the test result to exit on error after coverage.
4446
TEST_RESULT=$?
4547

pkg/controller/vsphere/actuator_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,10 @@ func TestMachineEvents(t *testing.T) {
115115
g.Expect(k8sClient.Delete(context.Background(), testNamespace)).To(Succeed())
116116
}()
117117

118+
credentialsSecretName := "test"
118119
credentialsSecret := corev1.Secret{
119120
ObjectMeta: metav1.ObjectMeta{
120-
Name: "test",
121+
Name: credentialsSecretName,
121122
Namespace: testNamespaceName,
122123
},
123124
Data: map[string][]byte{
@@ -131,7 +132,7 @@ func TestMachineEvents(t *testing.T) {
131132
g.Expect(k8sClient.Delete(context.Background(), &credentialsSecret)).To(Succeed())
132133
}()
133134

134-
testConfig := fmt.Sprintf(testConfigFmt, port)
135+
testConfig := fmt.Sprintf(testConfigFmt, port, credentialsSecretName, testNamespaceName)
135136
configMap := &corev1.ConfigMap{
136137
ObjectMeta: metav1.ObjectMeta{
137138
Name: "testname",

pkg/controller/vsphere/machine_scope.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
apicorev1 "k8s.io/api/core/v1"
1212
apimachineryerrors "k8s.io/apimachinery/pkg/api/errors"
1313
apimachineryutilerrors "k8s.io/apimachinery/pkg/util/errors"
14+
vsphere "k8s.io/cloud-provider-vsphere/pkg/common/config"
1415
"k8s.io/klog/v2"
1516
runtimeclient "sigs.k8s.io/controller-runtime/pkg/client"
1617
)
@@ -39,7 +40,7 @@ type machineScope struct {
3940
// client reader that bypasses the manager's cache
4041
apiReader runtimeclient.Reader
4142
// vSphere cloud-provider config
42-
vSphereConfig *vSphereConfig
43+
vSphereConfig *vsphere.Config
4344
// machine resource
4445
machine *machinev1.Machine
4546
providerSpec *machinev1.VSphereMachineProviderSpec
@@ -78,10 +79,10 @@ func newMachineScope(params machineScopeParams) (*machineScope, error) {
7879
return nil, fmt.Errorf("%v: no workspace provided", params.machine.GetName())
7980
}
8081

81-
server := fmt.Sprintf("%s:%s", providerSpec.Workspace.Server, getPortFromConfig(vSphereConfig))
82+
server := fmt.Sprintf("%s:%s", providerSpec.Workspace.Server, getVCenterPortFromConfig(vSphereConfig, providerSpec.Workspace.Server))
8283
authSession, err := session.GetOrCreate(params.Context,
8384
server, providerSpec.Workspace.Datacenter,
84-
user, password, getInsecureFlagFromConfig(vSphereConfig))
85+
user, password, getVCenterInsecureFlagFromConfig(vSphereConfig, providerSpec.Workspace.Server))
8586
if err != nil {
8687
return nil, fmt.Errorf("failed to create vSphere session: %w", err)
8788
}

pkg/controller/vsphere/machine_scope_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,9 +335,10 @@ func TestPatchMachine(t *testing.T) {
335335
g.Expect(k8sClient.Delete(ctx, testNamespace)).To(Succeed())
336336
}()
337337

338+
credentialsSecretName := "test"
338339
credentialsSecret := &corev1.Secret{
339340
ObjectMeta: metav1.ObjectMeta{
340-
Name: "test",
341+
Name: credentialsSecretName,
341342
Namespace: testNamespaceName,
342343
},
343344
Data: map[string][]byte{
@@ -351,7 +352,7 @@ func TestPatchMachine(t *testing.T) {
351352
g.Expect(k8sClient.Delete(ctx, credentialsSecret)).To(Succeed())
352353
}()
353354

354-
testConfig := fmt.Sprintf(testConfigFmt, port)
355+
testConfig := fmt.Sprintf(testConfigFmt, port, credentialsSecretName, testNamespaceName)
355356
configMap := &corev1.ConfigMap{
356357
ObjectMeta: metav1.ObjectMeta{
357358
Name: "testname",

pkg/controller/vsphere/reconciler_test.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import (
3939
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
4040
apimachinerytypes "k8s.io/apimachinery/pkg/types"
4141
"k8s.io/client-go/kubernetes/scheme"
42+
vsphere "k8s.io/cloud-provider-vsphere/pkg/common/config"
4243
runtimeclient "sigs.k8s.io/controller-runtime/pkg/client"
4344
"sigs.k8s.io/controller-runtime/pkg/client/fake"
4445

@@ -1763,9 +1764,10 @@ func TestDelete(t *testing.T) {
17631764

17641765
password, _ := server.URL.User.Password()
17651766

1767+
credentialsSecretName := "test"
17661768
secret := &corev1.Secret{
17671769
ObjectMeta: metav1.ObjectMeta{
1768-
Name: "test",
1770+
Name: credentialsSecretName,
17691771
Namespace: ns,
17701772
},
17711773
Data: map[string][]byte{
@@ -1774,7 +1776,7 @@ func TestDelete(t *testing.T) {
17741776
},
17751777
}
17761778

1777-
testConfig := fmt.Sprintf(testConfigFmt, port)
1779+
testConfig := fmt.Sprintf(testConfigFmt, port, credentialsSecretName, ns)
17781780
configMap := &corev1.ConfigMap{
17791781
ObjectMeta: metav1.ObjectMeta{
17801782
Name: "testName",
@@ -2272,9 +2274,10 @@ func TestCreate(t *testing.T) {
22722274
vm.Name = vmName
22732275
vm.Config.Version = minimumHWVersionString
22742276

2277+
credentialsSecretName := "test"
22752278
credentialsSecret := &corev1.Secret{
22762279
ObjectMeta: metav1.ObjectMeta{
2277-
Name: "test",
2280+
Name: credentialsSecretName,
22782281
Namespace: namespace,
22792282
},
22802283
Data: map[string][]byte{
@@ -2283,7 +2286,7 @@ func TestCreate(t *testing.T) {
22832286
},
22842287
}
22852288

2286-
testConfig := fmt.Sprintf(testConfigFmt, port)
2289+
testConfig := fmt.Sprintf(testConfigFmt, port, credentialsSecretName, namespace)
22872290
configMap := &corev1.ConfigMap{
22882291
ObjectMeta: metav1.ObjectMeta{
22892292
Name: "testName",
@@ -2687,9 +2690,10 @@ func TestUpdate(t *testing.T) {
26872690
instanceUUID := "a5764857-ae35-34dc-8f25-a9c9e73aa898"
26882691
vm.Config.InstanceUuid = instanceUUID
26892692

2693+
credentialsSecretName := "test"
26902694
credentialsSecret := &corev1.Secret{
26912695
ObjectMeta: metav1.ObjectMeta{
2692-
Name: "test",
2696+
Name: credentialsSecretName,
26932697
Namespace: namespace,
26942698
},
26952699
Data: map[string][]byte{
@@ -2698,7 +2702,7 @@ func TestUpdate(t *testing.T) {
26982702
},
26992703
}
27002704

2701-
testConfig := fmt.Sprintf(testConfigFmt, port)
2705+
testConfig := fmt.Sprintf(testConfigFmt, port, credentialsSecretName, namespace)
27022706
configMap := &corev1.ConfigMap{
27032707
ObjectMeta: metav1.ObjectMeta{
27042708
Name: "testName",
@@ -3019,8 +3023,8 @@ func TestReconcileMachineWithCloudState(t *testing.T) {
30193023
providerStatus: &machinev1.VSphereMachineProviderStatus{
30203024
TaskRef: task.Reference().Value,
30213025
},
3022-
vSphereConfig: &vSphereConfig{
3023-
Labels: Labels{
3026+
vSphereConfig: &vsphere.Config{
3027+
Labels: vsphere.Labels{
30243028
Zone: zoneKey,
30253029
Region: regionKey,
30263030
},

pkg/controller/vsphere/util.go

Lines changed: 24 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ import (
88
"net/http"
99
"strings"
1010

11-
"gopkg.in/gcfg.v1"
12-
1311
configv1 "github.com/openshift/api/config/v1"
1412
machinev1 "github.com/openshift/api/machine/v1beta1"
1513
corev1 "k8s.io/api/core/v1"
1614
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1715
"k8s.io/apimachinery/pkg/fields"
1816
"k8s.io/apimachinery/pkg/runtime"
17+
vsphere "k8s.io/cloud-provider-vsphere/pkg/common/config"
1918
"k8s.io/klog/v2"
2019
runtimeclient "sigs.k8s.io/controller-runtime/pkg/client"
2120
)
@@ -25,35 +24,6 @@ const (
2524
OpenshiftConfigNamespace = "openshift-config"
2625
)
2726

28-
// vSphereConfig is a copy of the Kubernetes vSphere cloud provider config type
29-
// that contains the fields we need. Unfortunately, we can't easily import
30-
// either the legacy or newer cloud provider code here, so we're just
31-
// duplicating part of the type and parsing it ourselves using the same gcfg
32-
// library for now.
33-
type vSphereConfig struct {
34-
// Global is the vSphere cloud provider's global configuration.
35-
Labels Labels `gcfg:"Labels"`
36-
// Global is the vSphere cloud provider's global configuration.
37-
Global Global `gcfg:"Global"`
38-
}
39-
40-
// Labels is the vSphere cloud provider's zone and region configuration.
41-
type Labels struct {
42-
// Zone is the zone in which VMs are created/located.
43-
Zone string `gcfg:"zone"`
44-
// Region is the region in which VMs are created/located.
45-
Region string `gcfg:"region"`
46-
}
47-
48-
// Global is the vSphere cloud provider's global configuration.
49-
type Global struct {
50-
// Port is the port on which the vSphere endpoint is listening.
51-
// Defaults to 443.
52-
// Has string type because we need empty string value for formatting
53-
Port string `gcfg:"port"`
54-
InsecureFlag string `gcfg:"insecure-flag"`
55-
}
56-
5727
func getInfrastructure(c runtimeclient.Reader) (*configv1.Infrastructure, error) {
5828
if c == nil {
5929
return nil, errors.New("no API reader -- will not fetch infrastructure config")
@@ -69,7 +39,7 @@ func getInfrastructure(c runtimeclient.Reader) (*configv1.Infrastructure, error)
6939
return infra, nil
7040
}
7141

72-
func getVSphereConfig(c runtimeclient.Reader, configNamespace string) (*vSphereConfig, error) {
42+
func getVSphereConfig(c runtimeclient.Reader, configNamespace string) (*vsphere.Config, error) {
7343
if c == nil {
7444
return nil, errors.New("no API reader -- will not fetch vSphere config")
7545
}
@@ -104,13 +74,7 @@ func getVSphereConfig(c runtimeclient.Reader, configNamespace string) (*vSphereC
10474
)
10575
}
10676

107-
var vcfg vSphereConfig
108-
109-
if err := gcfg.FatalOnly(gcfg.ReadStringInto(&vcfg, cloudConfig)); err != nil {
110-
return nil, err
111-
}
112-
113-
return &vcfg, nil
77+
return vsphere.ReadConfig([]byte(cloudConfig))
11478
}
11579

11680
func setConditions(condition metav1.Condition, conditions []metav1.Condition) []metav1.Condition {
@@ -169,18 +133,33 @@ func conditionFailed() metav1.Condition {
169133
}
170134
}
171135

172-
func getPortFromConfig(config *vSphereConfig) string {
136+
func getVCenterPortFromConfig(config *vsphere.Config, vcenter string) string {
173137
if config != nil {
174-
return config.Global.Port
138+
for _, vc := range config.VirtualCenter {
139+
if vc.VCenterIP == vcenter {
140+
if len(vc.VCenterPort) > 0 {
141+
return vc.VCenterPort
142+
} else {
143+
return config.Global.VCenterPort
144+
}
145+
}
146+
}
175147
}
176148
return ""
177149
}
178150

179-
// getInsecureFlagFromConfig get insecure flag from config and default to false
180-
func getInsecureFlagFromConfig(config *vSphereConfig) bool {
181-
if config != nil && config.Global.InsecureFlag == "1" {
182-
return true
151+
func getVCenterInsecureFlagFromConfig(config *vsphere.Config, vcenter string) bool {
152+
if config != nil {
153+
for _, vc := range config.VirtualCenter {
154+
if vc.VCenterIP == vcenter {
155+
return vc.InsecureFlag
156+
}
157+
}
158+
159+
// Either vCenter is not found or config is missing.
160+
return config.Global.InsecureFlag
183161
}
162+
184163
return false
185164
}
186165

0 commit comments

Comments
 (0)