Skip to content

Commit eecd829

Browse files
committed
ipam: CloudAllocator does not require service or cluster cidr
The inner logic of the controller already omits these fields, do the same in the command line flags validation, otherwise it forces the user to set some parameters that will be not used if the ipam controller is the CloudAllocator Change-Id: Ib539ca4bdce3e4f45b6b96edc7b581674db77528
1 parent f25aa9e commit eecd829

File tree

1 file changed

+45
-38
lines changed

1 file changed

+45
-38
lines changed

cmd/cloud-controller-manager/nodeipamcontroller.go

Lines changed: 45 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -70,59 +70,66 @@ func (nodeIpamController *nodeIPAMController) startNodeIpamControllerWrapper(ini
7070
func startNodeIpamController(ccmConfig *cloudcontrollerconfig.CompletedConfig, nodeIPAMConfig nodeipamconfig.NodeIPAMControllerConfiguration, ctx genericcontrollermanager.ControllerContext, cloud cloudprovider.Interface) (controller.Interface, bool, error) {
7171
var serviceCIDR *net.IPNet
7272
var secondaryServiceCIDR *net.IPNet
73+
var clusterCIDRs []*net.IPNet
74+
var nodeCIDRMaskSizes []int
7375

7476
// should we start nodeIPAM
7577
if !ccmConfig.ComponentConfig.KubeCloudShared.AllocateNodeCIDRs {
7678
return nil, false, fmt.Errorf("the AllocateNodeCIDRs is not enabled")
7779
}
7880

79-
// failure: bad cidrs in config
80-
clusterCIDRs, dualStack, err := processCIDRs(ccmConfig.ComponentConfig.KubeCloudShared.ClusterCIDR)
81-
if err != nil {
82-
return nil, false, err
83-
}
84-
85-
// failure: more than one cidr but they are not configured as dual stack
86-
if len(clusterCIDRs) > 1 && !dualStack {
87-
return nil, false, fmt.Errorf("len of ClusterCIDRs==%v and they are not configured as dual stack (at least one from each IPFamily", len(clusterCIDRs))
88-
}
81+
// the CloudAllocator ipam does not need service or cluster cidrs since it obtains the data from the cloud directly
82+
// for backward compatiblity reasons we don't fail if there are any of those values configured
83+
if ipam.CIDRAllocatorType(ccmConfig.ComponentConfig.KubeCloudShared.CIDRAllocatorType) != ipam.CloudAllocatorType {
84+
// failure: bad cidrs in config
85+
cidrs, dualStack, err := processCIDRs(ccmConfig.ComponentConfig.KubeCloudShared.ClusterCIDR)
86+
if err != nil {
87+
return nil, false, err
88+
}
89+
clusterCIDRs = cidrs
8990

90-
// failure: more than cidrs is not allowed even with dual stack
91-
if len(clusterCIDRs) > 2 {
92-
return nil, false, fmt.Errorf("len of clusters is:%v > more than max allowed of 2", len(clusterCIDRs))
93-
}
91+
// failure: more than one cidr but they are not configured as dual stack
92+
if len(clusterCIDRs) > 1 && !dualStack {
93+
return nil, false, fmt.Errorf("len of ClusterCIDRs==%v and they are not configured as dual stack (at least one from each IPFamily", len(clusterCIDRs))
94+
}
9495

95-
// service cidr processing
96-
if len(strings.TrimSpace(nodeIPAMConfig.ServiceCIDR)) != 0 {
97-
_, serviceCIDR, err = net.ParseCIDR(nodeIPAMConfig.ServiceCIDR)
98-
if err != nil {
99-
klog.Warningf("Unsuccessful parsing of service CIDR %v: %v", nodeIPAMConfig.ServiceCIDR, err)
96+
// failure: more than cidrs is not allowed even with dual stack
97+
if len(clusterCIDRs) > 2 {
98+
return nil, false, fmt.Errorf("len of clusters is:%v > more than max allowed of 2", len(clusterCIDRs))
10099
}
101-
}
102100

103-
if len(strings.TrimSpace(nodeIPAMConfig.SecondaryServiceCIDR)) != 0 {
104-
_, secondaryServiceCIDR, err = net.ParseCIDR(nodeIPAMConfig.SecondaryServiceCIDR)
105-
if err != nil {
106-
klog.Warningf("Unsuccessful parsing of service CIDR %v: %v", nodeIPAMConfig.SecondaryServiceCIDR, err)
101+
// service cidr processing
102+
if len(strings.TrimSpace(nodeIPAMConfig.ServiceCIDR)) != 0 {
103+
_, serviceCIDR, err = net.ParseCIDR(nodeIPAMConfig.ServiceCIDR)
104+
if err != nil {
105+
klog.Warningf("Unsuccessful parsing of service CIDR %v: %v", nodeIPAMConfig.ServiceCIDR, err)
106+
}
107107
}
108-
}
109108

110-
// the following checks are triggered if both serviceCIDR and secondaryServiceCIDR are provided
111-
if serviceCIDR != nil && secondaryServiceCIDR != nil {
112-
// should be dual stack (from different IPFamilies)
113-
dualstackServiceCIDR, err := netutils.IsDualStackCIDRs([]*net.IPNet{serviceCIDR, secondaryServiceCIDR})
114-
if err != nil {
115-
return nil, false, fmt.Errorf("failed to perform dualstack check on serviceCIDR and secondaryServiceCIDR error:%v", err)
109+
if len(strings.TrimSpace(nodeIPAMConfig.SecondaryServiceCIDR)) != 0 {
110+
_, secondaryServiceCIDR, err = net.ParseCIDR(nodeIPAMConfig.SecondaryServiceCIDR)
111+
if err != nil {
112+
klog.Warningf("Unsuccessful parsing of service CIDR %v: %v", nodeIPAMConfig.SecondaryServiceCIDR, err)
113+
}
116114
}
117-
if !dualstackServiceCIDR {
118-
return nil, false, fmt.Errorf("serviceCIDR and secondaryServiceCIDR are not dualstack (from different IPfamiles)")
115+
116+
// the following checks are triggered if both serviceCIDR and secondaryServiceCIDR are provided
117+
if serviceCIDR != nil && secondaryServiceCIDR != nil {
118+
// should be dual stack (from different IPFamilies)
119+
dualstackServiceCIDR, err := netutils.IsDualStackCIDRs([]*net.IPNet{serviceCIDR, secondaryServiceCIDR})
120+
if err != nil {
121+
return nil, false, fmt.Errorf("failed to perform dualstack check on serviceCIDR and secondaryServiceCIDR error:%v", err)
122+
}
123+
if !dualstackServiceCIDR {
124+
return nil, false, fmt.Errorf("serviceCIDR and secondaryServiceCIDR are not dualstack (from different IPfamiles)")
125+
}
119126
}
120-
}
121127

122-
// get list of node cidr mask sizes
123-
nodeCIDRMaskSizes, err := setNodeCIDRMaskSizes(nodeIPAMConfig, clusterCIDRs)
124-
if err != nil {
125-
return nil, false, err
128+
// get list of node cidr mask sizes
129+
nodeCIDRMaskSizes, err = setNodeCIDRMaskSizes(nodeIPAMConfig, clusterCIDRs)
130+
if err != nil {
131+
return nil, false, err
132+
}
126133
}
127134

128135
kubeConfig := ccmConfig.Complete().Kubeconfig

0 commit comments

Comments
 (0)