Skip to content

Commit d18ce77

Browse files
authored
Use addresses instead of node ref for rhel aws instances (#744)
* adding the NodeAddressType to machine Addresses() method Signed-off-by: Moath Qasim <[email protected]> * remove aws rhel subscription based on private dns name Signed-off-by: Moath Qasim <[email protected]> * fix linting Signed-off-by: Moath Qasim <[email protected]> * fix the NodeAddressType assignment in azure Signed-off-by: Moath Qasim <[email protected]> Signed-off-by: Moath Qasim <[email protected]>
1 parent 4d3add2 commit d18ce77

File tree

15 files changed

+102
-63
lines changed

15 files changed

+102
-63
lines changed

pkg/cloudprovider/instance/instance.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@ limitations under the License.
1616

1717
package instance
1818

19+
import v1 "k8s.io/api/core/v1"
20+
1921
// Instance represents a instance on the cloud provider
2022
type Instance interface {
2123
// Name returns the instance name.
2224
Name() string
2325
// ID returns the instance identifier.
2426
ID() string
2527
// Addresses returns a list of addresses associated with the instance.
26-
Addresses() []string
28+
Addresses() map[string]v1.NodeAddressType
2729
// Status returns the instance status.
2830
Status() Status
2931
}

pkg/cloudprovider/provider/alibaba/provider.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737
"github.com/kubermatic/machine-controller/pkg/providerconfig"
3838
providerconfigtypes "github.com/kubermatic/machine-controller/pkg/providerconfig/types"
3939

40+
v1 "k8s.io/api/core/v1"
4041
"k8s.io/apimachinery/pkg/types"
4142
)
4243

@@ -85,10 +86,10 @@ func (a *alibabaInstance) ID() string {
8586
return a.instance.InstanceId
8687
}
8788

88-
func (a *alibabaInstance) Addresses() []string {
89-
var primaryIPAddresses []string
89+
func (a *alibabaInstance) Addresses() map[string]v1.NodeAddressType {
90+
primaryIPAddresses := map[string]v1.NodeAddressType{}
9091
for _, networkInterface := range a.instance.NetworkInterfaces.NetworkInterface {
91-
primaryIPAddresses = append(primaryIPAddresses, networkInterface.PrimaryIpAddress)
92+
primaryIPAddresses[networkInterface.PrimaryIpAddress] = v1.NodeInternalIP
9293
}
9394

9495
return primaryIPAddresses

pkg/cloudprovider/provider/aws/provider.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import (
4343
providerconfigtypes "github.com/kubermatic/machine-controller/pkg/providerconfig/types"
4444
"github.com/kubermatic/machine-controller/pkg/userdata/convert"
4545

46+
v1 "k8s.io/api/core/v1"
4647
"k8s.io/apimachinery/pkg/runtime"
4748
"k8s.io/apimachinery/pkg/types"
4849
"k8s.io/apimachinery/pkg/util/sets"
@@ -741,13 +742,17 @@ func (d *awsInstance) ID() string {
741742
return aws.StringValue(d.instance.InstanceId)
742743
}
743744

744-
func (d *awsInstance) Addresses() []string {
745-
return []string{
746-
aws.StringValue(d.instance.PublicIpAddress),
747-
aws.StringValue(d.instance.PublicDnsName),
748-
aws.StringValue(d.instance.PrivateIpAddress),
749-
aws.StringValue(d.instance.PrivateDnsName),
745+
func (d *awsInstance) Addresses() map[string]v1.NodeAddressType {
746+
addresses := map[string]v1.NodeAddressType{
747+
aws.StringValue(d.instance.PublicIpAddress): v1.NodeExternalIP,
748+
aws.StringValue(d.instance.PublicDnsName): v1.NodeExternalDNS,
749+
aws.StringValue(d.instance.PrivateIpAddress): v1.NodeInternalIP,
750+
aws.StringValue(d.instance.PrivateDnsName): v1.NodeInternalDNS,
750751
}
752+
753+
delete(addresses, "")
754+
755+
return addresses
751756
}
752757

753758
func (d *awsInstance) Status() instance.Status {

pkg/cloudprovider/provider/azure/provider.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import (
4040
"github.com/kubermatic/machine-controller/pkg/providerconfig"
4141
providerconfigtypes "github.com/kubermatic/machine-controller/pkg/providerconfig/types"
4242

43+
v1 "k8s.io/api/core/v1"
4344
"k8s.io/apimachinery/pkg/types"
4445
"k8s.io/klog"
4546
"k8s.io/utils/pointer"
@@ -91,11 +92,11 @@ type config struct {
9192

9293
type azureVM struct {
9394
vm *compute.VirtualMachine
94-
ipAddresses []string
95+
ipAddresses map[string]v1.NodeAddressType
9596
status instance.Status
9697
}
9798

98-
func (vm *azureVM) Addresses() []string {
99+
func (vm *azureVM) Addresses() map[string]v1.NodeAddressType {
99100
return vm.ipAddresses
100101
}
101102

@@ -255,8 +256,11 @@ func (p *provider) getConfig(s v1alpha1.ProviderSpec) (*config, *providerconfigt
255256
return &c, &pconfig, nil
256257
}
257258

258-
func getVMIPAddresses(ctx context.Context, c *config, vm *compute.VirtualMachine) ([]string, error) {
259-
var ipAddresses []string
259+
func getVMIPAddresses(ctx context.Context, c *config, vm *compute.VirtualMachine) (map[string]v1.NodeAddressType, error) {
260+
var (
261+
ipAddresses = map[string]v1.NodeAddressType{}
262+
err error
263+
)
260264

261265
if vm.VirtualMachineProperties == nil {
262266
return nil, fmt.Errorf("machine is missing properties")
@@ -277,17 +281,16 @@ func getVMIPAddresses(ctx context.Context, c *config, vm *compute.VirtualMachine
277281

278282
splitIfaceID := strings.Split(*iface.ID, "/")
279283
ifaceName := splitIfaceID[len(splitIfaceID)-1]
280-
addrs, err := getNICIPAddresses(ctx, c, ifaceName)
284+
ipAddresses, err = getNICIPAddresses(ctx, c, ifaceName)
281285
if vm.NetworkProfile.NetworkInterfaces == nil {
282286
return nil, fmt.Errorf("failed to get addresses for interface %q: %v", ifaceName, err)
283287
}
284-
ipAddresses = append(ipAddresses, addrs...)
285288
}
286289

287290
return ipAddresses, nil
288291
}
289292

290-
func getNICIPAddresses(ctx context.Context, c *config, ifaceName string) ([]string, error) {
293+
func getNICIPAddresses(ctx context.Context, c *config, ifaceName string) (map[string]v1.NodeAddressType, error) {
291294
ifClient, err := getInterfacesClient(c)
292295
if err != nil {
293296
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
298301
return nil, fmt.Errorf("failed to get interface %q: %v", ifaceName, err.Error())
299302
}
300303

301-
var ipAddresses []string
304+
ipAddresses := map[string]v1.NodeAddressType{}
302305

303306
if netIf.IPConfigurations != nil {
304307
for _, conf := range *netIf.IPConfigurations {
@@ -320,15 +323,18 @@ func getNICIPAddresses(ctx context.Context, c *config, ifaceName string) ([]stri
320323
if err != nil {
321324
return nil, fmt.Errorf("failed to retrieve IP string for IP %q: %v", name, err)
322325
}
323-
ipAddresses = append(ipAddresses, publicIPs...)
326+
for _, ip := range publicIPs {
327+
ipAddresses[ip] = v1.NodeExternalIP
328+
}
324329
}
325330

326331
internalIPs, err := getInternalIPAddresses(ctx, c, ifaceName, name)
327332
if err != nil {
328333
return nil, fmt.Errorf("failed to retrieve internal IP string for IP %q: %v", name, err)
329334
}
330-
331-
ipAddresses = append(ipAddresses, internalIPs...)
335+
for _, ip := range internalIPs {
336+
ipAddresses[ip] = v1.NodeInternalIP
337+
}
332338

333339
}
334340
}

pkg/cloudprovider/provider/digitalocean/provider.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
"github.com/kubermatic/machine-controller/pkg/providerconfig"
3939
providerconfigtypes "github.com/kubermatic/machine-controller/pkg/providerconfig/types"
4040

41+
v1 "k8s.io/api/core/v1"
4142
"k8s.io/apimachinery/pkg/types"
4243
"k8s.io/apimachinery/pkg/util/sets"
4344
"k8s.io/apimachinery/pkg/util/wait"
@@ -494,13 +495,21 @@ func (d *doInstance) ID() string {
494495
return strconv.Itoa(d.droplet.ID)
495496
}
496497

497-
func (d *doInstance) Addresses() []string {
498-
var addresses []string
498+
func (d *doInstance) Addresses() map[string]v1.NodeAddressType {
499+
addresses := map[string]v1.NodeAddressType{}
499500
for _, n := range d.droplet.Networks.V4 {
500-
addresses = append(addresses, n.IPAddress)
501+
if n.Type == "public" {
502+
addresses[n.IPAddress] = v1.NodeExternalIP
503+
} else {
504+
addresses[n.IPAddress] = v1.NodeInternalIP
505+
}
501506
}
502507
for _, n := range d.droplet.Networks.V6 {
503-
addresses = append(addresses, n.IPAddress)
508+
if n.Type == "public" {
509+
addresses[n.IPAddress] = v1.NodeExternalIP
510+
} else {
511+
addresses[n.IPAddress] = v1.NodeInternalIP
512+
}
504513
}
505514
return addresses
506515
}

pkg/cloudprovider/provider/fake/provider.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package fake
1919
import (
2020
"encoding/json"
2121
"fmt"
22+
v1 "k8s.io/api/core/v1"
2223

2324
"github.com/kubermatic/machine-controller/pkg/apis/cluster/v1alpha1"
2425
"github.com/kubermatic/machine-controller/pkg/cloudprovider/instance"
@@ -44,7 +45,7 @@ func (f CloudProviderInstance) Name() string {
4445
func (f CloudProviderInstance) ID() string {
4546
return ""
4647
}
47-
func (f CloudProviderInstance) Addresses() []string {
48+
func (f CloudProviderInstance) Addresses() map[string]v1.NodeAddressType {
4849
return nil
4950
}
5051
func (f CloudProviderInstance) Status() instance.Status {

pkg/cloudprovider/provider/gce/instance.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import (
2626
"google.golang.org/api/compute/v1"
2727

2828
"github.com/kubermatic/machine-controller/pkg/cloudprovider/instance"
29+
30+
v1 "k8s.io/api/core/v1"
2931
)
3032

3133
// Possible instance statuses.
@@ -56,10 +58,10 @@ func (gi *googleInstance) ID() string {
5658
}
5759

5860
// Addresses implements instance.Instance.
59-
func (gi *googleInstance) Addresses() []string {
60-
var addrs []string
61+
func (gi *googleInstance) Addresses() map[string]v1.NodeAddressType {
62+
addrs := map[string]v1.NodeAddressType{}
6163
for _, ifc := range gi.ci.NetworkInterfaces {
62-
addrs = append(addrs, ifc.NetworkIP)
64+
addrs[ifc.NetworkIP] = v1.NodeInternalIP
6365
}
6466
return addrs
6567
}

pkg/cloudprovider/provider/hetzner/provider.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
"github.com/kubermatic/machine-controller/pkg/providerconfig"
3737
providerconfigtypes "github.com/kubermatic/machine-controller/pkg/providerconfig/types"
3838

39+
v1 "k8s.io/api/core/v1"
3940
"k8s.io/apimachinery/pkg/types"
4041
"k8s.io/klog"
4142
)
@@ -401,16 +402,17 @@ func (s *hetznerServer) ID() string {
401402
return strconv.Itoa(s.server.ID)
402403
}
403404

404-
func (s *hetznerServer) Addresses() []string {
405-
var addresses []string
405+
func (s *hetznerServer) Addresses() map[string]v1.NodeAddressType {
406+
addresses := map[string]v1.NodeAddressType{}
406407
for _, fips := range s.server.PublicNet.FloatingIPs {
407-
addresses = append(addresses, fips.IP.String())
408+
addresses[fips.IP.String()] = v1.NodeExternalIP
408409
}
409410
for _, privateNetwork := range s.server.PrivateNet {
410-
addresses = append(addresses, privateNetwork.IP.String())
411+
addresses[privateNetwork.IP.String()] = v1.NodeInternalIP
411412
}
412-
413-
return append(addresses, s.server.PublicNet.IPv4.IP.String(), s.server.PublicNet.IPv6.IP.String())
413+
addresses[s.server.PublicNet.IPv4.IP.String()] = v1.NodeExternalIP
414+
addresses[s.server.PublicNet.IPv6.IP.String()] = v1.NodeExternalIP
415+
return addresses
414416
}
415417

416418
func (s *hetznerServer) Status() instance.Status {

pkg/cloudprovider/provider/kubevirt/provider.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ func (k *kubeVirtServer) ID() string {
9191
return string(k.vmi.UID)
9292
}
9393

94-
func (k *kubeVirtServer) Addresses() []string {
95-
var addresses []string
94+
func (k *kubeVirtServer) Addresses() map[string]corev1.NodeAddressType {
95+
addresses := map[string]corev1.NodeAddressType{}
9696
for _, kvInterface := range k.vmi.Status.Interfaces {
9797
if address := strings.Split(kvInterface.IP, "/")[0]; address != "" {
98-
addresses = append(addresses, address)
98+
addresses[address] = corev1.NodeInternalIP
9999
}
100100
}
101101
return addresses

pkg/cloudprovider/provider/linode/provider.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import (
4141
"github.com/kubermatic/machine-controller/pkg/providerconfig"
4242
providerconfigtypes "github.com/kubermatic/machine-controller/pkg/providerconfig/types"
4343

44+
v1 "k8s.io/api/core/v1"
4445
"k8s.io/apimachinery/pkg/types"
4546
"k8s.io/apimachinery/pkg/util/sets"
4647
)
@@ -413,12 +414,12 @@ func (d *linodeInstance) ID() string {
413414
return strconv.Itoa(d.linode.ID)
414415
}
415416

416-
func (d *linodeInstance) Addresses() []string {
417-
var addresses []string
417+
func (d *linodeInstance) Addresses() map[string]v1.NodeAddressType {
418+
addresses := map[string]v1.NodeAddressType{}
418419
for _, n := range d.linode.IPv4 {
419-
addresses = append(addresses, n.String())
420+
addresses[n.String()] = v1.NodeInternalIP
420421
}
421-
addresses = append(addresses, d.linode.IPv6)
422+
addresses[d.linode.IPv6] = v1.NodeInternalIP
422423
return addresses
423424
}
424425

0 commit comments

Comments
 (0)