Skip to content

Commit

Permalink
fix: set the default ttl to 60s (#235)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiying-lin authored Dec 24, 2024
1 parent a3d3bd7 commit 153b55b
Show file tree
Hide file tree
Showing 9 changed files with 271 additions and 271 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.22.7

require (
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.16.0
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.8.0
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v4 v4.3.0
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/trafficmanager/armtrafficmanager v1.3.0
github.com/google/go-cmp v0.6.0
Expand All @@ -26,7 +27,6 @@ require go.goms.io/fleet v0.11.4

require (
github.com/Azure/azure-sdk-for-go v68.0.0+incompatible // indirect
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.8.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/authorization/armauthorization/v2 v2.2.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5 v5.7.0 // indirect
Expand Down
14 changes: 12 additions & 2 deletions pkg/controllers/hub/trafficmanagerprofile/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ const (
DNSRelativeNameFormat = "%s-%s"
// AzureResourceProfileNameFormat is the name format of the Azure Traffic Manager Profile created by the fleet controller.
AzureResourceProfileNameFormat = "fleet-%s"

// DefaultDNSTTL is in seconds. This informs the local DNS resolvers and DNS clients how long to cache DNS responses
// provided by this Traffic Manager profile.
// Defaults to 60 which is the same as the portal's default config.
DefaultDNSTTL = int64(60)
)

var (
Expand Down Expand Up @@ -170,8 +175,8 @@ func (r *Reconciler) handleUpdate(ctx context.Context, profile *fleetnetv1alpha1
// by ignoring others.
// The desired profile is built by the controllers and all the required fields should not be nil.
func EqualAzureTrafficManagerProfile(current, desired armtrafficmanager.Profile) bool {
// location and dnsConfig is not immutable
if current.Properties == nil || current.Properties.MonitorConfig == nil || current.Properties.ProfileStatus == nil || current.Properties.TrafficRoutingMethod == nil {
// location and dnsConfig (excluding TTL) is immutable
if current.Properties == nil || current.Properties.MonitorConfig == nil || current.Properties.ProfileStatus == nil || current.Properties.TrafficRoutingMethod == nil || current.Properties.DNSConfig == nil {
return false
}

Expand All @@ -194,6 +199,10 @@ func EqualAzureTrafficManagerProfile(current, desired armtrafficmanager.Profile)
return false
}

if current.Properties.DNSConfig.TTL == nil || *current.Properties.DNSConfig.TTL != *desired.Properties.DNSConfig.TTL {
return false
}

if current.Tags == nil {
return false
}
Expand Down Expand Up @@ -271,6 +280,7 @@ func generateAzureTrafficManagerProfile(profile *fleetnetv1alpha1.TrafficManager
Properties: &armtrafficmanager.ProfileProperties{
DNSConfig: &armtrafficmanager.DNSConfig{
RelativeName: ptr.To(fmt.Sprintf(DNSRelativeNameFormat, profile.Namespace, profile.Name)),
TTL: ptr.To(DefaultDNSTTL), // no default value on the server side, using 60s same as portal's default config
},
MonitorConfig: &armtrafficmanager.MonitorConfig{
IntervalInSeconds: mc.IntervalInSeconds,
Expand Down
Loading

0 comments on commit 153b55b

Please sign in to comment.