Skip to content

Commit b3726dd

Browse files
committed
fix(ip): dynamic ip exponential backoff
1 parent 1e4b6bf commit b3726dd

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

internal/controller/ip_controller.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
"errors"
2525
"fmt"
2626
"io"
27-
"math/rand"
27+
"math/rand/v2"
2828
"net"
2929
"net/http"
3030
"net/url"
@@ -250,13 +250,14 @@ func (r *IPReconciler) handleDynamic(ctx context.Context, ip *cloudflareoperator
250250
if len(ip.Spec.IPSources) == 0 {
251251
return errors.New("IP sources are required for dynamic IPs")
252252
}
253-
if len(ip.Spec.IPSources) > 1 {
254-
rand.Shuffle(len(ip.Spec.IPSources), func(i, j int) {
255-
ip.Spec.IPSources[i], ip.Spec.IPSources[j] = ip.Spec.IPSources[j], ip.Spec.IPSources[i]
256-
})
257-
}
253+
// DeepCopy the ip sources to avoid modifying the original slice which would cause the object to be updated on every reconcile
254+
// which would lead to an infinite loop
255+
ipSources := ip.Spec.DeepCopy().IPSources
256+
rand.Shuffle(len(ipSources), func(i, j int) {
257+
ipSources[i], ipSources[j] = ipSources[j], ipSources[i]
258+
})
258259
var ipSourceError error
259-
for _, source := range ip.Spec.IPSources {
260+
for _, source := range ipSources {
260261
response, err := r.getIPSource(ctx, source)
261262
if err != nil {
262263
ipSourceError = err

0 commit comments

Comments
 (0)