Repository: kubermatic/machine-controller
Pull request #1505 (2022-12-05 09:45:48)

Make CloudConfigToString a struct receiver function called String
**What this PR does / why we need it**:

**Which issue(s) this PR fixes**:
<!--optional, in `fixes #<issue number>` format, will close the issue(s) when PR gets merged-->



**What type of PR is this?**

/kind chore

**Special notes for your reviewer**:

**Does this PR introduce a user-facing change? Then add your Release Note here**:
<!--
Write your release note:
1. Enter your extended release note in the below block. If the PR requires additional action from users switching to the new release, include the string "action required".
2. If no release note is required, just write "NONE".
-->
```release-note
NONE
```

**Documentation**:
<!--
Please do one of the following options:
- Add a link to the existing documentation
- Add a link to the kubermatic/docs pull request
- If no documentation change is applicable then add:
  - TBD (documentation will be added later)
  - NONE (no documentation needed for this PR)
-->
```documentation
NONE
```


kubermatic-bot: @WeirdMachine: Adding the "do-not-merge/release-note-label-needed" label and removing any existing "release-note-none" label because there is a "kind/deprecation" label on the PR.

<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.
</details>
kubermatic-bot: [APPROVALNOTIFIER] This PR is **NOT APPROVED**

This pull-request has been approved by: *<a href="https://github.com/kubermatic/machine-controller/pull/1505#" title="Author self-approved">WeirdMachine</a>*
**Once this PR has been reviewed and has the lgtm label**, please assign ahmedwaleedmalik for approval by writing `/assign @ahmedwaleedmalik` in a comment. For more information see:[The Kubernetes Code Review Process](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process).

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=kubermatic%2Fmachine-controller).

<details open>
Needs approval from an approver in each of these files:

- **[pkg/cloudprovider/provider/OWNERS](https://github.com/kubermatic/machine-controller/blob/main/pkg/cloudprovider/provider/OWNERS)**

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":["ahmedwaleedmalik"]} -->
kubermatic-bot: @WeirdMachine: The following test **failed**, say `/retest` to rerun all failed tests or `/retest-required` to rerun all mandatory failed tests:

Test name | Commit | Details | Required | Rerun command
--- | --- | --- | --- | ---
pull-machine-controller-lint | 0e99febddea73479f9569fdfbd06d0cdb46c2ad6 | [link](https://public-prow.loodse.com/view/gs/prow-dev-public-data/pr-logs/pull/kubermatic_machine-controller/1505/pull-machine-controller-lint/1599702075808157696) | true | `/test pull-machine-controller-lint`

[Full PR test history](https://public-prow.loodse.com/pr-history?org=kubermatic&repo=machine-controller&pr=1505)

<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository. I understand the commands that are listed [here](https://go.k8s.io/bot-commands).
</details>
<!-- test report -->
kubermatic-bot: @WeirdMachine: The following tests **failed**, say `/retest` to rerun all failed tests or `/retest-required` to rerun all mandatory failed tests:

Test name | Commit | Details | Required | Rerun command
--- | --- | --- | --- | ---
pull-machine-controller-lint | 0e99febddea73479f9569fdfbd06d0cdb46c2ad6 | [link](https://public-prow.loodse.com/view/gs/prow-dev-public-data/pr-logs/pull/kubermatic_machine-controller/1505/pull-machine-controller-lint/1599702075808157696) | true | `/test pull-machine-controller-lint`
pull-machine-controller-e2e-azure | 0e99febddea73479f9569fdfbd06d0cdb46c2ad6 | [link](https://public-prow.loodse.com/view/gs/prow-dev-public-data/pr-logs/pull/kubermatic_machine-controller/1505/pull-machine-controller-e2e-azure/1599702072461103104) | true | `/test pull-machine-controller-e2e-azure`

[Full PR test history](https://public-prow.loodse.com/pr-history?org=kubermatic&repo=machine-controller&pr=1505)

<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository. I understand the commands that are listed [here](https://go.k8s.io/bot-commands).
</details>
<!-- test report -->
kubermatic-bot: @WeirdMachine: The following tests **failed**, say `/retest` to rerun all failed tests or `/retest-required` to rerun all mandatory failed tests:

Test name | Commit | Details | Required | Rerun command
--- | --- | --- | --- | ---
pull-machine-controller-lint | 0e99febddea73479f9569fdfbd06d0cdb46c2ad6 | [link](https://public-prow.loodse.com/view/gs/prow-dev-public-data/pr-logs/pull/kubermatic_machine-controller/1505/pull-machine-controller-lint/1599702075808157696) | true | `/test pull-machine-controller-lint`
pull-machine-controller-e2e-azure | 0e99febddea73479f9569fdfbd06d0cdb46c2ad6 | [link](https://public-prow.loodse.com/view/gs/prow-dev-public-data/pr-logs/pull/kubermatic_machine-controller/1505/pull-machine-controller-e2e-azure/1599702072461103104) | true | `/test pull-machine-controller-e2e-azure`
pull-machine-controller-e2e-vsphere | 0e99febddea73479f9569fdfbd06d0cdb46c2ad6 | [link](https://public-prow.loodse.com/view/gs/prow-dev-public-data/pr-logs/pull/kubermatic_machine-controller/1505/pull-machine-controller-e2e-vsphere/1599702073304158208) | true | `/test pull-machine-controller-e2e-vsphere`

[Full PR test history](https://public-prow.loodse.com/pr-history?org=kubermatic&repo=machine-controller&pr=1505)

<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository. I understand the commands that are listed [here](https://go.k8s.io/bot-commands).
</details>
<!-- test report -->

Patch:
diff --git a/pkg/cloudprovider/provider/vsphere/provider.go b/pkg/cloudprovider/provider/vsphere/provider.go
index a16f58b6..7151f15e 100644
--- a/pkg/cloudprovider/provider/vsphere/provider.go
+++ b/pkg/cloudprovider/provider/vsphere/provider.go
@@ -591,7 +591,7 @@ func (p *provider) GetCloudConfig(spec clusterv1alpha1.MachineSpec) (config stri
 		},
 	}
 
-	s, err := vspheretypes.CloudConfigToString(cc)
+	s, err := cc.String()
 	if err != nil {
 		return "", "", fmt.Errorf("failed to convert the cloud-config to string: %w", err)
 	}
diff --git a/pkg/cloudprovider/provider/vsphere/types/cloudconfig.go b/pkg/cloudprovider/provider/vsphere/types/cloudconfig.go
index 9e9f997b..a20bcda8 100644
--- a/pkg/cloudprovider/provider/vsphere/types/cloudconfig.go
+++ b/pkg/cloudprovider/provider/vsphere/types/cloudconfig.go
@@ -105,6 +105,26 @@ type CloudConfig struct {
 	VirtualCenter map[string]*VirtualCenterConfig
 }
 
+// String converts CloudConfig into its formatted string representation.
+func (c *CloudConfig) String() (string, error) {
+	funcMap := sprig.TxtFuncMap()
+	funcMap["iniEscape"] = ini.Escape
+
+	tpl, err := template.New("cloud-config").Funcs(funcMap).Parse(cloudConfigTpl)
+	if err != nil {
+		return "", fmt.Errorf("failed to parse the cloud config template: %w", err)
+	}
+
+	buf := &bytes.Buffer{}
+	if err := tpl.Execute(buf, c); err != nil {
+		return "", fmt.Errorf("failed to execute cloud config template: %w", err)
+	}
+
+	return buf.String(), nil
+}
+
+// CloudConfigToString converts CloudConfig into its formatted string representation.
+// Deprecated: use struct receiver function String() instead.
 func CloudConfigToString(c *CloudConfig) (string, error) {
 	funcMap := sprig.TxtFuncMap()
 	funcMap["iniEscape"] = ini.Escape


Test patch:
diff --git a/pkg/cloudprovider/provider/vsphere/types/cloudconfig_test.go b/pkg/cloudprovider/provider/vsphere/types/cloudconfig_test.go
index 399f3123..0f69bf4d 100644
--- a/pkg/cloudprovider/provider/vsphere/types/cloudconfig_test.go
+++ b/pkg/cloudprovider/provider/vsphere/types/cloudconfig_test.go
@@ -121,7 +121,7 @@ func TestCloudConfigToString(t *testing.T) {
 
 	for _, test := range tests {
 		t.Run(test.name, func(t *testing.T) {
-			s, err := CloudConfigToString(test.config)
+			s, err := test.config.String()
 			if err != nil {
 				t.Fatal(err)
 			}
diff --git a/test/e2e/provisioning/all_e2e_test.go b/test/e2e/provisioning/all_e2e_test.go
index 3716f473..ca4ccb55 100644
--- a/test/e2e/provisioning/all_e2e_test.go
+++ b/test/e2e/provisioning/all_e2e_test.go
@@ -871,7 +871,7 @@ func getVSphereTestParams(t *testing.T) []string {
 func TestVsphereProvisioningE2E(t *testing.T) {
 	t.Parallel()
 
-	selector := Not(OsSelector("sles", "amzn2", "rockylinux"))
+	selector := Not(OsSelector("sles", "amzn2", "rockylinux", "flatcar"))
 	params := getVSphereTestParams(t)
 
 	runScenarios(t, selector, params, VSPhereManifest, fmt.Sprintf("vs-%s", *testRunIdentifier))