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

NETOBSERV-1568: reintroduce finalizer check to remove any remaining finalizer #593

Merged
merged 1 commit into from
Mar 22, 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
20 changes: 20 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,17 @@ func (r *FlowCollectorReconciler) reconcile(ctx context.Context, clh *helper.Cli
return nil
}

func (r *FlowCollectorReconciler) checkFinalizer(ctx context.Context, desired *flowslatest.FlowCollector) error {
// Previous version of the operator (1.5) 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
Loading