From 314e3f56dca815fb4d0fa6518091fc88ae2b6465 Mon Sep 17 00:00:00 2001 From: Manuel Buil Date: Fri, 22 Apr 2022 16:04:22 +0200 Subject: [PATCH] Check if user has a correct cluster-cidr and service-cidr config Signed-off-by: Manuel Buil --- pkg/agent/run.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pkg/agent/run.go b/pkg/agent/run.go index 8abfb24581..c63ea2298e 100644 --- a/pkg/agent/run.go +++ b/pkg/agent/run.go @@ -2,6 +2,7 @@ package agent import ( "context" + "fmt" "net" "os" "path/filepath" @@ -64,11 +65,19 @@ func run(ctx context.Context, cfg cmds.Agent, proxy proxy.Proxy) error { } serviceIPv4 := utilsnet.IsIPv4CIDR(nodeConfig.AgentConfig.ServiceCIDR) clusterIPv4 := utilsnet.IsIPv4CIDR(nodeConfig.AgentConfig.ClusterCIDR) + nodeIPv4 := utilsnet.IsIPv4String(nodeConfig.AgentConfig.NodeIP) serviceIPv6 := utilsnet.IsIPv6CIDR(nodeConfig.AgentConfig.ServiceCIDR) clusterIPv6 := utilsnet.IsIPv6CIDR(nodeConfig.AgentConfig.ClusterCIDR) + nodeIPv6 := utilsnet.IsIPv6String(nodeConfig.AgentConfig.NodeIP) + if (serviceIPv6 != clusterIPv6) || (dualCluster != dualService) || (serviceIPv4 != clusterIPv4) { + return fmt.Errorf("cluster-cidr: %v and service-cidr: %v, must share the same IP version (IPv4, IPv6 or dual-stack)", nodeConfig.AgentConfig.ClusterCIDRs, nodeConfig.AgentConfig.ServiceCIDRs) + } + if (clusterIPv6 != nodeIPv6) || (dualCluster != dualNode) || (clusterIPv4 != nodeIPv4) { + return fmt.Errorf("cluster-cidr: %v and node-ip: %v, must share the same IP version (IPv4, IPv6 or dual-stack)", nodeConfig.AgentConfig.ClusterCIDRs, nodeConfig.AgentConfig.NodeIPs) + } + enableIPv6 := dualCluster || clusterIPv6 + enableIPv4 := dualCluster || clusterIPv4 - enableIPv4 := dualCluster || dualService || dualNode || serviceIPv4 || clusterIPv4 - enableIPv6 := dualCluster || dualService || dualNode || serviceIPv6 || clusterIPv6 conntrackConfig, err := getConntrackConfig(nodeConfig) if err != nil { return errors.Wrap(err, "failed to validate kube-proxy conntrack configuration")