Skip to content

Commit 38697af

Browse files
authored
Merge pull request #607 from aojea/ipv6_only_ipam
cloudAllocator ipv6 only ipam
2 parents f25aa9e + ce1a81a commit 38697af

File tree

2 files changed

+57
-4
lines changed

2 files changed

+57
-4
lines changed

pkg/controller/nodeipam/ipam/cloud_cidr_allocator.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,17 +311,31 @@ func (ca *cloudCIDRAllocator) updateCIDRAllocation(nodeName string) error {
311311

312312
cidrStrings := make([]string, 0)
313313

314-
if len(instance.NetworkInterfaces) == 0 || (len(instance.NetworkInterfaces) == 1 && len(instance.NetworkInterfaces[0].AliasIpRanges) == 0) {
314+
// if there are no interfaces or there is 1 interface
315+
// but does not have IP alias or IPv6 ranges no CIDR
316+
// can be allocated
317+
if len(instance.NetworkInterfaces) == 0 ||
318+
(len(instance.NetworkInterfaces) == 1 &&
319+
len(instance.NetworkInterfaces[0].AliasIpRanges) == 0 &&
320+
ca.cloud.GetIPV6Address(instance.NetworkInterfaces[0]) == nil) {
315321
nodeutil.RecordNodeStatusChange(ca.recorder, node, "CIDRNotAvailable")
316322
return fmt.Errorf("failed to allocate cidr: Node %v has no ranges from which CIDRs can be allocated", node.Name)
317323
}
318324

319325
// sets the v1.NodeNetworkUnavailable condition to False
320326
ca.setNetworkCondition(node)
321327

322-
// nodes in clusters WITHOUT multi-networking are expected to have only 1 network-interface with 1 alias IP range.
323-
if len(instance.NetworkInterfaces) == 1 && len(instance.NetworkInterfaces[0].AliasIpRanges) == 1 {
324-
cidrStrings = append(cidrStrings, instance.NetworkInterfaces[0].AliasIpRanges[0].IpCidrRange)
328+
// nodes in clusters WITHOUT multi-networking are expected to have
329+
// only 1 network-interface and 1 alias IPv4 range or/and 1 IPv6 address
330+
// multi-network cluster may have 1 interface with multiple alias
331+
if len(instance.NetworkInterfaces) == 1 &&
332+
(len(instance.NetworkInterfaces[0].AliasIpRanges) == 1 ||
333+
ca.cloud.GetIPV6Address(instance.NetworkInterfaces[0]) != nil) {
334+
// with 1 alias IPv4 range on single IPv4 or dual stack clusters
335+
if len(instance.NetworkInterfaces[0].AliasIpRanges) == 1 {
336+
cidrStrings = append(cidrStrings, instance.NetworkInterfaces[0].AliasIpRanges[0].IpCidrRange)
337+
}
338+
// with 1 IPv6 range on single IPv6 or dual stack cluster
325339
ipv6Addr := ca.cloud.GetIPV6Address(instance.NetworkInterfaces[0])
326340
if ipv6Addr != nil {
327341
cidrStrings = append(cidrStrings, ipv6Addr.String())

pkg/controller/nodeipam/ipam/cloud_cidr_allocator_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,45 @@ func TestUpdateCIDRAllocation(t *testing.T) {
281281
},
282282
expectedUpdate: true,
283283
},
284+
{
285+
name: "ipv6 single stack",
286+
fakeNodeHandler: &testutil.FakeNodeHandler{
287+
Existing: []*v1.Node{
288+
{
289+
ObjectMeta: metav1.ObjectMeta{
290+
Name: "test",
291+
},
292+
Spec: v1.NodeSpec{
293+
ProviderID: "gce://test-project/us-central1-b/test",
294+
},
295+
},
296+
},
297+
Clientset: fake.NewSimpleClientset(),
298+
},
299+
gceInstance: []*compute.Instance{
300+
{
301+
Name: "test",
302+
NetworkInterfaces: []*compute.NetworkInterface{
303+
{
304+
Ipv6Address: "2001:db9::110",
305+
},
306+
},
307+
},
308+
},
309+
nodeChanges: func(node *v1.Node) {
310+
node.Spec.PodCIDR = "2001:db9::/112"
311+
node.Spec.PodCIDRs = []string{"2001:db9::/112"}
312+
node.Status.Conditions = []v1.NodeCondition{
313+
{
314+
Type: "NetworkUnavailable",
315+
Status: "False",
316+
Reason: "RouteCreated",
317+
Message: "NodeController create implicit route",
318+
},
319+
}
320+
},
321+
expectedUpdate: true,
322+
},
284323
{
285324
name: "want error - incorrect cidr",
286325
fakeNodeHandler: &testutil.FakeNodeHandler{

0 commit comments

Comments
 (0)