From 4dddb8c6b3b00cc9c99f7bb1609e38a6d3b89e1c Mon Sep 17 00:00:00 2001 From: Alexandros Kosiaris Date: Wed, 1 Nov 2017 13:51:07 +0200 Subject: [PATCH] Only parse ClusterCIDR, ServiceCIDR if AllocateNodeCIDRs ClusterCIDR and ServiceCIDR are settings that are only used if at least AllocateNodeCIDRs is set. The route controller requires in addition to it for ConfigureCloudRoutes to be true as well. Since AllocateNodeCIDRs is by default false, if guard the parsing of these settings in order to not unnecessarily spam logs. Amend the documentation of kube-controller-manager for the 2 settings to point out the requirement of AllocateNodeCIDRs to be true as well --- cmd/kube-controller-manager/app/core.go | 34 ++++++++++--------- .../app/options/options.go | 4 +-- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/cmd/kube-controller-manager/app/core.go b/cmd/kube-controller-manager/app/core.go index 2ceb9fbc2b5..0d43b8de753 100644 --- a/cmd/kube-controller-manager/app/core.go +++ b/cmd/kube-controller-manager/app/core.go @@ -76,20 +76,22 @@ func startServiceController(ctx ControllerContext) (bool, error) { } func startNodeController(ctx ControllerContext) (bool, error) { - var clusterCIDR *net.IPNet - var err error - if len(strings.TrimSpace(ctx.Options.ClusterCIDR)) != 0 { - _, clusterCIDR, err = net.ParseCIDR(ctx.Options.ClusterCIDR) - if err != nil { - glog.Warningf("Unsuccessful parsing of cluster CIDR %v: %v", ctx.Options.ClusterCIDR, err) + var clusterCIDR *net.IPNet = nil + var serviceCIDR *net.IPNet = nil + if ctx.Options.AllocateNodeCIDRs { + var err error + if len(strings.TrimSpace(ctx.Options.ClusterCIDR)) != 0 { + _, clusterCIDR, err = net.ParseCIDR(ctx.Options.ClusterCIDR) + if err != nil { + glog.Warningf("Unsuccessful parsing of cluster CIDR %v: %v", ctx.Options.ClusterCIDR, err) + } } - } - var serviceCIDR *net.IPNet - if len(strings.TrimSpace(ctx.Options.ServiceCIDR)) != 0 { - _, serviceCIDR, err = net.ParseCIDR(ctx.Options.ServiceCIDR) - if err != nil { - glog.Warningf("Unsuccessful parsing of service CIDR %v: %v", ctx.Options.ServiceCIDR, err) + if len(strings.TrimSpace(ctx.Options.ServiceCIDR)) != 0 { + _, serviceCIDR, err = net.ParseCIDR(ctx.Options.ServiceCIDR) + if err != nil { + glog.Warningf("Unsuccessful parsing of service CIDR %v: %v", ctx.Options.ServiceCIDR, err) + } } } @@ -124,10 +126,6 @@ func startNodeController(ctx ControllerContext) (bool, error) { } func startRouteController(ctx ControllerContext) (bool, error) { - _, clusterCIDR, err := net.ParseCIDR(ctx.Options.ClusterCIDR) - if err != nil { - glog.Warningf("Unsuccessful parsing of cluster CIDR %v: %v", ctx.Options.ClusterCIDR, err) - } if !ctx.Options.AllocateNodeCIDRs || !ctx.Options.ConfigureCloudRoutes { glog.Infof("Will not configure cloud provider routes for allocate-node-cidrs: %v, configure-cloud-routes: %v.", ctx.Options.AllocateNodeCIDRs, ctx.Options.ConfigureCloudRoutes) return false, nil @@ -141,6 +139,10 @@ func startRouteController(ctx ControllerContext) (bool, error) { glog.Warning("configure-cloud-routes is set, but cloud provider does not support routes. Will not configure cloud provider routes.") return false, nil } + _, clusterCIDR, err := net.ParseCIDR(ctx.Options.ClusterCIDR) + if err != nil { + glog.Warningf("Unsuccessful parsing of cluster CIDR %v: %v", ctx.Options.ClusterCIDR, err) + } routeController := routecontroller.New(routes, ctx.ClientBuilder.ClientOrDie("route-controller"), ctx.InformerFactory.Core().V1().Nodes(), ctx.Options.ClusterName, clusterCIDR) go routeController.Run(ctx.Stop, ctx.Options.RouteReconciliationPeriod.Duration) return true, nil diff --git a/cmd/kube-controller-manager/app/options/options.go b/cmd/kube-controller-manager/app/options/options.go index a87afb20d8b..d5765e88b79 100644 --- a/cmd/kube-controller-manager/app/options/options.go +++ b/cmd/kube-controller-manager/app/options/options.go @@ -195,8 +195,8 @@ func (s *CMServer) AddFlags(fs *pflag.FlagSet, allControllers []string, disabled fs.BoolVar(&s.EnableProfiling, "profiling", true, "Enable profiling via web interface host:port/debug/pprof/") fs.BoolVar(&s.EnableContentionProfiling, "contention-profiling", false, "Enable lock contention profiling, if profiling is enabled") fs.StringVar(&s.ClusterName, "cluster-name", s.ClusterName, "The instance prefix for the cluster") - fs.StringVar(&s.ClusterCIDR, "cluster-cidr", s.ClusterCIDR, "CIDR Range for Pods in cluster.") - fs.StringVar(&s.ServiceCIDR, "service-cluster-ip-range", s.ServiceCIDR, "CIDR Range for Services in cluster.") + fs.StringVar(&s.ClusterCIDR, "cluster-cidr", s.ClusterCIDR, "CIDR Range for Pods in cluster. Requires --allocate-node-cidrs to be true") + fs.StringVar(&s.ServiceCIDR, "service-cluster-ip-range", s.ServiceCIDR, "CIDR Range for Services in cluster. Requires --allocate-node-cidrs to be true") fs.Int32Var(&s.NodeCIDRMaskSize, "node-cidr-mask-size", s.NodeCIDRMaskSize, "Mask size for node cidr in cluster.") fs.BoolVar(&s.AllocateNodeCIDRs, "allocate-node-cidrs", false, "Should CIDRs for Pods be allocated and set on the cloud provider.")