-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Finalizers #78
base: main
Are you sure you want to change the base?
Fix Finalizers #78
Conversation
9b2fc00
to
a1f57ac
Compare
a1f57ac
to
edc8fbe
Compare
edc8fbe
to
b6cc9db
Compare
@@ -81,6 +82,14 @@ func (r *PrefixReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr | |||
if controllerutil.ContainsFinalizer(prefix, PrefixFinalizerName) { | |||
if !prefix.Spec.PreserveInNetbox { | |||
if err := r.NetboxClient.DeletePrefix(prefix.Status.PrefixId); err != nil { | |||
if errors.Is(err, utils.ErrNotFound) { | |||
setConditionErr := r.SetConditionAndCreateEvent(ctx, prefix, netboxv1.ConditionPrefixReadyFalse, corev1.EventTypeWarning, err.Error()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Propose to use a different condition (replace netboxv1.ConditionPrefixReadyFalse with a new condition like e.g. netboxv1.ConditionPrefixReadyFalseDeletionFailed)
Currently the condition looks as follows:
conditions:
- lastTransitionTime: "2024-10-01T07:14:46Z"
message: 'Failed to reserve IP in NetBox. failed to fetch IPAddress: not found'
reason: FailedToReserveIpInNetbox
status: "False"
type: Ready
Propose to use reason "FailedToDeleteIpInNetbox" and message "Failed to delete IP in NetBox".
Same applies to the other controller...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree
@@ -98,9 +100,17 @@ func (r *NetboxClient) UpdatePrefix(prefixId int64, prefix *netboxModels.Writabl | |||
} | |||
|
|||
func (r *NetboxClient) DeletePrefix(prefixId int64) error { | |||
// assuming id starts from 1 when Prefix is created so 0 means that Prefix doesn't exist | |||
if prefixId == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what this check is about. Is it to catch the case where the prefix was never created in NetBox?
b6cc9db
to
51fd430
Compare
Changes:
Close #77