Skip to content

Commit

Permalink
NETOBSERV-1568: reintroduce finalizer check to remove any remaining f…
Browse files Browse the repository at this point in the history
…inalizer

Since removing ipfix, we don't use finalizers anymore. However users
upgrading from a 1.5 will still have one set in their CR. So we need,
for a release, to continue checking for the finalizer, and remove it if
found.
  • Loading branch information
jotak committed Mar 21, 2024
1 parent 1cd8e76 commit 6a829c9
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions controllers/flowcollector_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
corev1 "k8s.io/api/core/v1"
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/log"

flowslatest "github.com/netobserv/network-observability-operator/apis/flowcollector/v1beta2"
Expand All @@ -24,6 +25,10 @@ import (
"github.com/netobserv/network-observability-operator/pkg/watchers"
)

const (
flowsFinalizer = "flows.netobserv.io/finalizer"
)

// FlowCollectorReconciler reconciles a FlowCollector object
type FlowCollectorReconciler struct {
client.Client
Expand Down Expand Up @@ -118,6 +123,10 @@ func (r *FlowCollectorReconciler) reconcile(ctx context.Context, clh *helper.Cli
loki := helper.NewLokiConfig(&desired.Spec.Loki, ns)
reconcilersInfo := r.newCommonInfo(clh, ns, previousNamespace, &loki)

if err := r.checkFinalizer(ctx, desired); err != nil {
return err
}

if err := cleanup.CleanPastReferences(ctx, r.Client, ns); err != nil {
return err
}
Expand Down Expand Up @@ -161,6 +170,18 @@ func (r *FlowCollectorReconciler) reconcile(ctx context.Context, clh *helper.Cli
return nil
}

// checkFinalizer returns true (and/or error) if the calling function needs to return
func (r *FlowCollectorReconciler) checkFinalizer(ctx context.Context, desired *flowslatest.FlowCollector) error {
// Previous version of the operator had a finalizer, this isn't the case anymore.
// Remove any finalizer that could remain after an upgrade.
if controllerutil.ContainsFinalizer(desired, flowsFinalizer) {
controllerutil.RemoveFinalizer(desired, flowsFinalizer)
return r.Update(ctx, desired)
}

return nil
}

func (r *FlowCollectorReconciler) newCommonInfo(clh *helper.Client, ns, prevNs string, loki *helper.LokiConfig) reconcilers.Common {
return reconcilers.Common{
Client: *clh,
Expand Down

0 comments on commit 6a829c9

Please sign in to comment.