renable nodeipam in kube-controller-manager

pull/8/head
andrewsykim 2018-04-23 22:01:01 -04:00
parent 4692a6bf2e
commit 0a164760dc
4 changed files with 58 additions and 66 deletions

View File

@ -330,9 +330,9 @@ func NewControllerInitializers(loopMode ControllerLoopMode) map[string]InitFunc
controllers["ttl"] = startTTLController
controllers["bootstrapsigner"] = startBootstrapSignerController
controllers["tokencleaner"] = startTokenCleanerController
controllers["nodeipam"] = startNodeIpamController
if loopMode == IncludeCloudLoops {
controllers["service"] = startServiceController
controllers["nodeipam"] = startNodeIpamController
controllers["route"] = startRouteController
// TODO: volume controller into the IncludeCloudLoops only set.
// TODO: Separate cluster in cloud check from node lifecycle controller.

View File

@ -82,7 +82,11 @@ func startServiceController(ctx ControllerContext) (bool, error) {
func startNodeIpamController(ctx ControllerContext) (bool, error) {
var clusterCIDR *net.IPNet = nil
var serviceCIDR *net.IPNet = nil
if ctx.ComponentConfig.KubeCloudShared.AllocateNodeCIDRs {
if !ctx.ComponentConfig.KubeCloudShared.AllocateNodeCIDRs {
return false, nil
}
var err error
if len(strings.TrimSpace(ctx.ComponentConfig.KubeCloudShared.ClusterCIDR)) != 0 {
_, clusterCIDR, err = net.ParseCIDR(ctx.ComponentConfig.KubeCloudShared.ClusterCIDR)
@ -97,7 +101,6 @@ func startNodeIpamController(ctx ControllerContext) (bool, error) {
glog.Warningf("Unsuccessful parsing of service CIDR %v: %v", ctx.ComponentConfig.NodeIpamController.ServiceCIDR, err)
}
}
}
nodeIpamController, err := nodeipamcontroller.NewNodeIpamController(
ctx.InformerFactory.Core().V1().Nodes(),
@ -106,7 +109,6 @@ func startNodeIpamController(ctx ControllerContext) (bool, error) {
clusterCIDR,
serviceCIDR,
int(ctx.ComponentConfig.NodeIpamController.NodeCIDRMaskSize),
ctx.ComponentConfig.KubeCloudShared.AllocateNodeCIDRs,
ipam.CIDRAllocatorType(ctx.ComponentConfig.KubeCloudShared.CIDRAllocatorType),
)
if err != nil {

View File

@ -58,7 +58,6 @@ const (
// Controller is the controller that manages node ipam state.
type Controller struct {
allocateNodeCIDRs bool
allocatorType ipam.CIDRAllocatorType
cloud cloudprovider.Interface
@ -88,7 +87,6 @@ func NewNodeIpamController(
clusterCIDR *net.IPNet,
serviceCIDR *net.IPNet,
nodeCIDRMaskSize int,
allocateNodeCIDRs bool,
allocatorType ipam.CIDRAllocatorType) (*Controller, error) {
if kubeClient == nil {
@ -108,14 +106,12 @@ func NewNodeIpamController(
metrics.RegisterMetricAndTrackRateLimiterUsage("node_ipam_controller", kubeClient.CoreV1().RESTClient().GetRateLimiter())
}
if allocateNodeCIDRs {
if clusterCIDR == nil {
glog.Fatal("Controller: Must specify clusterCIDR if allocateNodeCIDRs == true.")
glog.Fatal("Controller: Must specify --cluster-cidr if --allocate-node-cidrs is set")
}
mask := clusterCIDR.Mask
if maskSize, _ := mask.Size(); maskSize > nodeCIDRMaskSize {
glog.Fatal("Controller: Invalid clusterCIDR, mask size of clusterCIDR must be less than nodeCIDRMaskSize.")
}
glog.Fatal("Controller: Invalid --cluster-cidr, mask size of cluster CIDR must be less than --node-cidr-mask-size")
}
ic := &Controller{
@ -124,12 +120,10 @@ func NewNodeIpamController(
lookupIP: net.LookupIP,
clusterCIDR: clusterCIDR,
serviceCIDR: serviceCIDR,
allocateNodeCIDRs: allocateNodeCIDRs,
allocatorType: allocatorType,
}
// TODO: Abstract this check into a generic controller manager should run method.
if ic.allocateNodeCIDRs {
if ic.allocatorType == ipam.IPAMFromClusterAllocatorType || ic.allocatorType == ipam.IPAMFromCloudAllocatorType {
cfg := &ipam.Config{
Resync: ipamResyncInterval,
@ -157,7 +151,6 @@ func NewNodeIpamController(
return nil, err
}
}
}
ic.nodeLister = nodeInformer.Lister()
ic.nodeInformerSynced = nodeInformer.Informer().HasSynced
@ -176,12 +169,9 @@ func (nc *Controller) Run(stopCh <-chan struct{}) {
return
}
// TODO: Abstract this check into a generic controller manager should run method.
if nc.allocateNodeCIDRs {
if nc.allocatorType != ipam.IPAMFromClusterAllocatorType && nc.allocatorType != ipam.IPAMFromCloudAllocatorType {
go nc.cidrAllocator.Run(stopCh)
}
}
<-stopCh
}

View File

@ -53,7 +53,7 @@ func setupAllocator(apiURL string, config *Config, clusterCIDR, serviceCIDR *net
sharedInformer := informers.NewSharedInformerFactory(clientSet, 1*time.Hour)
ipamController, err := nodeipam.NewNodeIpamController(
sharedInformer.Core().V1().Nodes(), config.Cloud, clientSet,
clusterCIDR, serviceCIDR, subnetMaskSize, true, config.AllocatorType,
clusterCIDR, serviceCIDR, subnetMaskSize, config.AllocatorType,
)
if err != nil {
return nil, shutdownFunc, err