Skip to content

Commit 9e9b0c8

Browse files
committed
small improvements
Signed-off-by: craig <[email protected]> rh-pre-commit.version: 2.2.0 rh-pre-commit.check-secrets: ENABLED
1 parent b6fc0f1 commit 9e9b0c8

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

Diff for: internal/controller/dnsrecord_controller.go

+32-6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"errors"
2222
"fmt"
2323
"net"
24+
"slices"
2425
"strings"
2526
"time"
2627

@@ -700,9 +701,12 @@ func (r *DNSRecordReconciler) applyLocalChanges(ctx context.Context, dnsRecord *
700701
// update flow
701702

702703
}
703-
mergeCopy.Spec.Endpoints = endpointSet
704-
if err := r.Client.Update(ctx, mergeCopy, &client.UpdateOptions{}); err != nil {
705-
return fmt.Errorf("failed to update core dns merged copy %w", err)
704+
if !endPointsEqual(mergeCopy.Spec.Endpoints, endpointSet) {
705+
logger.Info("updating merged copy with new endpoints" + mergeCopy.Name)
706+
mergeCopy.Spec.Endpoints = endpointSet
707+
if err := r.Client.Update(ctx, mergeCopy, &client.UpdateOptions{}); err != nil {
708+
return fmt.Errorf("failed to update core dns merged copy %w", err)
709+
}
706710
}
707711
return nil
708712
}
@@ -735,10 +739,15 @@ func (r *DNSRecordReconciler) applyLocalChanges(ctx context.Context, dnsRecord *
735739
}
736740
}
737741
//update endpoints only
738-
kdrntLocalCopy.Spec.Endpoints = computeLocalEndpointSet(original)
739-
if err := r.Client.Update(ctx, kdrntLocalCopy, &client.UpdateOptions{}); err != nil {
740-
return fmt.Errorf("failed to update kuadrant local copy %w", err)
742+
computedEndpoints := computeLocalEndpointSet(original)
743+
if !endPointsEqual(kdrntLocalCopy.Spec.Endpoints, computedEndpoints) {
744+
logger.Info("updating local endpoints for record " + kdrntLocalCopy.Name)
745+
kdrntLocalCopy.Spec.Endpoints = computedEndpoints
746+
if err := r.Client.Update(ctx, kdrntLocalCopy, &client.UpdateOptions{}); err != nil {
747+
return fmt.Errorf("failed to update kuadrant local copy %w", err)
748+
}
741749
}
750+
742751
return nil
743752
}
744753

@@ -773,6 +782,23 @@ func (r *DNSRecordReconciler) applyLocalChanges(ctx context.Context, dnsRecord *
773782
return hadChanges, []string{}, nil
774783
}
775784

785+
func endPointsEqual(eps1, eps2 []*externaldnsendpoint.Endpoint) bool {
786+
return slices.EqualFunc(eps1, eps2, func(e1, e2 *externaldnsendpoint.Endpoint) bool {
787+
if e1.DNSName != e2.DNSName {
788+
return false
789+
}
790+
791+
if !e1.Targets.Same(e2.Targets) {
792+
return false
793+
}
794+
if !slices.Equal(e1.ProviderSpecific, e2.ProviderSpecific) {
795+
return false
796+
}
797+
798+
return true
799+
})
800+
}
801+
776802
// applyExternalDNSChanges creates the Plan and applies it to the registry. This is used only for external cloud provider DNS. Returns true only if the Plan had no errors and there were changes to apply.
777803
// The error is nil only if the changes were successfully applied or there were no changes to be made.
778804
func (r *DNSRecordReconciler) applyExternalDNSChanges(ctx context.Context, dnsRecord *v1alpha1.DNSRecord, probes *v1alpha1.DNSHealthCheckProbeList, dnsProvider provider.Provider, isDelete bool) (bool, []string, error) {

0 commit comments

Comments
 (0)