Skip to content

Commit

Permalink
Merge pull request #963 from nader-ziada/ip-across-accounts
Browse files Browse the repository at this point in the history
🐛  Leave DNS name empty for outbound public ip
  • Loading branch information
k8s-ci-robot authored Oct 1, 2020
2 parents 5392d74 + d82721b commit 9eb3140
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
14 changes: 10 additions & 4 deletions cloud/services/publicips/publicips.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,20 @@ func (s *Service) Reconcile(ctx context.Context) error {
for _, ip := range s.Scope.PublicIPSpecs() {
s.Scope.V(2).Info("creating public IP", "public ip", ip.Name)

// only set DNS properties if there is a DNS name specified
addressVersion := network.IPv4
if ip.IsIPv6 {
addressVersion = network.IPv6
}

var dnsSettings *network.PublicIPAddressDNSSettings
if ip.DNSName != "" {
dnsSettings = &network.PublicIPAddressDNSSettings{
DomainNameLabel: to.StringPtr(strings.ToLower(ip.Name)),
Fqdn: to.StringPtr(ip.DNSName),
}
}

err := s.Client.CreateOrUpdate(
ctx,
s.Scope.ResourceGroup(),
Expand All @@ -47,10 +56,7 @@ func (s *Service) Reconcile(ctx context.Context) error {
PublicIPAddressPropertiesFormat: &network.PublicIPAddressPropertiesFormat{
PublicIPAddressVersion: addressVersion,
PublicIPAllocationMethod: network.Static,
DNSSettings: &network.PublicIPAddressDNSSettings{
DomainNameLabel: to.StringPtr(strings.ToLower(ip.Name)),
Fqdn: to.StringPtr(ip.DNSName),
},
DNSSettings: dnsSettings,
},
},
)
Expand Down
7 changes: 2 additions & 5 deletions cloud/services/publicips/publicips_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ package publicips
import (
"context"
"net/http"
gomockinternal "sigs.k8s.io/cluster-api-provider-azure/internal/test/matchers/gomock"
"testing"

gomockinternal "sigs.k8s.io/cluster-api-provider-azure/internal/test/matchers/gomock"

azure "sigs.k8s.io/cluster-api-provider-azure/cloud"

. "github.com/onsi/gomega"
Expand Down Expand Up @@ -106,10 +107,6 @@ func TestReconcilePublicIP(t *testing.T) {
PublicIPAddressPropertiesFormat: &network.PublicIPAddressPropertiesFormat{
PublicIPAddressVersion: network.IPv4,
PublicIPAllocationMethod: network.Static,
DNSSettings: &network.PublicIPAddressDNSSettings{
DomainNameLabel: to.StringPtr("my-publicip-3"),
Fqdn: to.StringPtr(""),
},
},
})).Times(1),
m.CreateOrUpdate(context.TODO(), "my-rg", "my-publicip-ipv6", gomockinternal.DiffEq(network.PublicIPAddress{
Expand Down

0 comments on commit 9eb3140

Please sign in to comment.