Skip to content
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

controller: misc. cleanup for LinodeVPCReconciler #125

Merged
merged 4 commits into from
Feb 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions controller/linodevpc_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

"github.com/go-logr/logr"
Expand Down Expand Up @@ -121,7 +123,9 @@ func (r *LinodeVPCReconciler) reconcile(
r.Recorder.Event(vpcScope.LinodeVPC, corev1.EventTypeWarning, string(failureReason), err.Error())
}

// Always close the scope when exiting this function so we can persist any LinodeMachine changes.
// Always close the scope when exiting this function so we can persist
// any LinodeVPC changes. This ignores any resource not found errors
// when reconciling deletions.
if patchErr := vpcScope.Close(ctx); patchErr != nil && utilerrors.FilterOut(patchErr, apierrors.IsNotFound) != nil {
logger.Error(patchErr, "failed to patch LinodeVPC")

Expand Down Expand Up @@ -179,6 +183,10 @@ func (r *LinodeVPCReconciler) reconcileCreate(ctx context.Context, vpcScope *sco
}
vpcScope.LinodeVPC.Status.Ready = true

if vpcScope.LinodeVPC.Spec.VPCID != nil {
r.Recorder.Event(vpcScope.LinodeVPC, corev1.EventTypeNormal, "Created", fmt.Sprintf("Created VPC %d", *vpcScope.LinodeVPC.Spec.VPCID))
}

return nil
}

Expand Down Expand Up @@ -260,8 +268,16 @@ func (r *LinodeVPCReconciler) reconcileDelete(ctx context.Context, logger logr.L
func (r *LinodeVPCReconciler) SetupWithManager(mgr ctrl.Manager) error {
_, err := ctrl.NewControllerManagedBy(mgr).
For(&infrav1alpha1.LinodeVPC{}).
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(mgr.GetLogger(), r.WatchFilterValue)).
Build(r)
WithEventFilter(
predicate.And(
// Filter for objects with a specific WatchLabel.
predicates.ResourceNotPausedAndHasFilterLabel(mgr.GetLogger(), r.WatchFilterValue),
// Do not reconcile the Delete events generated by the
// controller itself.
predicate.Funcs{
DeleteFunc: func(e event.DeleteEvent) bool { return false },
},
)).Build(r)
if err != nil {
return fmt.Errorf("failed to build controller: %w", err)
}
Expand Down