Skip to content

Commit

Permalink
fix(network-manager): network manager reconciles the tunnelendpoints …
Browse files Browse the repository at this point in the history
…when changed

The tunnelendpointcreator controller part of the network manager now reconciles the networkconfigs each time the tunnelendpoint
associated with the given networkconfig is created/updated/deleted. No need to restart the network-manager to have the tunnelendpoint
recreated if deleted.
  • Loading branch information
alacuku committed Jan 4, 2022
1 parent ceb501a commit 4fbba16
Showing 1 changed file with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"os"
"os/signal"
"reflect"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/source"
"strings"

apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand All @@ -28,6 +30,7 @@ import (
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/client-go/util/retry"
"k8s.io/klog/v2"
"k8s.io/utils/pointer"
"k8s.io/utils/trace"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -168,6 +171,8 @@ func (tec *TunnelEndpointCreator) Reconcile(ctx context.Context, req ctrl.Reques
func (tec *TunnelEndpointCreator) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&netv1alpha1.NetworkConfig{}).
Watches(&source.Kind{Type: &netv1alpha1.TunnelEndpoint{}},
&handler.EnqueueRequestForOwner{OwnerType: &netv1alpha1.NetworkConfig{}, IsController: false}).
Complete(tec)
}

Expand Down Expand Up @@ -337,8 +342,9 @@ func (tec *TunnelEndpointCreator) enforceTunnelEndpoint(ctx context.Context, loc

if !found {
controllerRef := metav1.GetControllerOf(local)
controllerRef.Controller = pointer.BoolPtr(false)
defer tracer.Step("TunnelEndpoint creation")
return tec.createTunnelEndpoint(ctx, param, controllerRef, local.GetNamespace())
return tec.createTunnelEndpoint(ctx, param, controllerRef, local.GetNamespace(), local)
}

defer tracer.Step("TunnelEndpoint update")
Expand Down Expand Up @@ -378,7 +384,7 @@ func (tec *TunnelEndpointCreator) updateSpecTunnelEndpoint(ctx context.Context,
}

func (tec *TunnelEndpointCreator) createTunnelEndpoint(ctx context.Context, param *networkParam,
ownerRef *metav1.OwnerReference, namespace string) error {
ownerRef *metav1.OwnerReference, namespace string, localNet *netv1alpha1.NetworkConfig) error {
// here we create it
tep := &netv1alpha1.TunnelEndpoint{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -389,17 +395,22 @@ func (tec *TunnelEndpointCreator) createTunnelEndpoint(ctx context.Context, para
},
},
}
if ownerRef != nil {
tep.OwnerReferences = append(tep.OwnerReferences, *ownerRef)

if err := controllerutil.SetOwnerReference(localNet, tep, tec.Scheme); err != nil {
klog.Errorf("an error occurred while setting owner reference to resource %s: %v", tep.Name, err)
return err
}

tep.OwnerReferences = append(tep.OwnerReferences, *ownerRef)

tec.fillTunnelEndpointSpec(tep, param)
err := tec.Create(ctx, tep)
if err != nil {

if err := tec.Create(ctx, tep); err != nil {
klog.Errorf("an error occurred while creating resource %s of type %s: %s",
tep.Name, netv1alpha1.TunnelEndpointGroupResource, err)
return err
}

klog.Infof("resource %s of type %s created", tep.Name, netv1alpha1.TunnelEndpointGroupResource)

return nil
Expand Down

0 comments on commit 4fbba16

Please sign in to comment.