@@ -184,25 +184,37 @@ func (r *PrefixReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
184
184
185
185
netboxPrefixModel , err := r .NetboxClient .ReserveOrUpdatePrefix (prefixModel )
186
186
if err != nil {
187
- if errors .Is (err , api .ErrRestorationHashMissmatch ) && prefix .Status .PrefixId == 0 {
188
- // if there is a restoration has missmatch and the PrefixId status field is not set,
189
- // delete the prefix so it can be recreated by the prefix claim controller
190
- logger .Info ("restoration hash missmatch, deleting prefix custom resource" , "prefix" , prefix .Spec .Prefix )
191
- err = r .Client .Delete (ctx , prefix )
192
- if err != nil {
193
- updateStatusErr := r .SetConditionAndCreateEvent (ctx , prefix , netboxv1 .ConditionIpaddressReadyFalse ,
194
- corev1 .EventTypeWarning , err .Error ())
195
- return ctrl.Result {}, fmt .Errorf ("failed to update prefix status: %w, " +
196
- "after deletion of prefix cr failed: %w" , updateStatusErr , err )
187
+ if errors .Is (err , api .ErrRestorationHashMismatch ) {
188
+ if prefix .Status .PrefixId == 0 {
189
+ // if there is a restoration hash mismatch and the PrefixId status field is not set,
190
+ // delete the prefix so it can be recreated by the prefix claim controller
191
+ // this will only affect resources that are created by a claim controller (and have a restoration hash custom field
192
+ logger .Info ("restoration hash mismatch, deleting prefix custom resource" , "prefix" , prefix .Spec .Prefix )
193
+ err = r .Client .Delete (ctx , prefix )
194
+ if err != nil {
195
+ if updateStatusErr := r .SetConditionAndCreateEvent (ctx , prefix , netboxv1 .ConditionPrefixReadyFalse ,
196
+ corev1 .EventTypeWarning , err .Error ()); updateStatusErr != nil {
197
+ return ctrl.Result {}, fmt .Errorf ("failed to update prefix status: %w, " +
198
+ "after deletion of prefix cr failed: %w" , updateStatusErr , err )
199
+ }
200
+ return ctrl.Result {Requeue : true }, nil
201
+ }
202
+ return ctrl.Result {}, nil
203
+ } else {
204
+ if updateStatusErr := r .SetConditionAndCreateEvent (ctx , prefix , netboxv1 .ConditionPrefixReadyFalse ,
205
+ corev1 .EventTypeWarning , err .Error ()); updateStatusErr != nil {
206
+ return ctrl.Result {}, fmt .Errorf ("failed to update prefix status: %w, " +
207
+ "after deletion of prefix cr failed: %w" , updateStatusErr , err )
208
+ }
209
+ return ctrl.Result {Requeue : true }, nil
197
210
}
198
- return ctrl.Result {}, nil
199
211
}
200
- if updateStatusErr := r .SetConditionAndCreateEvent (ctx , prefix , netboxv1 .ConditionIpaddressReadyFalse ,
201
- corev1 .EventTypeWarning , prefix . Spec . Prefix ); updateStatusErr != nil {
212
+ if updateStatusErr := r .SetConditionAndCreateEvent (ctx , prefix , netboxv1 .ConditionPrefixReadyFalse ,
213
+ corev1 .EventTypeWarning , err . Error () ); updateStatusErr != nil {
202
214
return ctrl.Result {}, fmt .Errorf ("failed to update prefix status: %w, " +
203
215
"after reservation of prefix netbox failed: %w" , updateStatusErr , err )
204
216
}
205
- return ctrl.Result {}, nil
217
+ return ctrl.Result {Requeue : true }, nil
206
218
}
207
219
208
220
/* 3. unlock lease of parent prefix */
0 commit comments