Skip to content

Commit

Permalink
fix: geneve cleanup on gw
Browse files Browse the repository at this point in the history
  • Loading branch information
cheina97 committed Feb 14, 2025
1 parent 5284147 commit fafefa6
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 6 deletions.
12 changes: 6 additions & 6 deletions pkg/fabric/finalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ const (
)

func (r *InternalFabricReconciler) ensureinternalfabricFinalizerPresence(
ctx context.Context, fwcfg *networkingv1beta1.InternalFabric) error {
ctrlutil.AddFinalizer(fwcfg, internalfabricControllerFinalizer)
return r.Client.Update(ctx, fwcfg)
ctx context.Context, internalfabric *networkingv1beta1.InternalFabric) error {
ctrlutil.AddFinalizer(internalfabric, internalfabricControllerFinalizer)
return r.Client.Update(ctx, internalfabric)
}

func (r *InternalFabricReconciler) ensureinternalfabricFinalizerAbsence(
ctx context.Context, fwcfg *networkingv1beta1.InternalFabric) error {
ctrlutil.RemoveFinalizer(fwcfg, internalfabricControllerFinalizer)
return r.Client.Update(ctx, fwcfg)
ctx context.Context, internalfabric *networkingv1beta1.InternalFabric) error {
ctrlutil.RemoveFinalizer(internalfabric, internalfabricControllerFinalizer)
return r.Client.Update(ctx, internalfabric)
}
40 changes: 40 additions & 0 deletions pkg/gateway/fabric/geneve/finalizer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2019-2025 The Liqo Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package geneve

import (
"context"

ctrlutil "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

networkingv1beta1 "github.com/liqotech/liqo/apis/networking/v1beta1"
)

const (
// internalnodeControllerFinalizer is the finalizer added to internalnode to allow the controller to clean up.
internalnodeControllerFinalizer = "internalnode-controller.liqo.io/finalizer"
)

func (r *InternalNodeReconciler) ensureinternalnodeFinalizerPresence(
ctx context.Context, internalnode *networkingv1beta1.InternalNode) error {
ctrlutil.AddFinalizer(internalnode, internalnodeControllerFinalizer)
return r.Client.Update(ctx, internalnode)
}

func (r *InternalNodeReconciler) ensureinternalnodeFinalizerAbsence(
ctx context.Context, internalnode *networkingv1beta1.InternalNode) error {
ctrlutil.RemoveFinalizer(internalnode, internalnodeControllerFinalizer)
return r.Client.Update(ctx, internalnode)
}
29 changes: 29 additions & 0 deletions pkg/gateway/fabric/geneve/internalnode_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"k8s.io/klog/v2"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

networkingv1beta1 "github.com/liqotech/liqo/apis/networking/v1beta1"
"github.com/liqotech/liqo/pkg/consts"
Expand Down Expand Up @@ -72,6 +73,34 @@ func (r *InternalNodeReconciler) Reconcile(ctx context.Context, req ctrl.Request

klog.V(4).Infof("Reconciling internalnode %s", req.String())

// Manage Finalizers and routeconfiguration deletion.
deleting := !internalnode.ObjectMeta.DeletionTimestamp.IsZero()
containsFinalizer := controllerutil.ContainsFinalizer(internalnode, internalnodeControllerFinalizer)
switch {
case !deleting && !containsFinalizer:
if err = r.ensureinternalnodeFinalizerPresence(ctx, internalnode); err != nil {
return ctrl.Result{}, err
}

return ctrl.Result{}, nil

case deleting && containsFinalizer:
if err := geneve.EnsureGeneveInterfaceAbsence(internalnode.Spec.Interface.Gateway.Name); err != nil {
return ctrl.Result{}, fmt.Errorf("unable to ensure the geneve interface absence: %w", err)
}

if err = r.ensureinternalnodeFinalizerAbsence(ctx, internalnode); err != nil {
return ctrl.Result{}, err
}

klog.V(2).Infof("InternalFabric %s deleted", req.String())

return ctrl.Result{}, nil

case deleting && !containsFinalizer:
return ctrl.Result{}, nil
}

// The internal fabric has the same name of the gateway resource.
internalFabricName := r.Options.GwOptions.Name
id, err := geneve.GetGeneveTunnelID(ctx, r.Client, internalFabricName, internalnode.Name)
Expand Down

0 comments on commit fafefa6

Please sign in to comment.