Repository: kubermatic/machine-controller
Pull request #744 (2020-04-20 16:41:38)

Use addresses instead of node ref for rhel aws instances
**What this PR does / why we need it**:
Attaching the Node Address Type to the created machines, and cleanup rhel subscription based on the private dns for aws cloud provider. 

**Which issue(s) this PR fixes**
Fixes kubermatic/kubermatic#5307

**Optional Release Note**:
<!--
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
```


kubermatic-bot: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/kubermatic/machine-controller/pull/744#" 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":[]} -->
moadqassem: cc @xmudrii: here I have made this PR to attach the Node Address Type for the addresses ;)  
kubermatic-bot: @moadqassem: The following test **failed**, say `/retest` to rerun all failed tests:

Test name | Commit | Details | Rerun command
--- | --- | --- | ---
pull-machine-controller-lint | 6ff575bf96e60dc2fe602a31706437bb26cb3edb | [link](https://public-prow.loodse.com/view/gcs/prow-dev-public-data/pr-logs/pull/kubermatic_machine-controller/744/pull-machine-controller-lint/1252276295027396608) | `/test pull-machine-controller-lint`

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

<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: /hold 
xrstf: /lgtm
kubermatic-bot: LGTM label has been added.  <details>Git tree hash: 2116798a8e808899579a9f9da9d74426e63028fd</details>
kubermatic-bot: New changes are detected. LGTM label has been removed.
moadqassem: /hold cancel
xmudrii: /hold
review in progress
kubermatic-bot: LGTM label has been added.  <details>Git tree hash: 94f23d93c30613b3a627a2ed29f4c94fc7fdf419</details>
xmudrii: /hold cancel

Patch:
diff --git a/pkg/cloudprovider/instance/instance.go b/pkg/cloudprovider/instance/instance.go
index 1657ecde..edadc991 100644
--- a/pkg/cloudprovider/instance/instance.go
+++ b/pkg/cloudprovider/instance/instance.go
@@ -16,6 +16,8 @@ limitations under the License.
 
 package instance
 
+import v1 "k8s.io/api/core/v1"
+
 // Instance represents a instance on the cloud provider
 type Instance interface {
 	// Name returns the instance name.
@@ -23,7 +25,7 @@ type Instance interface {
 	// ID returns the instance identifier.
 	ID() string
 	// Addresses returns a list of addresses associated with the instance.
-	Addresses() []string
+	Addresses() map[string]v1.NodeAddressType
 	// Status returns the instance status.
 	Status() Status
 }
diff --git a/pkg/cloudprovider/provider/alibaba/provider.go b/pkg/cloudprovider/provider/alibaba/provider.go
index 0d9ea376..c8b650b3 100644
--- a/pkg/cloudprovider/provider/alibaba/provider.go
+++ b/pkg/cloudprovider/provider/alibaba/provider.go
@@ -37,6 +37,7 @@ import (
 	"github.com/kubermatic/machine-controller/pkg/providerconfig"
 	providerconfigtypes "github.com/kubermatic/machine-controller/pkg/providerconfig/types"
 
+	v1 "k8s.io/api/core/v1"
 	"k8s.io/apimachinery/pkg/types"
 )
 
@@ -85,10 +86,10 @@ func (a *alibabaInstance) ID() string {
 	return a.instance.InstanceId
 }
 
-func (a *alibabaInstance) Addresses() []string {
-	var primaryIPAddresses []string
+func (a *alibabaInstance) Addresses() map[string]v1.NodeAddressType {
+	primaryIPAddresses := map[string]v1.NodeAddressType{}
 	for _, networkInterface := range a.instance.NetworkInterfaces.NetworkInterface {
-		primaryIPAddresses = append(primaryIPAddresses, networkInterface.PrimaryIpAddress)
+		primaryIPAddresses[networkInterface.PrimaryIpAddress] = v1.NodeInternalIP
 	}
 
 	return primaryIPAddresses
diff --git a/pkg/cloudprovider/provider/aws/provider.go b/pkg/cloudprovider/provider/aws/provider.go
index 49cfff85..9b60b001 100644
--- a/pkg/cloudprovider/provider/aws/provider.go
+++ b/pkg/cloudprovider/provider/aws/provider.go
@@ -43,6 +43,7 @@ import (
 	providerconfigtypes "github.com/kubermatic/machine-controller/pkg/providerconfig/types"
 	"github.com/kubermatic/machine-controller/pkg/userdata/convert"
 
+	v1 "k8s.io/api/core/v1"
 	"k8s.io/apimachinery/pkg/runtime"
 	"k8s.io/apimachinery/pkg/types"
 	"k8s.io/apimachinery/pkg/util/sets"
@@ -741,13 +742,17 @@ func (d *awsInstance) ID() string {
 	return aws.StringValue(d.instance.InstanceId)
 }
 
-func (d *awsInstance) Addresses() []string {
-	return []string{
-		aws.StringValue(d.instance.PublicIpAddress),
-		aws.StringValue(d.instance.PublicDnsName),
-		aws.StringValue(d.instance.PrivateIpAddress),
-		aws.StringValue(d.instance.PrivateDnsName),
+func (d *awsInstance) Addresses() map[string]v1.NodeAddressType {
+	addresses := map[string]v1.NodeAddressType{
+		aws.StringValue(d.instance.PublicIpAddress):  v1.NodeExternalIP,
+		aws.StringValue(d.instance.PublicDnsName):    v1.NodeExternalDNS,
+		aws.StringValue(d.instance.PrivateIpAddress): v1.NodeInternalIP,
+		aws.StringValue(d.instance.PrivateDnsName):   v1.NodeInternalDNS,
 	}
+
+	delete(addresses, "")
+
+	return addresses
 }
 
 func (d *awsInstance) Status() instance.Status {
diff --git a/pkg/cloudprovider/provider/azure/provider.go b/pkg/cloudprovider/provider/azure/provider.go
index b8e63719..50fc50d0 100644
--- a/pkg/cloudprovider/provider/azure/provider.go
+++ b/pkg/cloudprovider/provider/azure/provider.go
@@ -40,6 +40,7 @@ import (
 	"github.com/kubermatic/machine-controller/pkg/providerconfig"
 	providerconfigtypes "github.com/kubermatic/machine-controller/pkg/providerconfig/types"
 
+	v1 "k8s.io/api/core/v1"
 	"k8s.io/apimachinery/pkg/types"
 	"k8s.io/klog"
 	"k8s.io/utils/pointer"
@@ -91,11 +92,11 @@ type config struct {
 
 type azureVM struct {
 	vm          *compute.VirtualMachine
-	ipAddresses []string
+	ipAddresses map[string]v1.NodeAddressType
 	status      instance.Status
 }
 
-func (vm *azureVM) Addresses() []string {
+func (vm *azureVM) Addresses() map[string]v1.NodeAddressType {
 	return vm.ipAddresses
 }
 
@@ -255,8 +256,11 @@ func (p *provider) getConfig(s v1alpha1.ProviderSpec) (*config, *providerconfigt
 	return &c, &pconfig, nil
 }
 
-func getVMIPAddresses(ctx context.Context, c *config, vm *compute.VirtualMachine) ([]string, error) {
-	var ipAddresses []string
+func getVMIPAddresses(ctx context.Context, c *config, vm *compute.VirtualMachine) (map[string]v1.NodeAddressType, error) {
+	var (
+		ipAddresses = map[string]v1.NodeAddressType{}
+		err         error
+	)
 
 	if vm.VirtualMachineProperties == nil {
 		return nil, fmt.Errorf("machine is missing properties")
@@ -277,17 +281,16 @@ func getVMIPAddresses(ctx context.Context, c *config, vm *compute.VirtualMachine
 
 		splitIfaceID := strings.Split(*iface.ID, "/")
 		ifaceName := splitIfaceID[len(splitIfaceID)-1]
-		addrs, err := getNICIPAddresses(ctx, c, ifaceName)
+		ipAddresses, err = getNICIPAddresses(ctx, c, ifaceName)
 		if vm.NetworkProfile.NetworkInterfaces == nil {
 			return nil, fmt.Errorf("failed to get addresses for interface %q: %v", ifaceName, err)
 		}
-		ipAddresses = append(ipAddresses, addrs...)
 	}
 
 	return ipAddresses, nil
 }
 
-func getNICIPAddresses(ctx context.Context, c *config, ifaceName string) ([]string, error) {
+func getNICIPAddresses(ctx context.Context, c *config, ifaceName string) (map[string]v1.NodeAddressType, error) {
 	ifClient, err := getInterfacesClient(c)
 	if err != nil {
 		return nil, fmt.Errorf("failed to create interfaces client: %v", err)
@@ -298,7 +301,7 @@ func getNICIPAddresses(ctx context.Context, c *config, ifaceName string) ([]stri
 		return nil, fmt.Errorf("failed to get interface %q: %v", ifaceName, err.Error())
 	}
 
-	var ipAddresses []string
+	ipAddresses := map[string]v1.NodeAddressType{}
 
 	if netIf.IPConfigurations != nil {
 		for _, conf := range *netIf.IPConfigurations {
@@ -320,15 +323,18 @@ func getNICIPAddresses(ctx context.Context, c *config, ifaceName string) ([]stri
 				if err != nil {
 					return nil, fmt.Errorf("failed to retrieve IP string for IP %q: %v", name, err)
 				}
-				ipAddresses = append(ipAddresses, publicIPs...)
+				for _, ip := range publicIPs {
+					ipAddresses[ip] = v1.NodeExternalIP
+				}
 			}
 
 			internalIPs, err := getInternalIPAddresses(ctx, c, ifaceName, name)
 			if err != nil {
 				return nil, fmt.Errorf("failed to retrieve internal IP string for IP %q: %v", name, err)
 			}
-
-			ipAddresses = append(ipAddresses, internalIPs...)
+			for _, ip := range internalIPs {
+				ipAddresses[ip] = v1.NodeInternalIP
+			}
 
 		}
 	}
diff --git a/pkg/cloudprovider/provider/digitalocean/provider.go b/pkg/cloudprovider/provider/digitalocean/provider.go
index 22aeee1e..6c80940e 100644
--- a/pkg/cloudprovider/provider/digitalocean/provider.go
+++ b/pkg/cloudprovider/provider/digitalocean/provider.go
@@ -38,6 +38,7 @@ import (
 	"github.com/kubermatic/machine-controller/pkg/providerconfig"
 	providerconfigtypes "github.com/kubermatic/machine-controller/pkg/providerconfig/types"
 
+	v1 "k8s.io/api/core/v1"
 	"k8s.io/apimachinery/pkg/types"
 	"k8s.io/apimachinery/pkg/util/sets"
 	"k8s.io/apimachinery/pkg/util/wait"
@@ -494,13 +495,21 @@ func (d *doInstance) ID() string {
 	return strconv.Itoa(d.droplet.ID)
 }
 
-func (d *doInstance) Addresses() []string {
-	var addresses []string
+func (d *doInstance) Addresses() map[string]v1.NodeAddressType {
+	addresses := map[string]v1.NodeAddressType{}
 	for _, n := range d.droplet.Networks.V4 {
-		addresses = append(addresses, n.IPAddress)
+		if n.Type == "public" {
+			addresses[n.IPAddress] = v1.NodeExternalIP
+		} else {
+			addresses[n.IPAddress] = v1.NodeInternalIP
+		}
 	}
 	for _, n := range d.droplet.Networks.V6 {
-		addresses = append(addresses, n.IPAddress)
+		if n.Type == "public" {
+			addresses[n.IPAddress] = v1.NodeExternalIP
+		} else {
+			addresses[n.IPAddress] = v1.NodeInternalIP
+		}
 	}
 	return addresses
 }
diff --git a/pkg/cloudprovider/provider/fake/provider.go b/pkg/cloudprovider/provider/fake/provider.go
index 722c40c1..4071abda 100644
--- a/pkg/cloudprovider/provider/fake/provider.go
+++ b/pkg/cloudprovider/provider/fake/provider.go
@@ -19,6 +19,7 @@ package fake
 import (
 	"encoding/json"
 	"fmt"
+	v1 "k8s.io/api/core/v1"
 
 	"github.com/kubermatic/machine-controller/pkg/apis/cluster/v1alpha1"
 	"github.com/kubermatic/machine-controller/pkg/cloudprovider/instance"
@@ -44,7 +45,7 @@ func (f CloudProviderInstance) Name() string {
 func (f CloudProviderInstance) ID() string {
 	return ""
 }
-func (f CloudProviderInstance) Addresses() []string {
+func (f CloudProviderInstance) Addresses() map[string]v1.NodeAddressType {
 	return nil
 }
 func (f CloudProviderInstance) Status() instance.Status {
diff --git a/pkg/cloudprovider/provider/gce/instance.go b/pkg/cloudprovider/provider/gce/instance.go
index fe5b4bee..bb6ce3ef 100644
--- a/pkg/cloudprovider/provider/gce/instance.go
+++ b/pkg/cloudprovider/provider/gce/instance.go
@@ -26,6 +26,8 @@ import (
 	"google.golang.org/api/compute/v1"
 
 	"github.com/kubermatic/machine-controller/pkg/cloudprovider/instance"
+
+	v1 "k8s.io/api/core/v1"
 )
 
 // Possible instance statuses.
@@ -56,10 +58,10 @@ func (gi *googleInstance) ID() string {
 }
 
 // Addresses implements instance.Instance.
-func (gi *googleInstance) Addresses() []string {
-	var addrs []string
+func (gi *googleInstance) Addresses() map[string]v1.NodeAddressType {
+	addrs := map[string]v1.NodeAddressType{}
 	for _, ifc := range gi.ci.NetworkInterfaces {
-		addrs = append(addrs, ifc.NetworkIP)
+		addrs[ifc.NetworkIP] = v1.NodeInternalIP
 	}
 	return addrs
 }
diff --git a/pkg/cloudprovider/provider/hetzner/provider.go b/pkg/cloudprovider/provider/hetzner/provider.go
index d3a6f5a0..1623328c 100644
--- a/pkg/cloudprovider/provider/hetzner/provider.go
+++ b/pkg/cloudprovider/provider/hetzner/provider.go
@@ -36,6 +36,7 @@ import (
 	"github.com/kubermatic/machine-controller/pkg/providerconfig"
 	providerconfigtypes "github.com/kubermatic/machine-controller/pkg/providerconfig/types"
 
+	v1 "k8s.io/api/core/v1"
 	"k8s.io/apimachinery/pkg/types"
 	"k8s.io/klog"
 )
@@ -401,16 +402,17 @@ func (s *hetznerServer) ID() string {
 	return strconv.Itoa(s.server.ID)
 }
 
-func (s *hetznerServer) Addresses() []string {
-	var addresses []string
+func (s *hetznerServer) Addresses() map[string]v1.NodeAddressType {
+	addresses := map[string]v1.NodeAddressType{}
 	for _, fips := range s.server.PublicNet.FloatingIPs {
-		addresses = append(addresses, fips.IP.String())
+		addresses[fips.IP.String()] = v1.NodeExternalIP
 	}
 	for _, privateNetwork := range s.server.PrivateNet {
-		addresses = append(addresses, privateNetwork.IP.String())
+		addresses[privateNetwork.IP.String()] = v1.NodeInternalIP
 	}
-
-	return append(addresses, s.server.PublicNet.IPv4.IP.String(), s.server.PublicNet.IPv6.IP.String())
+	addresses[s.server.PublicNet.IPv4.IP.String()] = v1.NodeExternalIP
+	addresses[s.server.PublicNet.IPv6.IP.String()] = v1.NodeExternalIP
+	return addresses
 }
 
 func (s *hetznerServer) Status() instance.Status {
diff --git a/pkg/cloudprovider/provider/kubevirt/provider.go b/pkg/cloudprovider/provider/kubevirt/provider.go
index 91380166..6ad82364 100644
--- a/pkg/cloudprovider/provider/kubevirt/provider.go
+++ b/pkg/cloudprovider/provider/kubevirt/provider.go
@@ -91,11 +91,11 @@ func (k *kubeVirtServer) ID() string {
 	return string(k.vmi.UID)
 }
 
-func (k *kubeVirtServer) Addresses() []string {
-	var addresses []string
+func (k *kubeVirtServer) Addresses() map[string]corev1.NodeAddressType {
+	addresses := map[string]corev1.NodeAddressType{}
 	for _, kvInterface := range k.vmi.Status.Interfaces {
 		if address := strings.Split(kvInterface.IP, "/")[0]; address != "" {
-			addresses = append(addresses, address)
+			addresses[address] = corev1.NodeInternalIP
 		}
 	}
 	return addresses
diff --git a/pkg/cloudprovider/provider/linode/provider.go b/pkg/cloudprovider/provider/linode/provider.go
index 30ce0774..a344c76c 100644
--- a/pkg/cloudprovider/provider/linode/provider.go
+++ b/pkg/cloudprovider/provider/linode/provider.go
@@ -41,6 +41,7 @@ import (
 	"github.com/kubermatic/machine-controller/pkg/providerconfig"
 	providerconfigtypes "github.com/kubermatic/machine-controller/pkg/providerconfig/types"
 
+	v1 "k8s.io/api/core/v1"
 	"k8s.io/apimachinery/pkg/types"
 	"k8s.io/apimachinery/pkg/util/sets"
 )
@@ -413,12 +414,12 @@ func (d *linodeInstance) ID() string {
 	return strconv.Itoa(d.linode.ID)
 }
 
-func (d *linodeInstance) Addresses() []string {
-	var addresses []string
+func (d *linodeInstance) Addresses() map[string]v1.NodeAddressType {
+	addresses := map[string]v1.NodeAddressType{}
 	for _, n := range d.linode.IPv4 {
-		addresses = append(addresses, n.String())
+		addresses[n.String()] = v1.NodeInternalIP
 	}
-	addresses = append(addresses, d.linode.IPv6)
+	addresses[d.linode.IPv6] = v1.NodeInternalIP
 	return addresses
 }
 
diff --git a/pkg/cloudprovider/provider/openstack/provider.go b/pkg/cloudprovider/provider/openstack/provider.go
index 8a1997e9..745f8b7a 100644
--- a/pkg/cloudprovider/provider/openstack/provider.go
+++ b/pkg/cloudprovider/provider/openstack/provider.go
@@ -42,6 +42,7 @@ import (
 	"github.com/kubermatic/machine-controller/pkg/providerconfig"
 	providerconfigtypes "github.com/kubermatic/machine-controller/pkg/providerconfig/types"
 
+	v1 "k8s.io/api/core/v1"
 	"k8s.io/apimachinery/pkg/runtime"
 	"k8s.io/apimachinery/pkg/types"
 	utilruntime "k8s.io/apimachinery/pkg/util/runtime"
@@ -748,12 +749,12 @@ func (d *osInstance) ID() string {
 	return d.server.ID
 }
 
-func (d *osInstance) Addresses() []string {
-	var addresses []string
+func (d *osInstance) Addresses() map[string]v1.NodeAddressType {
+	addresses := map[string]v1.NodeAddressType{}
 	for _, networkAddresses := range d.server.Addresses {
 		for _, element := range networkAddresses.([]interface{}) {
 			address := element.(map[string]interface{})
-			addresses = append(addresses, address["addr"].(string))
+			addresses[address["addr"].(string)] = ""
 		}
 	}
 
diff --git a/pkg/cloudprovider/provider/packet/provider.go b/pkg/cloudprovider/provider/packet/provider.go
index 79226cd3..75f6e023 100644
--- a/pkg/cloudprovider/provider/packet/provider.go
+++ b/pkg/cloudprovider/provider/packet/provider.go
@@ -34,6 +34,7 @@ import (
 	"github.com/kubermatic/machine-controller/pkg/providerconfig"
 	providerconfigtypes "github.com/kubermatic/machine-controller/pkg/providerconfig/types"
 
+	v1 "k8s.io/api/core/v1"
 	"k8s.io/apimachinery/pkg/runtime"
 	"k8s.io/apimachinery/pkg/types"
 	"k8s.io/klog"
@@ -356,11 +357,15 @@ func (s *packetDevice) ID() string {
 	return s.device.ID
 }
 
-func (s *packetDevice) Addresses() []string {
+func (s *packetDevice) Addresses() map[string]v1.NodeAddressType {
 	// returns addresses in CIDR format
-	var addresses []string
+	addresses := map[string]v1.NodeAddressType{}
 	for _, ip := range s.device.Network {
-		addresses = append(addresses, ip.Address)
+		if ip.Public {
+			addresses[ip.Address] = v1.NodeExternalIP
+			continue
+		}
+		addresses[ip.Address] = v1.NodeInternalIP
 	}
 
 	return addresses
diff --git a/pkg/cloudprovider/provider/vsphere/provider.go b/pkg/cloudprovider/provider/vsphere/provider.go
index 171bbe2c..da3922c6 100644
--- a/pkg/cloudprovider/provider/vsphere/provider.go
+++ b/pkg/cloudprovider/provider/vsphere/provider.go
@@ -82,7 +82,7 @@ type Server struct {
 	name      string
 	id        string
 	status    instance.Status
-	addresses []string
+	addresses map[string]corev1.NodeAddressType
 }
 
 func (vsphereServer Server) Name() string {
@@ -93,7 +93,7 @@ func (vsphereServer Server) ID() string {
 	return vsphereServer.id
 }
 
-func (vsphereServer Server) Addresses() []string {
+func (vsphereServer Server) Addresses() map[string]corev1.NodeAddressType {
 	return vsphereServer.addresses
 }
 
@@ -480,7 +480,7 @@ func (p *provider) Get(machine *v1alpha1.Machine, data *cloudprovidertypes.Provi
 	}
 
 	// virtualMachine.IsToolsRunning panics when executed on a VM that is not powered on
-	addresses := []string{}
+	addresses := map[string]corev1.NodeAddressType{}
 	isGuestToolsRunning, err := virtualMachine.IsToolsRunning(ctx)
 	if err != nil {
 		return nil, fmt.Errorf("failed to check if guest utils are running: %v", err)
@@ -496,7 +496,7 @@ func (p *provider) Get(machine *v1alpha1.Machine, data *cloudprovidertypes.Provi
 			for _, address := range nic.IpAddress {
 				// Exclude ipv6 link-local addresses and default Docker bridge
 				if !strings.HasPrefix(address, "fe80:") && !strings.HasPrefix(address, "172.17.") {
-					addresses = append(addresses, address)
+					addresses[address] = ""
 				}
 			}
 		}
diff --git a/pkg/controller/machine/machine.go b/pkg/controller/machine/machine.go
index d289f662..a8516294 100644
--- a/pkg/controller/machine/machine.go
+++ b/pkg/controller/machine/machine.go
@@ -572,7 +572,11 @@ func (r *Reconciler) deleteCloudProviderInstance(prov cloudprovidertypes.Provide
 		if rhelConfig.RHSMOfflineToken != "" {
 			machineName := machine.Name
 			if machineConfig.CloudProvider == providerconfigtypes.CloudProviderAWS {
-				machineName = machine.Status.NodeRef.Name
+				for _, address := range machine.Status.Addresses {
+					if address.Type == corev1.NodeInternalDNS {
+						machineName = address.Address
+					}
+				}
 			}
 
 			if err := r.redhatSubscriptionManager.UnregisterInstance(rhelConfig.RHSMOfflineToken, machineName); err != nil {
@@ -698,8 +702,8 @@ func (r *Reconciler) ensureInstanceExistsForMachine(
 	eventMessage := fmt.Sprintf("Found instance at cloud provider, addresses: %v", addresses)
 	r.recorder.Event(machine, corev1.EventTypeNormal, "InstanceFound", eventMessage)
 	machineAddresses := []corev1.NodeAddress{}
-	for _, address := range addresses {
-		machineAddresses = append(machineAddresses, corev1.NodeAddress{Address: address})
+	for address, addressType := range addresses {
+		machineAddresses = append(machineAddresses, corev1.NodeAddress{Address: address, Type: addressType})
 	}
 	if err := r.updateMachine(machine, func(m *clusterv1alpha1.Machine) {
 		m.Status.Addresses = machineAddresses
@@ -873,7 +877,7 @@ func (r *Reconciler) getNode(instance instance.Instance, provider providerconfig
 			}
 		}
 		for _, nodeAddress := range node.Status.Addresses {
-			for _, instanceAddress := range instance.Addresses() {
+			for instanceAddress := range instance.Addresses() {
 				if nodeAddress.Address == instanceAddress {
 					return node.DeepCopy(), true, nil
 				}


Test patch:
diff --git a/pkg/controller/machine/machine_test.go b/pkg/controller/machine/machine_test.go
index f8f312d3..42661ba0 100644
--- a/pkg/controller/machine/machine_test.go
+++ b/pkg/controller/machine/machine_test.go
@@ -48,7 +48,7 @@ func init() {
 type fakeInstance struct {
 	name      string
 	id        string
-	addresses []string
+	addresses map[string]corev1.NodeAddressType
 	status    instance.Status
 }
 
@@ -64,7 +64,7 @@ func (i *fakeInstance) Status() instance.Status {
 	return i.status
 }
 
-func (i *fakeInstance) Addresses() []string {
+func (i *fakeInstance) Addresses() map[string]corev1.NodeAddressType {
 	return i.addresses
 }
 
@@ -115,7 +115,7 @@ func TestController_GetNode(t *testing.T) {
 			resNode:  nil,
 			exists:   false,
 			err:      nil,
-			instance: &fakeInstance{id: "99", addresses: []string{"192.168.1.99"}},
+			instance: &fakeInstance{id: "99", addresses: map[string]corev1.NodeAddressType{"192.168.1.99": corev1.NodeInternalIP}},
 		},
 		{
 			name:     "node not found - no suitable node",
@@ -123,7 +123,7 @@ func TestController_GetNode(t *testing.T) {
 			resNode:  nil,
 			exists:   false,
 			err:      nil,
-			instance: &fakeInstance{id: "99", addresses: []string{"192.168.1.99"}},
+			instance: &fakeInstance{id: "99", addresses: map[string]corev1.NodeAddressType{"192.168.1.99": corev1.NodeInternalIP}},
 		},
 		{
 			name:     "node found by provider id",
@@ -131,7 +131,7 @@ func TestController_GetNode(t *testing.T) {
 			resNode:  &node1,
 			exists:   true,
 			err:      nil,
-			instance: &fakeInstance{id: "1", addresses: []string{""}},
+			instance: &fakeInstance{id: "1", addresses: map[string]corev1.NodeAddressType{"": ""}},
 		},
 		{
 			name:     "node found by internal ip",
@@ -139,7 +139,7 @@ func TestController_GetNode(t *testing.T) {
 			resNode:  &node3,
 			exists:   true,
 			err:      nil,
-			instance: &fakeInstance{id: "3", addresses: []string{"192.168.1.3"}},
+			instance: &fakeInstance{id: "3", addresses: map[string]corev1.NodeAddressType{"192.168.1.3": corev1.NodeInternalIP}},
 		},
 		{
 			name:     "node found by external ip",
@@ -147,7 +147,7 @@ func TestController_GetNode(t *testing.T) {
 			resNode:  &node3,
 			exists:   true,
 			err:      nil,
-			instance: &fakeInstance{id: "3", addresses: []string{"172.16.1.3"}},
+			instance: &fakeInstance{id: "3", addresses: map[string]corev1.NodeAddressType{"172.16.1.3": corev1.NodeInternalIP}},
 		},
 	}