Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some ipv6 fixes #1249

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions pkg/controllers/netpol/network_policy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ var (
// NetworkPolicyController struct to hold information required by NetworkPolicyController
type NetworkPolicyController struct {
nodeIP net.IP
isIpv6 bool
nodeHostName string
serviceClusterIPRange net.IPNet
serviceExternalIPRanges []net.IPNet
Expand Down Expand Up @@ -296,7 +297,7 @@ func (npc *NetworkPolicyController) ensureTopLevelChains() {
const whitelistUDPNodePortsPosition = 3
const externalIPPositionAdditive = 4

iptablesCmdHandler, err := iptables.New()
iptablesCmdHandler, err := npc.newIptablesCmdHandler()
if err != nil {
klog.Fatalf("Failed to initialize iptables executor due to %s", err.Error())
}
Expand Down Expand Up @@ -430,7 +431,7 @@ func (npc *NetworkPolicyController) ensureExplicitAccept() {
// Creates custom chains KUBE-NWPLCY-DEFAULT
func (npc *NetworkPolicyController) ensureDefaultNetworkPolicyChain() {

iptablesCmdHandler, err := iptables.New()
iptablesCmdHandler, err := npc.newIptablesCmdHandler()
if err != nil {
klog.Fatalf("Failed to initialize iptables executor due to %s", err.Error())
}
Expand All @@ -457,14 +458,21 @@ func (npc *NetworkPolicyController) ensureDefaultNetworkPolicyChain() {
}
}

func (npc *NetworkPolicyController) newIptablesCmdHandler() (*iptables.IPTables, error) {
if npc.isIpv6 {
return iptables.NewWithProtocol(iptables.ProtocolIPv6)
}
return iptables.NewWithProtocol(iptables.ProtocolIPv4)
}

func (npc *NetworkPolicyController) cleanupStaleRules(activePolicyChains, activePodFwChains map[string]bool,
deleteDefaultChains bool) error {

cleanupPodFwChains := make([]string, 0)
cleanupPolicyChains := make([]string, 0)

// initialize tool sets for working with iptables and ipset
iptablesCmdHandler, err := iptables.New()
iptablesCmdHandler, err := npc.newIptablesCmdHandler()
if err != nil {
return fmt.Errorf("failed to initialize iptables command executor due to %s", err.Error())
}
Expand Down Expand Up @@ -558,7 +566,7 @@ func (npc *NetworkPolicyController) cleanupStaleIPSets(activePolicyIPSets map[st
}()
}

ipsets, err := utils.NewIPSet(false)
ipsets, err := utils.NewIPSet(npc.isIpv6)
if err != nil {
return fmt.Errorf("failed to create ipsets command executor due to %s", err.Error())
}
Expand Down Expand Up @@ -673,6 +681,7 @@ func NewNetworkPolicyController(clientset kubernetes.Interface,
return nil, err
}
npc.nodeIP = nodeIP
npc.isIpv6 = nodeIP.To4() == nil

npc.podLister = podInformer.GetIndexer()
npc.PodEventHandler = npc.newPodEventHandler()
Expand Down
9 changes: 7 additions & 2 deletions pkg/controllers/routing/network_routes_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -985,8 +985,13 @@ func (nrc *NetworkRoutingController) startBgpServer(grpcServer bool) error {
}

if grpcServer {
nrc.bgpServer = gobgp.NewBgpServer(
gobgp.GrpcListenAddress(nrc.nodeIP.String() + ":50051" + "," + "127.0.0.1:50051"))
var addr string
if nrc.isIpv6 {
addr = "[" + nrc.nodeIP.String() + "]:50051" + "," + "[::1]:50051"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Random question by the way. Why does this need to listen on nodeIP on the first place; and not just on loopback? nodeIP is definitely publicly routable in ipv6 and i'm curious why we're having to spawn a publicly accessible grpc server. Do the different kube-router daemonsets connect to eachother over grpc or something?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good question. TBH I'm not 100% sure since I'm pretty sure this code was around before my time on the project. Off the top of my head, I'm not sure if gobgp exposes metrics on that port, but if it did that might be a reason for it to be bound. kube-router uses BGP and the kube-apiserver for communication between instances, it does not use gobgp's grpc port remotely.

I'll try to dig around and see if I can find a better explanation.

} else {
addr = nrc.nodeIP.String() + ":50051" + "," + "127.0.0.1:50051"
}
nrc.bgpServer = gobgp.NewBgpServer(gobgp.GrpcListenAddress(addr))
} else {
nrc.bgpServer = gobgp.NewBgpServer()
}
Expand Down