-
Notifications
You must be signed in to change notification settings - Fork 473
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package cmd | |
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"os" | ||
"os/signal" | ||
"sync" | ||
|
@@ -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" | ||
|
@@ -184,8 +188,39 @@ func (kr *KubeRouter) Run() error { | |
} | ||
|
||
if kr.Config.RunFirewall { | ||
iptablesCmdHandlers := make(map[v1core.IPFamily]utils.IPTablesHandler, 2) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
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()) | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, changed to false
There was a problem hiding this comment.
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.