Repository: kubermatic/machine-controller
Pull request #1416 (2022-08-23 12:56:34)

enable flatcar, rockylinux and rhel for azure
Signed-off-by: Moath Qasim <moad.qassem@gmail.com>

**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-->
Fixes #

**What type of PR is this?**
<!--
Add one of the following kinds:
/kind bug
/kind cleanup
/kind documentation
/kind feature
/kind design

Optionally add one or more of the following kinds if applicable:
/kind api-change
/kind deprecation
/kind failing-test
/kind flake
/kind regression
-->

**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: @moadqassem: Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our [release note process](https://git.k8s.io/community/contributors/guide/release-notes.md) to remove it.

<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 **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/kubermatic/machine-controller/pull/1416#" title="Author self-approved">moadqassem</a>*

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

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

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

- ~~[OWNERS](https://github.com/kubermatic/machine-controller/blob/master/OWNERS)~~ [moadqassem]

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":[]} -->
kubermatic-bot: @moadqassem: 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-e2e-vsphere | bdaa89c023c2a9aed3531874af2c9789c663bed5 | [link](https://public-prow.loodse.com/view/gs/prow-dev-public-data/pr-logs/pull/kubermatic_machine-controller/1416/pull-machine-controller-e2e-vsphere/1562061258427994112) | true | `/test pull-machine-controller-e2e-vsphere`

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

<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: @moadqassem: 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-e2e-vsphere | bdaa89c023c2a9aed3531874af2c9789c663bed5 | [link](https://public-prow.loodse.com/view/gs/prow-dev-public-data/pr-logs/pull/kubermatic_machine-controller/1416/pull-machine-controller-e2e-vsphere/1562061258427994112) | true | `/test pull-machine-controller-e2e-vsphere`
pull-machine-controller-e2e-azure | bdaa89c023c2a9aed3531874af2c9789c663bed5 | [link](https://public-prow.loodse.com/view/gs/prow-dev-public-data/pr-logs/pull/kubermatic_machine-controller/1416/pull-machine-controller-e2e-azure/1562061251708719104) | true | `/test pull-machine-controller-e2e-azure`

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

<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 -->
moadqassem: /retest
kubermatic-bot: @moadqassem: 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-e2e-vsphere | bdaa89c023c2a9aed3531874af2c9789c663bed5 | [link](https://public-prow.loodse.com/view/gs/prow-dev-public-data/pr-logs/pull/kubermatic_machine-controller/1416/pull-machine-controller-e2e-vsphere/1562082866374905856) | true | `/test pull-machine-controller-e2e-vsphere`

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

<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 -->
moadqassem: /retest
kubermatic-bot: @moadqassem: 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-e2e-vsphere | bdaa89c023c2a9aed3531874af2c9789c663bed5 | [link](https://public-prow.loodse.com/view/gs/prow-dev-public-data/pr-logs/pull/kubermatic_machine-controller/1416/pull-machine-controller-e2e-vsphere/1562095692770447360) | true | `/test pull-machine-controller-e2e-vsphere`

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

<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 -->
xrstf: /override pull-machine-controller-e2e-vsphere
kubermatic-bot: @xrstf: Overrode contexts on behalf of xrstf: pull-machine-controller-e2e-vsphere

<details>

In response to [this](https://github.com/kubermatic/machine-controller/pull/1416#issuecomment-1224271432):

>/override pull-machine-controller-e2e-vsphere


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>

Patch:
diff --git a/pkg/cloudprovider/provider/anexia/instance.go b/pkg/cloudprovider/provider/anexia/instance.go
index cc9a9e60..fa53467a 100644
--- a/pkg/cloudprovider/provider/anexia/instance.go
+++ b/pkg/cloudprovider/provider/anexia/instance.go
@@ -17,6 +17,8 @@ limitations under the License.
 package anexia
 
 import (
+	"net"
+
 	"go.anx.io/go-anxcloud/pkg/vsphere/info"
 
 	"github.com/kubermatic/machine-controller/pkg/cloudprovider/instance"
@@ -26,7 +28,8 @@ import (
 )
 
 type anexiaInstance struct {
-	info *info.Info
+	info              *info.Info
+	reservedAddresses []string
 }
 
 func (ai *anexiaInstance) Name() string {
@@ -52,19 +55,30 @@ func (ai *anexiaInstance) ProviderID() string {
 func (ai *anexiaInstance) Addresses() map[string]v1.NodeAddressType {
 	addresses := map[string]v1.NodeAddressType{}
 
-	if ai.info == nil {
-		return addresses
+	if ai.reservedAddresses != nil {
+		for _, reservedIP := range ai.reservedAddresses {
+			addresses[reservedIP] = v1.NodeExternalIP
+		}
 	}
 
-	for _, network := range ai.info.Network {
-		for _, ip := range network.IPv4 {
-			addresses[ip] = v1.NodeExternalIP
+	if ai.info != nil {
+		for _, network := range ai.info.Network {
+			for _, ip := range network.IPv4 {
+				addresses[ip] = v1.NodeExternalIP
+			}
+			for _, ip := range network.IPv6 {
+				addresses[ip] = v1.NodeExternalIP
+			}
 		}
-		for _, ip := range network.IPv6 {
+	}
+
+	for ip := range addresses {
+		parsed := net.ParseIP(ip)
+		if parsed.IsPrivate() {
+			addresses[ip] = v1.NodeInternalIP
+		} else {
 			addresses[ip] = v1.NodeExternalIP
 		}
-
-		// TODO mark RFC1918 and RFC4193 addresses as internal
 	}
 
 	return addresses
diff --git a/pkg/cloudprovider/provider/anexia/provider.go b/pkg/cloudprovider/provider/anexia/provider.go
index da8718cb..84172372 100644
--- a/pkg/cloudprovider/provider/anexia/provider.go
+++ b/pkg/cloudprovider/provider/anexia/provider.go
@@ -254,7 +254,7 @@ func getIPAddress(ctx context.Context, client anxclient.Client) (string, error)
 
 	// only use IP if it is still unbound
 	if status.ReservedIP != "" && status.IPState == anxtypes.IPStateUnbound {
-		klog.Info("reusing already provisioned ip", "IP", status.ReservedIP)
+		klog.Infof("reusing already provisioned ip %q", status.ReservedIP)
 		return status.ReservedIP, nil
 	}
 
@@ -450,7 +450,7 @@ func (p *provider) Validate(_ context.Context, machinespec clusterv1alpha1.Machi
 func (p *provider) Get(ctx context.Context, machine *clusterv1alpha1.Machine, _ *cloudprovidertypes.ProviderData) (instance.Instance, error) {
 	config, _, err := p.getConfig(machine.Spec.ProviderSpec)
 	if err != nil {
-		return nil, newError(common.InvalidConfigurationMachineError, "failed to parse MachineSpec: %v", err)
+		return nil, newError(common.InvalidConfigurationMachineError, "failed to retrieve config: %v", err)
 	}
 
 	cli, err := getClient(config.Token)
@@ -463,10 +463,17 @@ func (p *provider) Get(ctx context.Context, machine *clusterv1alpha1.Machine, _
 	if err != nil {
 		return nil, newError(common.InvalidConfigurationMachineError, "failed to get machine status: %v", err)
 	}
+
 	if status.InstanceID == "" {
 		return nil, cloudprovidererrors.ErrInstanceNotFound
 	}
 
+	instance := anexiaInstance{}
+
+	if status.IPState == anxtypes.IPStateBound && status.ReservedIP != "" {
+		instance.reservedAddresses = []string{status.ReservedIP}
+	}
+
 	timeoutCtx, cancel := context.WithTimeout(ctx, anxtypes.GetRequestTimeout)
 	defer cancel()
 
@@ -474,10 +481,9 @@ func (p *provider) Get(ctx context.Context, machine *clusterv1alpha1.Machine, _
 	if err != nil {
 		return nil, fmt.Errorf("failed get machine info: %w", err)
 	}
+	instance.info = &info
 
-	return &anexiaInstance{
-		info: &info,
-	}, nil
+	return &instance, nil
 }
 
 func (p *provider) GetCloudConfig(_ clusterv1alpha1.MachineSpec) (string, string, error) {


Test patch:
diff --git a/pkg/cloudprovider/provider/anexia/instance_test.go b/pkg/cloudprovider/provider/anexia/instance_test.go
new file mode 100644
index 00000000..0d7641a5
--- /dev/null
+++ b/pkg/cloudprovider/provider/anexia/instance_test.go
@@ -0,0 +1,127 @@
+/*
+Copyright 2022 The Machine Controller Authors.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package anexia
+
+import (
+	"testing"
+
+	"github.com/gophercloud/gophercloud/testhelper"
+
+	"go.anx.io/go-anxcloud/pkg/vsphere/info"
+	v1 "k8s.io/api/core/v1"
+)
+
+func TestAnexiaInstance(t *testing.T) {
+	addressCheck := func(t *testing.T, testcase string, instance *anexiaInstance, expected map[string]v1.NodeAddressType) {
+		t.Run(testcase, func(t *testing.T) {
+			addresses := instance.Addresses()
+
+			testhelper.AssertDeepEquals(t, expected, addresses)
+		})
+	}
+
+	t.Run("empty instance", func(t *testing.T) {
+		instance := anexiaInstance{}
+		addressCheck(t, "no addresses", &instance, map[string]v1.NodeAddressType{})
+	})
+
+	t.Run("instance with only reservedAddresses set", func(t *testing.T) {
+		instance := anexiaInstance{
+			reservedAddresses: []string{"10.0.0.2", "fda0:23::2", "8.8.8.8", "2001:db8::2"},
+		}
+
+		addressCheck(t, "expected addresses", &instance, map[string]v1.NodeAddressType{
+			"10.0.0.2":    v1.NodeInternalIP,
+			"fda0:23::2":  v1.NodeInternalIP,
+			"8.8.8.8":     v1.NodeExternalIP,
+			"2001:db8::2": v1.NodeExternalIP,
+		})
+	})
+
+	t.Run("instance with only info set", func(t *testing.T) {
+		instance := anexiaInstance{
+			info: &info.Info{
+				Network: []info.Network{
+					{
+						IPv4: []string{"10.0.0.2"},
+						IPv6: []string{"fda0:23::2"},
+					},
+					{
+						IPv4: []string{"8.8.8.8"},
+						IPv6: []string{"2001:db8::2"},
+					},
+				},
+			},
+		}
+
+		addressCheck(t, "expected addresses", &instance, map[string]v1.NodeAddressType{
+			"10.0.0.2":    v1.NodeInternalIP,
+			"fda0:23::2":  v1.NodeInternalIP,
+			"8.8.8.8":     v1.NodeExternalIP,
+			"2001:db8::2": v1.NodeExternalIP,
+		})
+	})
+
+	t.Run("instance with both reservedAddresses and info set, full overlapping set", func(t *testing.T) {
+		instance := anexiaInstance{
+			reservedAddresses: []string{"10.0.0.2", "fda0:23::2", "8.8.8.8", "2001:db8::2"},
+			info: &info.Info{
+				Network: []info.Network{
+					{
+						IPv4: []string{"10.0.0.2"},
+						IPv6: []string{"fda0:23::2"},
+					},
+					{
+						IPv4: []string{"8.8.8.8"},
+						IPv6: []string{"2001:db8::2"},
+					},
+				},
+			},
+		}
+
+		addressCheck(t, "expected addresses", &instance, map[string]v1.NodeAddressType{
+			"10.0.0.2":    v1.NodeInternalIP,
+			"fda0:23::2":  v1.NodeInternalIP,
+			"8.8.8.8":     v1.NodeExternalIP,
+			"2001:db8::2": v1.NodeExternalIP,
+		})
+	})
+
+	t.Run("instance with both reservedAddresses and info set, some overlap, each adding some", func(t *testing.T) {
+		instance := anexiaInstance{
+			reservedAddresses: []string{"10.0.0.2", "8.8.8.8", "2001:db8::2"},
+			info: &info.Info{
+				Network: []info.Network{
+					{
+						IPv4: []string{"10.0.0.2"},
+						IPv6: []string{"fda0:23::2"},
+					},
+					{
+						IPv6: []string{"2001:db8::2"},
+					},
+				},
+			},
+		}
+
+		addressCheck(t, "expected addresses", &instance, map[string]v1.NodeAddressType{
+			"10.0.0.2":    v1.NodeInternalIP,
+			"fda0:23::2":  v1.NodeInternalIP,
+			"8.8.8.8":     v1.NodeExternalIP,
+			"2001:db8::2": v1.NodeExternalIP,
+		})
+	})
+}
diff --git a/test/e2e/provisioning/all_e2e_test.go b/test/e2e/provisioning/all_e2e_test.go
index 205d82d3..25244065 100644
--- a/test/e2e/provisioning/all_e2e_test.go
+++ b/test/e2e/provisioning/all_e2e_test.go
@@ -629,7 +629,7 @@ func TestAzureProvisioningE2E(t *testing.T) {
 		t.Fatal("unable to run the test suite, AZURE_TENANT_ID, AZURE_SUBSCRIPTION_ID, AZURE_CLIENT_ID and AZURE_CLIENT_SECRET environment variables cannot be empty")
 	}
 
-	selector := Not(OsSelector("sles", "amzn2", "rhel", "rockylinux", "flatcar"))
+	selector := Not(OsSelector("sles", "amzn2"))
 	// act
 	params := []string{
 		fmt.Sprintf("<< AZURE_TENANT_ID >>=%s", azureTenantID),
diff --git a/test/e2e/provisioning/helper.go b/test/e2e/provisioning/helper.go
index f8825434..39812773 100644
--- a/test/e2e/provisioning/helper.go
+++ b/test/e2e/provisioning/helper.go
@@ -57,11 +57,11 @@ var (
 	}
 
 	vSphereOSImageTemplates = map[string]string{
-		string(providerconfigtypes.OperatingSystemCentOS):     "centos-7",
-		string(providerconfigtypes.OperatingSystemFlatcar):    "flatcar-3033.2.2",
-		string(providerconfigtypes.OperatingSystemRHEL):       "rhel-8.6",
-		string(providerconfigtypes.OperatingSystemRockyLinux): "rockylinux-8",
-		string(providerconfigtypes.OperatingSystemUbuntu):     "ubuntu-20.04",
+		string(providerconfigtypes.OperatingSystemCentOS):     "kkp-centos-7",
+		string(providerconfigtypes.OperatingSystemFlatcar):    "kkp-flatcar-3033.2.2",
+		string(providerconfigtypes.OperatingSystemRHEL):       "kkp-rhel-8.6",
+		string(providerconfigtypes.OperatingSystemRockyLinux): "kkp-rockylinux-8",
+		string(providerconfigtypes.OperatingSystemUbuntu):     "kkp-ubuntu-20.04",
 	}
 )