@@ -127,6 +127,48 @@ func (r *IPReconciler) reconcileIP(ctx context.Context, ip *cloudflareoperatorio
127
127
return ctrl.Result {}
128
128
}
129
129
130
+ // handleStatic handles the static ip
131
+ func (r * IPReconciler ) handleStatic (ip * cloudflareoperatoriov1.IP ) error {
132
+ if ip .Spec .Address == "" {
133
+ return errors .New ("Address is required for static IPs" )
134
+ }
135
+ if net .ParseIP (ip .Spec .Address ) == nil {
136
+ return errors .New ("Address is not a valid IP address" )
137
+ }
138
+ return nil
139
+ }
140
+
141
+ // handleDynamic handles the dynamic ip
142
+ func (r * IPReconciler ) handleDynamic (ctx context.Context , ip * cloudflareoperatoriov1.IP ) error {
143
+ if ip .Spec .Interval == nil {
144
+ ip .Spec .Interval = & metav1.Duration {Duration : time .Minute * 5 }
145
+ }
146
+ if len (ip .Spec .IPSources ) == 0 {
147
+ return errors .New ("IP sources are required for dynamic IPs" )
148
+ }
149
+ // DeepCopy the ip sources to avoid modifying the original slice which would cause the object to be updated on every reconcile
150
+ // which would lead to an infinite loop
151
+ ipSources := ip .Spec .DeepCopy ().IPSources
152
+ rand .Shuffle (len (ipSources ), func (i , j int ) {
153
+ ipSources [i ], ipSources [j ] = ipSources [j ], ipSources [i ]
154
+ })
155
+ var ipSourceError error
156
+ for _ , source := range ipSources {
157
+ response , err := r .getIPSource (ctx , source )
158
+ if err != nil {
159
+ ipSourceError = err
160
+ continue
161
+ }
162
+ ip .Spec .Address = response
163
+ ipSourceError = nil
164
+ break
165
+ }
166
+ if ipSourceError != nil {
167
+ return ipSourceError
168
+ }
169
+ return nil
170
+ }
171
+
130
172
// getIPSource returns the IP gathered from the IPSource
131
173
func (r * IPReconciler ) getIPSource (ctx context.Context , source cloudflareoperatoriov1.IPSpecIPSources ) (string , error ) {
132
174
log := ctrl .LoggerFrom (ctx )
@@ -231,48 +273,6 @@ func (r *IPReconciler) getIPSource(ctx context.Context, source cloudflareoperato
231
273
return extractedIP , nil
232
274
}
233
275
234
- // handleStatic handles the static ip
235
- func (r * IPReconciler ) handleStatic (ip * cloudflareoperatoriov1.IP ) error {
236
- if ip .Spec .Address == "" {
237
- return errors .New ("Address is required for static IPs" )
238
- }
239
- if net .ParseIP (ip .Spec .Address ) == nil {
240
- return errors .New ("Address is not a valid IP address" )
241
- }
242
- return nil
243
- }
244
-
245
- // handleDynamic handles the dynamic ip
246
- func (r * IPReconciler ) handleDynamic (ctx context.Context , ip * cloudflareoperatoriov1.IP ) error {
247
- if ip .Spec .Interval == nil {
248
- ip .Spec .Interval = & metav1.Duration {Duration : time .Minute * 5 }
249
- }
250
- if len (ip .Spec .IPSources ) == 0 {
251
- return errors .New ("IP sources are required for dynamic IPs" )
252
- }
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
- })
259
- var ipSourceError error
260
- for _ , source := range ipSources {
261
- response , err := r .getIPSource (ctx , source )
262
- if err != nil {
263
- ipSourceError = err
264
- continue
265
- }
266
- ip .Spec .Address = response
267
- ipSourceError = nil
268
- break
269
- }
270
- if ipSourceError != nil {
271
- return ipSourceError
272
- }
273
- return nil
274
- }
275
-
276
276
// reconcileDelete reconciles the deletion of the ip
277
277
func (r * IPReconciler ) reconcileDelete (ip * cloudflareoperatoriov1.IP ) {
278
278
metrics .IpFailureCounter .DeleteLabelValues (ip .Name , ip .Spec .Type )
0 commit comments