Skip to content

Commit 9eb3140

Browse files
authored
Merge pull request #963 from nader-ziada/ip-across-accounts
🐛 Leave DNS name empty for outbound public ip
2 parents 5392d74 + d82721b commit 9eb3140

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

cloud/services/publicips/publicips.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,20 @@ func (s *Service) Reconcile(ctx context.Context) error {
3131
for _, ip := range s.Scope.PublicIPSpecs() {
3232
s.Scope.V(2).Info("creating public IP", "public ip", ip.Name)
3333

34+
// only set DNS properties if there is a DNS name specified
3435
addressVersion := network.IPv4
3536
if ip.IsIPv6 {
3637
addressVersion = network.IPv6
3738
}
3839

40+
var dnsSettings *network.PublicIPAddressDNSSettings
41+
if ip.DNSName != "" {
42+
dnsSettings = &network.PublicIPAddressDNSSettings{
43+
DomainNameLabel: to.StringPtr(strings.ToLower(ip.Name)),
44+
Fqdn: to.StringPtr(ip.DNSName),
45+
}
46+
}
47+
3948
err := s.Client.CreateOrUpdate(
4049
ctx,
4150
s.Scope.ResourceGroup(),
@@ -47,10 +56,7 @@ func (s *Service) Reconcile(ctx context.Context) error {
4756
PublicIPAddressPropertiesFormat: &network.PublicIPAddressPropertiesFormat{
4857
PublicIPAddressVersion: addressVersion,
4958
PublicIPAllocationMethod: network.Static,
50-
DNSSettings: &network.PublicIPAddressDNSSettings{
51-
DomainNameLabel: to.StringPtr(strings.ToLower(ip.Name)),
52-
Fqdn: to.StringPtr(ip.DNSName),
53-
},
59+
DNSSettings: dnsSettings,
5460
},
5561
},
5662
)

cloud/services/publicips/publicips_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ package publicips
1919
import (
2020
"context"
2121
"net/http"
22-
gomockinternal "sigs.k8s.io/cluster-api-provider-azure/internal/test/matchers/gomock"
2322
"testing"
2423

24+
gomockinternal "sigs.k8s.io/cluster-api-provider-azure/internal/test/matchers/gomock"
25+
2526
azure "sigs.k8s.io/cluster-api-provider-azure/cloud"
2627

2728
. "github.com/onsi/gomega"
@@ -106,10 +107,6 @@ func TestReconcilePublicIP(t *testing.T) {
106107
PublicIPAddressPropertiesFormat: &network.PublicIPAddressPropertiesFormat{
107108
PublicIPAddressVersion: network.IPv4,
108109
PublicIPAllocationMethod: network.Static,
109-
DNSSettings: &network.PublicIPAddressDNSSettings{
110-
DomainNameLabel: to.StringPtr("my-publicip-3"),
111-
Fqdn: to.StringPtr(""),
112-
},
113110
},
114111
})).Times(1),
115112
m.CreateOrUpdate(context.TODO(), "my-rg", "my-publicip-ipv6", gomockinternal.DiffEq(network.PublicIPAddress{

0 commit comments

Comments
 (0)