Skip to content

Commit 74cd18c

Browse files
author
Rahul Sharma
committed
add flag to enable/disable ipv6 allocation logic
1 parent fcae6d9 commit 74cd18c

File tree

10 files changed

+52
-21
lines changed

10 files changed

+52
-21
lines changed

cloud/linode/cloud.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ var Options struct {
5555
GlobalStopChannel chan<- struct{}
5656
EnableIPv6ForLoadBalancers bool
5757
AllocateNodeCIDRs bool
58+
DisableIPv6NodeCIDRAllocation bool
5859
ClusterCIDRIPv4 string
5960
NodeCIDRMaskSizeIPv4 int
6061
NodeCIDRMaskSizeIPv6 int

cloud/linode/nodeipamcontroller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ func startNodeIpamController(stopCh <-chan struct{}, cloud *linodeCloud, nodeInf
8686
secondaryServiceCIDR,
8787
nodeCIDRMaskSizes,
8888
ipam.CloudAllocatorType,
89+
Options.DisableIPv6NodeCIDRAllocation,
8990
)
9091
if err != nil {
9192
return err

cloud/nodeipam/ipam/cidr_allocator.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ type CIDRAllocatorParams struct {
9292
// SecondaryServiceCIDR is secondary service cidr for cluster.
9393
SecondaryServiceCIDR *net.IPNet
9494
// NodeCIDRMaskSizes is list of node cidr mask sizes.
95-
NodeCIDRMaskSizes []int
95+
NodeCIDRMaskSizes []int
96+
DisableIPv6NodeCIDRAllocation bool
9697
}
9798

9899
// New creates a new CIDR range allocator.

cloud/nodeipam/ipam/cloud_allocator.go

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ type cloudAllocator struct {
6868

6969
// nodeCIDRMaskSizeIPv6 is the mask size for the IPv6 CIDR assigned to nodes.
7070
nodeCIDRMaskSizeIPv6 int
71+
// disableIPv6NodeCIDRAllocation is true if we should not allocate IPv6 CIDRs for nodes.
72+
disableIPv6NodeCIDRAllocation bool
7173
}
7274

7375
const providerIDPrefix = "linode://"
@@ -96,16 +98,17 @@ func NewLinodeCIDRAllocator(ctx context.Context, linodeClient linode.Client, cli
9698
}
9799

98100
ca := &cloudAllocator{
99-
client: client,
100-
linodeClient: linodeClient,
101-
clusterCIDR: allocatorParams.ClusterCIDRs[0],
102-
cidrSet: cidrSet,
103-
nodeLister: nodeInformer.Lister(),
104-
nodesSynced: nodeInformer.Informer().HasSynced,
105-
broadcaster: eventBroadcaster,
106-
recorder: recorder,
107-
queue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultTypedControllerRateLimiter[any](), "cidrallocator_node"),
108-
nodeCIDRMaskSizeIPv6: allocatorParams.NodeCIDRMaskSizes[1],
101+
client: client,
102+
linodeClient: linodeClient,
103+
clusterCIDR: allocatorParams.ClusterCIDRs[0],
104+
cidrSet: cidrSet,
105+
nodeLister: nodeInformer.Lister(),
106+
nodesSynced: nodeInformer.Informer().HasSynced,
107+
broadcaster: eventBroadcaster,
108+
recorder: recorder,
109+
queue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultTypedControllerRateLimiter[any](), "cidrallocator_node"),
110+
nodeCIDRMaskSizeIPv6: allocatorParams.NodeCIDRMaskSizes[1],
111+
disableIPv6NodeCIDRAllocation: allocatorParams.DisableIPv6NodeCIDRAllocation,
109112
}
110113

111114
if allocatorParams.ServiceCIDR != nil {
@@ -393,13 +396,26 @@ func (c *cloudAllocator) AllocateOrOccupyCIDR(ctx context.Context, node *v1.Node
393396
return fmt.Errorf("failed to allocate cidr from cluster cidr: %w", err)
394397
}
395398
allocatedCIDRs[0] = podCIDR
399+
400+
// If IPv6 CIDR allocation is disabled, log and return early.
401+
if c.disableIPv6NodeCIDRAllocation {
402+
logger.V(4).Info("IPv6 CIDR allocation disabled; using only IPv4", "node", klog.KObj(node))
403+
return c.enqueueCIDRUpdate(ctx, node.Name, allocatedCIDRs)
404+
}
405+
// Allocate IPv6 CIDR for the node.
406+
logger.V(4).Info("Allocating IPv6 CIDR", "node", klog.KObj(node))
396407
if allocatedCIDRs[1], err = c.allocateIPv6CIDR(ctx, node); err != nil {
397408
return fmt.Errorf("failed to assign IPv6 CIDR: %w", err)
398409
}
399410

400-
// queue the assignment
401-
logger.V(4).Info("Putting node with CIDR into the work queue", "node", klog.KObj(node), "CIDR", allocatedCIDRs)
402-
return c.updateCIDRsAllocation(ctx, node.Name, allocatedCIDRs)
411+
return c.enqueueCIDRUpdate(ctx, node.Name, allocatedCIDRs)
412+
}
413+
414+
// enqueueCIDRUpdate adds the node name and CIDRs to the work queue for processing.
415+
func (c *cloudAllocator) enqueueCIDRUpdate(ctx context.Context, nodeName string, cidrs []*net.IPNet) error {
416+
logger := klog.FromContext(ctx)
417+
logger.V(4).Info("Putting node with CIDR into the work queue", "node", nodeName, "CIDR", cidrs)
418+
return c.updateCIDRsAllocation(ctx, nodeName, cidrs)
403419
}
404420

405421
// ReleaseCIDR marks node.podCIDRs[...] as unused in our tracked cidrSets

cloud/nodeipam/node_ipam_controller.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ type Controller struct {
5151
nodeLister corelisters.NodeLister
5252
nodeInformerSynced cache.InformerSynced
5353

54-
cidrAllocator ipam.CIDRAllocator
54+
cidrAllocator ipam.CIDRAllocator
55+
disableIPv6NodeCIDRAllocation bool
5556
}
5657

5758
// NewNodeIpamController returns a new node IP Address Management controller to
@@ -70,6 +71,7 @@ func NewNodeIpamController(
7071
secondaryServiceCIDR *net.IPNet,
7172
nodeCIDRMaskSizes []int,
7273
allocatorType ipam.CIDRAllocatorType,
74+
disableIPv6NodeCIDRAllocation bool,
7375
) (*Controller, error) {
7476
if kubeClient == nil {
7577
return nil, fmt.Errorf("kubeClient is nil when starting Controller")
@@ -100,10 +102,11 @@ func NewNodeIpamController(
100102
var err error
101103

102104
allocatorParams := ipam.CIDRAllocatorParams{
103-
ClusterCIDRs: clusterCIDRs,
104-
ServiceCIDR: ic.serviceCIDR,
105-
SecondaryServiceCIDR: ic.secondaryServiceCIDR,
106-
NodeCIDRMaskSizes: nodeCIDRMaskSizes,
105+
ClusterCIDRs: clusterCIDRs,
106+
ServiceCIDR: ic.serviceCIDR,
107+
SecondaryServiceCIDR: ic.secondaryServiceCIDR,
108+
NodeCIDRMaskSizes: nodeCIDRMaskSizes,
109+
DisableIPv6NodeCIDRAllocation: disableIPv6NodeCIDRAllocation,
107110
}
108111

109112
ic.cidrAllocator, err = ipam.New(ctx, ic.linodeClient, kubeClient, cloud, nodeInformer, ic.allocatorType, allocatorParams)

deploy/chart/templates/daemonset.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ spec:
6868
{{- if not $clusterCIDR }}
6969
{{- fail "clusterCIDR is required if enableNodeIPAM is set" }}
7070
{{- end }}
71+
{{- with .Values.disableIPv6NodeCIDRAllocation }}
72+
- --disable-ipv6-node-cidr-allocation={{ . }}
73+
{{- end }}
7174
{{- with .Values.nodeCIDRMaskSizeIPv4 }}
7275
- --node-cidr-mask-size-ipv4={{ . }}
7376
{{- end }}

deploy/chart/values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ tolerations:
8686
# clusterCIDR: 10.192.0.0/10
8787
# nodeCIDRMaskSizeIPv4: 24
8888
# nodeCIDRMaskSizeIPv6: 64
89+
# disableIPv6NodeCIDRAllocation: false
8990

9091
# vpcs and subnets that node internal IPs will be assigned from (not required if already specified in routeController)
9192
# vpcName: <name of VPC> [Deprecated: use vpcNames instead]

docs/configuration/environment.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ The CCM supports the following flags:
5353
| `--enable-ipv6-for-loadbalancers` | `false` | Set both IPv4 and IPv6 addresses for all LoadBalancer services (when disabled, only IPv4 is used). This can also be configured per-service using the `service.beta.kubernetes.io/linode-loadbalancer-enable-ipv6-ingress` annotation. |
5454
| `--node-cidr-mask-size-ipv4` | `24` | ipv4 cidr mask size for pod cidrs allocated to nodes |
5555
| `--node-cidr-mask-size-ipv6` | `64` | ipv6 cidr mask size for pod cidrs allocated to nodes |
56+
| `--disable-ipv6-node-cidr-allocation` | `false` | disables allocating ipv6 CIDR ranges to nodes when using CCM for node IPAM (set to `true` if ipv6 ranges are not configured on linode interfaces) |
5657

5758
## Configuration Methods
5859

docs/configuration/nodeipam.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Note:
2121
Make sure node IPAM allocation is disabled in kube-controller-manager to avoid both controllers competing to assign CIDRs to nodes. To make sure its disabled, check and make sure kube-controller-manager is not started with `--allocate-node-cidrs` flag.
2222

2323
## Allocated subnet size
24-
By default, CCM allocates /24 subnet for ipv4 addresses and /64 for ipv6 addresses to nodes. If one wants different subnet range, it can be configured by using `--node-cidr-mask-size-ipv4` and `--node-cidr-mask-size-ipv6` flags.
24+
By default, CCM allocates /24 subnet for ipv4 addresses and /112 for ipv6 addresses to nodes. For ipv6 cidr allocation using CCM, linodes should have ipv6 ranges configured on their interfaces. If one wants different subnet range, it can be configured by using `--node-cidr-mask-size-ipv4` and `--node-cidr-mask-size-ipv6` flags.
2525

2626
```yaml
2727
spec:
@@ -31,7 +31,10 @@ spec:
3131
- name: ccm-linode
3232
args:
3333
- --allocate-node-cidrs=true
34-
- --cluster-cidr=10.192.0.0/10,fd00::/56
34+
- --cluster-cidr=10.192.0.0/10
3535
- --node-cidr-mask-size-ipv4=25
3636
- --node-cidr-mask-size-ipv6=64
3737
```
38+
39+
## Disabling ipv6 ipam allocation
40+
If one wants to just use ipv4 node ipam allocation for their nodes, they can start CCM with `--disable-ipv6-node-cidr-allocation=true` which disables ipv6 range allocation to nodes.

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ func main() {
9898
command.Flags().IntVar(&linode.Options.NodeBalancerBackendIPv4SubnetID, "nodebalancer-backend-ipv4-subnet-id", 0, "ipv4 subnet id to use for NodeBalancer backends")
9999
command.Flags().StringVar(&linode.Options.NodeBalancerBackendIPv4SubnetName, "nodebalancer-backend-ipv4-subnet-name", "", "ipv4 subnet name to use for NodeBalancer backends")
100100
command.Flags().BoolVar(&linode.Options.DisableNodeBalancerVPCBackends, "disable-nodebalancer-vpc-backends", false, "disables nodebalancer backends in VPCs (when enabled, nodebalancers will only have private IPs as backends for backward compatibility)")
101+
command.Flags().BoolVar(&linode.Options.DisableIPv6NodeCIDRAllocation, "disable-ipv6-node-cidr-allocation", false, "disables IPv6 node cidr allocation by ipam controller (when enabled, IPv6 cidr ranges will be allocated to nodes)")
101102

102103
// Set static flags
103104
command.Flags().VisitAll(func(fl *pflag.Flag) {

0 commit comments

Comments
 (0)