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

netpol: Add dual-stack support #1280

Closed
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
2 changes: 2 additions & 0 deletions docs/user-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ Usage of kube-router:
--disable-source-dest-check Disable the source-dest-check attribute for AWS EC2 instances. When this option is false, it must be set some other way. (default true)
--enable-cni Enable CNI plugin. Disable if you want to use kube-router features alongside another CNI plugin. (default true)
--enable-ibgp Enables peering with nodes with the same ASN, if disabled will only peer with external BGP peers (default true)
--enable-ipv4 Enables IPv4 support (default true)
--enable-ipv6 Enables IPv6 support (default true)
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we enable this by default?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can disable it by default, if you want.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm just wondering on implications to existing systems that don't use ipv6 currently. Maybe introduce as disabled and enable later?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright, changed to false

Copy link
Collaborator

Choose a reason for hiding this comment

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

@vadorovsky it looks like this is still set to enabled by default. Given that it's going to fail to initialize the NPC if IPv6 is enabled and there is not an IPv6 address on the node in the Kubernetes API, I think that enabling IPv6 is too risky as a default.

--enable-overlay When enable-overlay is set to true, IP-in-IP tunneling is used for pod-to-pod networking across nodes in different subnets. When set to false no tunneling is used and routing infrastructure is expected to route traffic for pod-to-pod networking across nodes in different subnets (default true)
--enable-pod-egress SNAT traffic from Pods to destinations outside the cluster. (default true)
--enable-pprof Enables pprof for debugging performance and memory leak issues.
Expand Down
37 changes: 36 additions & 1 deletion pkg/cmd/kube-router.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"errors"
"fmt"
"os"
"os/signal"
"sync"
Expand All @@ -14,9 +15,12 @@ import (
"github.com/cloudnativelabs/kube-router/pkg/healthcheck"
"github.com/cloudnativelabs/kube-router/pkg/metrics"
"github.com/cloudnativelabs/kube-router/pkg/options"
"github.com/cloudnativelabs/kube-router/pkg/utils"
"github.com/cloudnativelabs/kube-router/pkg/version"
"github.com/coreos/go-iptables/iptables"
"k8s.io/klog/v2"

v1core "k8s.io/api/core/v1"
"k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
Expand Down Expand Up @@ -184,8 +188,39 @@ func (kr *KubeRouter) Run() error {
}

if kr.Config.RunFirewall {
iptablesCmdHandlers := make(map[v1core.IPFamily]utils.IPTablesHandler, 2)
Copy link
Collaborator

Choose a reason for hiding this comment

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

It doesn't seem like there a particular need to move iptables and ipset logic up here into the command handler. If not, it would be better to sink this down into the NPC, into the NewNetworkPolicyController() initializer.

ipSetHandlers := make(map[v1core.IPFamily]utils.IPSetHandler, 2)

if kr.Config.EnableIPv4 {
iptHandler, err := iptables.NewWithProtocol(iptables.ProtocolIPv4)
if err != nil {
return fmt.Errorf("failed to create iptables handler: %w", err)
}
iptablesCmdHandlers[v1core.IPv4Protocol] = iptHandler

ipset, err := utils.NewIPSet(false)
if err != nil {
return fmt.Errorf("failed to create ipset handler: %w", err)
}
ipSetHandlers[v1core.IPv4Protocol] = ipset
}
if kr.Config.EnableIPv6 {
iptHandler, err := iptables.NewWithProtocol(iptables.ProtocolIPv6)
if err != nil {
return fmt.Errorf("failed to create iptables handler: %w", err)
}
iptablesCmdHandlers[v1core.IPv6Protocol] = iptHandler

ipset, err := utils.NewIPSet(true)
if err != nil {
return fmt.Errorf("failed to create ipset handler: %w", err)
}
ipSetHandlers[v1core.IPv6Protocol] = ipset
}

npc, err := netpol.NewNetworkPolicyController(kr.Client,
kr.Config, podInformer, npInformer, nsInformer, &ipsetMutex)
kr.Config, podInformer, npInformer, nsInformer, &ipsetMutex,
iptablesCmdHandlers, ipSetHandlers)
if err != nil {
return errors.New("Failed to create network policy controller: " + err.Error())
}
Expand Down
Loading