Skip to content

Commit

Permalink
liqo-route: mac annotation fix
Browse files Browse the repository at this point in the history
  • Loading branch information
cheina97 committed Sep 13, 2023
1 parent 004a0cf commit 6d0e3ef
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
7 changes: 6 additions & 1 deletion cmd/liqonet/route-operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ func runRouteOperator(commonFlags *liqonetCommonFlags, routeFlags *routeOperator
klog.Errorf("unable to get podIP: %v", err)
os.Exit(1)
}
podName, err := liqonetutils.GetPodName()
if err != nil {
klog.Errorf("unable to get pod name: %v", err)
os.Exit(1)
}
nodeName, err := liqonetutils.GetNodeName()
if err != nil {
klog.Errorf("unable to get node name: %v", err)
Expand Down Expand Up @@ -170,7 +175,7 @@ func runRouteOperator(commonFlags *liqonetCommonFlags, routeFlags *routeOperator
klog.Errorf("unable to start go routine that configures firewall rules for the route controller: %v", err)
os.Exit(1)
}
overlayController, err := routeoperator.NewOverlayController(podIP.String(), vxlanDevice, mutex, nodeMap, overlayMgr.GetClient())
overlayController, err := routeoperator.NewOverlayController(podName, vxlanDevice, mutex, nodeMap, overlayMgr.GetClient())
if err != nil {
klog.Errorf("an error occurred while creating overlay controller: %v", err)
os.Exit(3)
Expand Down
10 changes: 5 additions & 5 deletions internal/liqonet/route-operator/overlayOperator.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var (
type OverlayController struct {
client.Client
vxlanDev *overlay.VxlanDevice
podIP string
podName string
nodesLock *sync.RWMutex
vxlanPeers map[string]*overlay.Neighbor
// For each nodeName contains its IP addr.
Expand Down Expand Up @@ -76,7 +76,7 @@ func (ovc *OverlayController) Reconcile(ctx context.Context, req ctrl.Request) (
return ctrl.Result{}, nil
}
// If it is our pod than add the mac address annotation.
if ovc.podIP == pod.Status.PodIP {
if ovc.podName == pod.Name {
if liqonetutils.AddAnnotationToObj(&pod, vxlanMACAddressKey, ovc.vxlanDev.Link.HardwareAddr.String()) {
if err := ovc.Update(ctx, &pod); err != nil {
klog.Errorf("an error occurred while adding mac address annotation to pod {%s}: %v", req.String(), err)
Expand All @@ -102,7 +102,7 @@ func (ovc *OverlayController) Reconcile(ctx context.Context, req ctrl.Request) (
}

// NewOverlayController returns a new controller ready to be setup and started with the controller manager.
func NewOverlayController(podIP string, vxlanDevice *overlay.VxlanDevice, nodesLock *sync.RWMutex,
func NewOverlayController(podName string, vxlanDevice *overlay.VxlanDevice, nodesLock *sync.RWMutex,
vxlanNodes map[string]string, cl client.Client) (*OverlayController, error) {
if vxlanDevice == nil {
return nil, &liqoerrors.WrongParameter{
Expand All @@ -113,7 +113,7 @@ func NewOverlayController(podIP string, vxlanDevice *overlay.VxlanDevice, nodesL
return &OverlayController{
Client: cl,
vxlanDev: vxlanDevice,
podIP: podIP,
podName: podName,
nodesLock: nodesLock,
vxlanPeers: map[string]*overlay.Neighbor{},
vxlanNodes: vxlanNodes,
Expand Down Expand Up @@ -217,7 +217,7 @@ func (ovc *OverlayController) podFilter(obj client.Object) bool {
return false
}
// If it is our pod then process it.
if ovc.podIP == p.Status.PodIP {
if ovc.podName == p.Name {
return true
}
// If it is not our pod then check if the vxlan mac address has been set.
Expand Down
2 changes: 1 addition & 1 deletion internal/liqonet/route-operator/overlayOperator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ var _ = Describe("OverlayOperator", func() {
}
// Create dummy overlay operator.
ovc = &OverlayController{
podIP: overlayPodIP,
podName: overlayPodName,
vxlanPeers: make(map[string]*overlay.Neighbor),
vxlanDev: vxlanDevice,
Client: k8sClient,
Expand Down
9 changes: 9 additions & 0 deletions pkg/liqonet/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ func MapIPToNetwork(newNetwork, oldIP string) (newIP string, err error) {
return
}

// GetPodName returns the pod name.
func GetPodName() (string, error) {
podName, isSet := os.LookupEnv("POD_NAME")
if !isSet || podName == "" {
return "", errors.New("pod name is not yet set")
}
return podName, nil
}

// GetPodIP returns the pod IP address.
func GetPodIP() (net.IP, error) {
ipAddress, isSet := os.LookupEnv("POD_IP")
Expand Down

0 comments on commit 6d0e3ef

Please sign in to comment.