Skip to content

Commit

Permalink
Merge pull request #3612 from patrickdillon/vsphere-cloud-provider-fo…
Browse files Browse the repository at this point in the history
…lder

Bug 1836042: set folder absolute path in vSphere cloud provider
  • Loading branch information
openshift-merge-robot committed May 21, 2020
2 parents e2367c4 + b652e58 commit 29024b6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
12 changes: 5 additions & 7 deletions pkg/asset/manifests/cloudproviderconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"io/ioutil"
"path/filepath"
"strings"

"github.com/ghodss/yaml"
"github.com/pkg/errors"
Expand Down Expand Up @@ -147,14 +146,13 @@ func (cpc *CloudProviderConfig) Generate(dependencies asset.Parents) error {
}
cm.Data[cloudProviderConfigDataKey] = gcpConfig
case vspheretypes.Name:
var folderRelPath string
if len(installConfig.Config.Platform.VSphere.Folder) != 0 {
folderRelPath = strings.SplitAfterN(installConfig.Config.Platform.VSphere.Folder, "vm/", 2)[1]
folderPath := installConfig.Config.Platform.VSphere.Folder
if len(folderPath) == 0 {
dataCenter := installConfig.Config.Platform.VSphere.Datacenter
folderPath = fmt.Sprintf("/%s/vm/%s", dataCenter, clusterID.InfraID)
}

vsphereConfig, err := vspheremanifests.CloudProviderConfig(
clusterID.InfraID,
folderRelPath,
folderPath,
installConfig.Config.Platform.VSphere,
)
if err != nil {
Expand Down
9 changes: 4 additions & 5 deletions pkg/asset/manifests/vsphere/cloudproviderconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ func printIfNotEmpty(buf *bytes.Buffer, k, v string) {
}

// CloudProviderConfig generates the cloud provider config for the vSphere platform.
func CloudProviderConfig(clusterID, folderRelPath string, p *vspheretypes.Platform) (string, error) {
// folderPath is the absolute path to the VM folder that will be used for installation.
// p is the vSphere platform struct.
func CloudProviderConfig(folderPath string, p *vspheretypes.Platform) (string, error) {
buf := new(bytes.Buffer)

fmt.Fprintln(buf, "[Global]")
Expand All @@ -27,10 +29,7 @@ func CloudProviderConfig(clusterID, folderRelPath string, p *vspheretypes.Platfo
printIfNotEmpty(buf, "server", p.VCenter)
printIfNotEmpty(buf, "datacenter", p.Datacenter)
printIfNotEmpty(buf, "default-datastore", p.DefaultDatastore)
printIfNotEmpty(buf, "folder", folderRelPath)
if p.Folder == "" {
printIfNotEmpty(buf, "folder", clusterID)
}
printIfNotEmpty(buf, "folder", folderPath)
fmt.Fprintln(buf, "")

fmt.Fprintf(buf, "[VirtualCenter %q]\n", p.VCenter)
Expand Down
8 changes: 4 additions & 4 deletions pkg/asset/manifests/vsphere/cloudproviderconfig_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package vsphere

import (
"fmt"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -9,8 +10,6 @@ import (
)

func TestCloudProviderConfig(t *testing.T) {
clusterName := "test-cluster"
folderRelPath := ""
platform := &vspheretypes.Platform{
VCenter: "test-name",
Username: "test-username",
Expand All @@ -27,12 +26,13 @@ insecure-flag = "1"
server = "test-name"
datacenter = "test-datacenter"
default-datastore = "test-datastore"
folder = "test-cluster"
folder = "/test-datacenter/vm/clusterID"
[VirtualCenter "test-name"]
datacenters = "test-datacenter"
`
actualConfig, err := CloudProviderConfig(clusterName, folderRelPath, platform)
folderPath := fmt.Sprintf("/%s/vm/%s", "test-datacenter", "clusterID")
actualConfig, err := CloudProviderConfig(folderPath, platform)
assert.NoError(t, err, "failed to create cloud provider config")
assert.Equal(t, expectedConfig, actualConfig, "unexpected cloud provider config")
}

0 comments on commit 29024b6

Please sign in to comment.