Skip to content

Commit 3b029e5

Browse files
author
Rahul Sharma
committed
enable adding ipv6 address as annotation
1 parent b0bf52f commit 3b029e5

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

cloud/annotations/annotations.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ const (
3838
// addresses for its LoadBalancer ingress. When set to "true", both addresses will be included in the status.
3939
AnnLinodeEnableIPv6Ingress = "service.beta.kubernetes.io/linode-loadbalancer-enable-ipv6-ingress"
4040

41-
AnnLinodeNodePrivateIP = "node.k8s.linode.com/private-ip"
42-
AnnLinodeHostUUID = "node.k8s.linode.com/host-uuid"
41+
AnnLinodeNodePrivateIP = "node.k8s.linode.com/private-ip"
42+
AnnLinodeHostUUID = "node.k8s.linode.com/host-uuid"
43+
AnnLinodeNodePublicIPv6 = "node.k8s.linode.com/public-ipv6"
4344

4445
AnnLinodeNodeIPSharingUpdated = "node.k8s.linode.com/ip-sharing-updated"
4546
AnnExcludeNodeFromNb = "node.k8s.linode.com/exclude-from-nb"

cloud/linode/node_controller.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,11 @@ func (s *nodeController) handleNode(ctx context.Context, node *v1.Node) error {
270270
lastUpdate := s.LastMetadataUpdate(node.Name)
271271

272272
uuid, foundLabel := node.Labels[annotations.AnnLinodeHostUUID]
273-
configuredPrivateIP, foundAnnotation := node.Annotations[annotations.AnnLinodeNodePrivateIP]
273+
configuredPrivateIP, foundPrivateIPAnnotation := node.Annotations[annotations.AnnLinodeNodePrivateIP]
274+
configuredPublicIPv6, foundIPv6Annotation := node.Annotations[annotations.AnnLinodeNodePublicIPv6]
274275

275276
metaAge := time.Since(lastUpdate)
276-
if foundLabel && foundAnnotation && metaAge < s.ttl {
277+
if foundLabel && foundPrivateIPAnnotation && foundIPv6Annotation && metaAge < s.ttl {
277278
klog.V(3).InfoS("Skipping refresh, ttl not reached",
278279
"node", klog.KObj(node),
279280
"ttl", s.ttl,
@@ -298,7 +299,8 @@ func (s *nodeController) handleNode(ctx context.Context, node *v1.Node) error {
298299
}
299300
}
300301

301-
if uuid == linode.HostUUID && node.Spec.ProviderID != "" && configuredPrivateIP == expectedPrivateIP {
302+
expectedPublicIPv6 := linode.IPv6
303+
if uuid == linode.HostUUID && node.Spec.ProviderID != "" && configuredPrivateIP == expectedPrivateIP && configuredPublicIPv6 == expectedPublicIPv6 {
302304
s.SetLastMetadataUpdate(node.Name)
303305
return nil
304306
}
@@ -325,6 +327,9 @@ func (s *nodeController) handleNode(ctx context.Context, node *v1.Node) error {
325327
if nodeResult.Annotations[annotations.AnnLinodeNodePrivateIP] != expectedPrivateIP && expectedPrivateIP != "" {
326328
nodeResult.Annotations[annotations.AnnLinodeNodePrivateIP] = expectedPrivateIP
327329
}
330+
if nodeResult.Annotations[annotations.AnnLinodeNodePublicIPv6] != expectedPublicIPv6 && expectedPublicIPv6 != "" {
331+
nodeResult.Annotations[annotations.AnnLinodeNodePublicIPv6] = expectedPublicIPv6
332+
}
328333
updatedNode, err = s.kubeclient.CoreV1().Nodes().Update(ctx, nodeResult, metav1.UpdateOptions{})
329334
return err
330335
}); err != nil {

cloud/linode/node_controller_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,9 @@ func TestNodeController_handleNode(t *testing.T) {
226226
// Test: Successful metadata update
227227
publicIP := net.ParseIP("172.234.31.123")
228228
privateIP := net.ParseIP("192.168.159.135")
229+
publicIPv6SLAAC := "2001:db::f03c:91ff:fe2b:1a2b"
229230
client.EXPECT().ListInstances(gomock.Any(), nil).Times(1).Return([]linodego.Instance{
230-
{ID: 123, Label: "test-node", IPv4: []*net.IP{&publicIP, &privateIP}, HostUUID: "123"},
231+
{ID: 123, Label: "test-node", IPv4: []*net.IP{&publicIP, &privateIP}, IPv6: publicIPv6SLAAC, HostUUID: "123"},
231232
}, nil)
232233
err = nodeCtrl.handleNode(t.Context(), node)
233234
require.NoError(t, err, "expected no error during handleNode")
@@ -241,6 +242,7 @@ func TestNodeController_handleNode(t *testing.T) {
241242
// Annotations set, no update needed as ttl not reached
242243
node.Labels[annotations.AnnLinodeHostUUID] = "123"
243244
node.Annotations[annotations.AnnLinodeNodePrivateIP] = privateIP.String()
245+
node.Annotations[annotations.AnnLinodeNodePublicIPv6] = publicIPv6SLAAC
244246
err = nodeCtrl.handleNode(t.Context(), node)
245247
require.NoError(t, err, "expected no error during handleNode")
246248

@@ -257,7 +259,7 @@ func TestNodeController_handleNode(t *testing.T) {
257259
nodeCtrl.instances = newInstances(client)
258260
nodeCtrl.metadataLastUpdate["test-node"] = time.Now().Add(-2 * nodeCtrl.ttl)
259261
client.EXPECT().ListInstances(gomock.Any(), nil).Times(1).Return([]linodego.Instance{
260-
{ID: 123, Label: "test-node", IPv4: []*net.IP{&publicIP, &privateIP}, HostUUID: "123"},
262+
{ID: 123, Label: "test-node", IPv4: []*net.IP{&publicIP, &privateIP}, IPv6: publicIPv6SLAAC, HostUUID: "123"},
261263
}, nil)
262264
err = nodeCtrl.handleNode(t.Context(), node)
263265
assert.NoError(t, err, "expected no error during handleNode")

docs/configuration/environment.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ The CCM supports the following flags:
5656
| `--node-cidr-mask-size-ipv4` | Int | `24` | ipv4 cidr mask size for pod cidrs allocated to nodes |
5757
| `--node-cidr-mask-size-ipv6` | Int | `64` | ipv6 cidr mask size for pod cidrs allocated to nodes |
5858
| `--nodebalancer-prefix` | String | `ccm` | Name prefix for NoadBalancers. |
59-
| `--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) |
59+
| `--disable-ipv6-node-cidr-allocation` | Boolean | `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) |
6060

6161
## Configuration Methods
6262

0 commit comments

Comments
 (0)