@@ -70,59 +70,66 @@ func (nodeIpamController *nodeIPAMController) startNodeIpamControllerWrapper(ini
70
70
func startNodeIpamController (ccmConfig * cloudcontrollerconfig.CompletedConfig , nodeIPAMConfig nodeipamconfig.NodeIPAMControllerConfiguration , ctx genericcontrollermanager.ControllerContext , cloud cloudprovider.Interface ) (controller.Interface , bool , error ) {
71
71
var serviceCIDR * net.IPNet
72
72
var secondaryServiceCIDR * net.IPNet
73
+ var clusterCIDRs []* net.IPNet
74
+ var nodeCIDRMaskSizes []int
73
75
74
76
// should we start nodeIPAM
75
77
if ! ccmConfig .ComponentConfig .KubeCloudShared .AllocateNodeCIDRs {
76
78
return nil , false , fmt .Errorf ("the AllocateNodeCIDRs is not enabled" )
77
79
}
78
80
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
89
90
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
+ }
94
95
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 ))
100
99
}
101
- }
102
100
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
+ }
107
107
}
108
- }
109
108
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
+ }
116
114
}
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
+ }
119
126
}
120
- }
121
127
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
+ }
126
133
}
127
134
128
135
kubeConfig := ccmConfig .Complete ().Kubeconfig
0 commit comments