Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set the node-ips annotation correctly with CloudDualStackNodeIPs #118329

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion pkg/kubelet/nodestatus/setters.go
Expand Up @@ -109,7 +109,11 @@ func NodeAddress(nodeIPs []net.IP, // typically Kubelet.nodeIPs
if node.ObjectMeta.Annotations == nil {
node.ObjectMeta.Annotations = make(map[string]string)
}
node.ObjectMeta.Annotations[cloudproviderapi.AnnotationAlphaProvidedIPAddr] = nodeIP.String()
annotation := nodeIP.String()
if secondaryNodeIPSpecified {
annotation += "," + secondaryNodeIP.String()
}
node.ObjectMeta.Annotations[cloudproviderapi.AnnotationAlphaProvidedIPAddr] = annotation
} else if node.ObjectMeta.Annotations != nil {
// Clean up stale annotations if no longer using a cloud provider or
// no longer overriding node IP.
Expand Down
77 changes: 75 additions & 2 deletions pkg/kubelet/nodestatus/setters_test.go
Expand Up @@ -68,6 +68,7 @@ func TestNodeAddress(t *testing.T) {
name string
hostnameOverride bool
nodeIP net.IP
secondaryNodeIP net.IP
cloudProviderType cloudProviderType
nodeAddresses []v1.NodeAddress
expectedAddresses []v1.NodeAddress
Expand Down Expand Up @@ -521,6 +522,74 @@ func TestNodeAddress(t *testing.T) {
},
shouldError: false,
},
{
// We don't have to test "legacy cloud provider with dual-stack
// IPs" etc because we won't have gotten this far with an invalid
// config like that.
name: "Dual-stack cloud, with dual-stack nodeIPs",
nodeIP: netutils.ParseIPSloppy("2600:1f14:1d4:d101::ba3d"),
secondaryNodeIP: netutils.ParseIPSloppy("10.1.1.2"),
cloudProviderType: cloudProviderExternal,
nodeAddresses: []v1.NodeAddress{
{Type: v1.NodeInternalIP, Address: "10.1.1.1"},
{Type: v1.NodeInternalIP, Address: "10.1.1.2"},
{Type: v1.NodeInternalIP, Address: "2600:1f14:1d4:d101::ba3d"},
{Type: v1.NodeHostName, Address: testKubeletHostname},
},
expectedAddresses: []v1.NodeAddress{
{Type: v1.NodeInternalIP, Address: "2600:1f14:1d4:d101::ba3d"},
{Type: v1.NodeInternalIP, Address: "10.1.1.2"},
{Type: v1.NodeHostName, Address: testKubeletHostname},
},
expectedAnnotations: map[string]string{
"alpha.kubernetes.io/provided-node-ip": "2600:1f14:1d4:d101::ba3d,10.1.1.2",
},
shouldError: false,
},
{
name: "Upgrade to cloud dual-stack nodeIPs",
nodeIP: netutils.ParseIPSloppy("10.1.1.1"),
secondaryNodeIP: netutils.ParseIPSloppy("2600:1f14:1d4:d101::ba3d"),
cloudProviderType: cloudProviderExternal,
nodeAddresses: []v1.NodeAddress{
{Type: v1.NodeInternalIP, Address: "10.1.1.1"},
{Type: v1.NodeInternalIP, Address: "2600:1f14:1d4:d101::ba3d"},
{Type: v1.NodeHostName, Address: testKubeletHostname},
},
expectedAddresses: []v1.NodeAddress{
{Type: v1.NodeInternalIP, Address: "10.1.1.1"},
{Type: v1.NodeInternalIP, Address: "2600:1f14:1d4:d101::ba3d"},
{Type: v1.NodeHostName, Address: testKubeletHostname},
},
existingAnnotations: map[string]string{
"alpha.kubernetes.io/provided-node-ip": "10.1.1.1",
},
expectedAnnotations: map[string]string{
"alpha.kubernetes.io/provided-node-ip": "10.1.1.1,2600:1f14:1d4:d101::ba3d",
},
shouldError: false,
},
{
name: "Downgrade from cloud dual-stack nodeIPs",
nodeIP: netutils.ParseIPSloppy("10.1.1.1"),
cloudProviderType: cloudProviderExternal,
nodeAddresses: []v1.NodeAddress{
{Type: v1.NodeInternalIP, Address: "10.1.1.1"},
{Type: v1.NodeInternalIP, Address: "2600:1f14:1d4:d101::ba3d"},
{Type: v1.NodeHostName, Address: testKubeletHostname},
},
expectedAddresses: []v1.NodeAddress{
{Type: v1.NodeInternalIP, Address: "10.1.1.1"},
{Type: v1.NodeHostName, Address: testKubeletHostname},
},
existingAnnotations: map[string]string{
"alpha.kubernetes.io/provided-node-ip": "10.1.1.1,2600:1f14:1d4:d101::ba3d",
},
expectedAnnotations: map[string]string{
"alpha.kubernetes.io/provided-node-ip": "10.1.1.1",
},
shouldError: false,
},
}
for _, testCase := range cases {
t.Run(testCase.name, func(t *testing.T) {
Expand All @@ -541,7 +610,6 @@ func TestNodeAddress(t *testing.T) {
existingNode.Status.Addresses = append(existingNode.Status.Addresses, existingNodeAddress)
}

nodeIP := testCase.nodeIP
nodeIPValidator := func(nodeIP net.IP) error {
return nil
}
Expand All @@ -560,8 +628,13 @@ func TestNodeAddress(t *testing.T) {
}
}

nodeIPs := []net.IP{testCase.nodeIP}
if testCase.secondaryNodeIP != nil {
nodeIPs = append(nodeIPs, testCase.secondaryNodeIP)
}

// construct setter
setter := NodeAddress([]net.IP{nodeIP},
setter := NodeAddress(nodeIPs,
nodeIPValidator,
hostname,
testCase.hostnameOverride,
Expand Down