Skip to content

Commit

Permalink
Use only InternalIP for NextHop selection (#53)
Browse files Browse the repository at this point in the history
Signed-off-by: Andrey Klimentyev <[email protected]>
  • Loading branch information
zuzzas authored Mar 15, 2023
1 parent ba1c7c8 commit eac4199
Showing 1 changed file with 13 additions and 21 deletions.
34 changes: 13 additions & 21 deletions pkg/cloudprovider/yandex/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package yandex

import (
"context"
"fmt"
"sync"

"github.com/davecgh/go-spew/spew"
"github.com/pkg/errors"
"github.com/yandex-cloud/go-genproto/yandex/cloud/operation"
"github.com/yandex-cloud/go-genproto/yandex/cloud/vpc/v1"
Expand Down Expand Up @@ -77,11 +77,22 @@ func (yc *Cloud) CreateRoute(ctx context.Context, _ string, _ string, route *clo
}

kubeNodeName := string(route.TargetNode)
nextHop, err := yc.getInternalIpByNodeName(kubeNodeName)
addresses, err := yc.NodeAddresses(ctx, route.TargetNode)
if err != nil {
return err
}

var nextHop string
for _, address := range addresses {
if address.Type == v1.NodeInternalIP {
nextHop = address.Address
break
}
}
if len(nextHop) == 0 {
return spew.Errorf("could not determine InternalIP from list of IPs for VM %q: %v", route.TargetNode, addresses)
}

newStaticRoutes := filterStaticRoutes(rt.StaticRoutes, routeFilterTerm{
termType: routeFilterAddOrUpdate,
nodeName: kubeNodeName,
Expand Down Expand Up @@ -133,25 +144,6 @@ func (yc *Cloud) DeleteRoute(ctx context.Context, _ string, route *cloudprovider
return err
}

func (yc *Cloud) getInternalIpByNodeName(nodeName string) (string, error) {
kubeNode, err := yc.nodeLister.Get(nodeName)
if err != nil {
return "", err
}

var targetInternalIP string
for _, address := range kubeNode.Status.Addresses {
if address.Type == v1.NodeInternalIP {
targetInternalIP = address.Address
}
}
if len(targetInternalIP) == 0 {
return "", fmt.Errorf("no InternalIPs found for Node %q", nodeName)
}

return targetInternalIP, nil
}

type routeFilterTerm struct {
termType routeFilterTermType
nodeName string
Expand Down

0 comments on commit eac4199

Please sign in to comment.