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 0b0b75a
Showing 1 changed file with 9 additions and 2 deletions.
Expand Up @@ -17,6 +17,7 @@ package tunnelendpointcreator
import (
"context"
"fmt"
"k8s.io/utils/pointer"
"os"
"os/signal"
"reflect"
Expand Down Expand Up @@ -168,6 +169,7 @@ 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{}).
Owns(&netv1alpha1.TunnelEndpoint{}).
Complete(tec)
}

Expand Down Expand Up @@ -337,8 +339,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 +381,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,6 +392,10 @@ func (tec *TunnelEndpointCreator) createTunnelEndpoint(ctx context.Context, para
},
},
}
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
}
if ownerRef != nil {
tep.OwnerReferences = append(tep.OwnerReferences, *ownerRef)
}
Expand Down

0 comments on commit 0b0b75a

Please sign in to comment.