Skip to content

Commit 50a9b89

Browse files
committed
add debug logging
1 parent 8c66a58 commit 50a9b89

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

main.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,28 +81,25 @@ func (c *ibmCloudCisProviderSolver) Present(ch *v1alpha1.ChallengeRequest) error
8181
func findLongestMatchingZone(zones []cis.Zone, fqdn string) *cis.Zone {
8282
var longestMatchZone *cis.Zone
8383
var longestMatchLength int
84+
var longestMatchIndex = -1
8485

85-
for _, zone := range zones {
86+
for i, zone := range zones {
8687
log.Printf("Checking zone: %s (id: %s)", zone.Name, zone.Id)
8788
zoneNameWithDot := zone.Name + "."
88-
log.Printf("zone with dot: %s ", zoneNameWithDot)
89-
if strings.HasSuffix(fqdn, zoneNameWithDot) {
90-
log.Printf("Match found with zone: %s", zone.Name)
91-
if len(zoneNameWithDot) > longestMatchLength {
92-
log.Printf("Updating longest match to zone: %s with length: %d", zone.Name, len(zoneNameWithDot))
93-
longestMatchLength = len(zoneNameWithDot)
94-
longestMatchZone = &zone
95-
}
96-
} else {
97-
log.Printf("No match for zone: %s", zone.Name)
89+
if strings.HasSuffix(fqdn, zoneNameWithDot) && len(zoneNameWithDot) > longestMatchLength {
90+
log.Printf("Updating longest match to zone: %s with length: %d", zone.Name, len(zoneNameWithDot))
91+
longestMatchLength = len(zoneNameWithDot)
92+
longestMatchIndex = i
9893
}
9994
}
10095

101-
if longestMatchZone != nil {
96+
if longestMatchIndex != -1 {
97+
longestMatchZone = &zones[longestMatchIndex]
10298
log.Printf("Longest matching zone found: %s", longestMatchZone.Name)
10399
} else {
104100
log.Printf("No matching zone found")
105101
}
102+
106103
return longestMatchZone
107104
}
108105

0 commit comments

Comments
 (0)