Update ParseNodeIPArgument for cloud dual-stack

Add an arg to ParseNodeIPArgument saying whether to allow dual-stack
IPs for external cloud providers. Update kubelet for the new API, but
always pass "false" for now.
This commit is contained in:
Dan Winship 2023-03-03 11:29:31 -05:00
parent 0f1f1711fe
commit 77e0fbe774
3 changed files with 26 additions and 10 deletions

View File

@ -1120,7 +1120,7 @@ func RunKubelet(kubeServer *options.KubeletServer, kubeDeps *kubelet.Dependencie
// Setup event recorder if required.
makeEventRecorder(kubeDeps, nodeName)
nodeIPs, err := nodeutil.ParseNodeIPArgument(kubeServer.NodeIP, kubeServer.CloudProvider)
nodeIPs, err := nodeutil.ParseNodeIPArgument(kubeServer.NodeIP, kubeServer.CloudProvider, false)
if err != nil {
return fmt.Errorf("bad --node-ip %q: %v", kubeServer.NodeIP, err)
}

View File

@ -63,10 +63,14 @@ func parseNodeIP(nodeIP string, allowDual, sloppy bool) ([]net.IP, error) {
}
// ParseNodeIPArgument parses kubelet's --node-ip argument. If nodeIP contains invalid
// values, they will be logged and ignored. Dual-stack node IPs are only supported if
// cloudProvider is unset.
func ParseNodeIPArgument(nodeIP, cloudProvider string) ([]net.IP, error) {
return parseNodeIP(nodeIP, cloudProvider == cloudProviderNone, true)
// values, they will be logged and ignored. Dual-stack node IPs are allowed if
// cloudProvider is unset, or if it is `"external"` and allowCloudDualStack is true.
func ParseNodeIPArgument(nodeIP, cloudProvider string, allowCloudDualStack bool) ([]net.IP, error) {
var allowDualStack bool
if (cloudProvider == cloudProviderNone) || (cloudProvider == cloudProviderExternal && allowCloudDualStack) {
allowDualStack = true
}
return parseNodeIP(nodeIP, allowDualStack, true)
}
// ParseNodeIPAnnotation parses the `alpha.kubernetes.io/provided-node-ip` annotation,

View File

@ -164,17 +164,29 @@ func TestParseNodeIPArgument(t *testing.T) {
},
}
configurations := []struct {
cloudProvider string
allowCloudDualStack bool
dualStackSupported bool
}{
{cloudProviderNone, false, true},
{cloudProviderNone, true, true},
{cloudProviderExternal, false, false},
{cloudProviderExternal, true, true},
{"gce", false, false},
{"gce", true, false},
}
for _, tc := range testCases {
for _, cloudProvider := range []string{cloudProviderNone, cloudProviderExternal, "gce"} {
desc := fmt.Sprintf("%s, cloudProvider=%q", tc.desc, cloudProvider)
for _, conf := range configurations {
desc := fmt.Sprintf("%s, cloudProvider=%q, allowCloudDualStack=%v", tc.desc, conf.cloudProvider, conf.allowCloudDualStack)
t.Run(desc, func(t *testing.T) {
parsed, err := ParseNodeIPArgument(tc.in, cloudProvider)
parsed, err := ParseNodeIPArgument(tc.in, conf.cloudProvider, conf.allowCloudDualStack)
expectedOut := tc.out
expectedErr := tc.err
// Dual-stack is only supported with no cloudProvider
if cloudProvider != "" {
if !conf.dualStackSupported {
if len(tc.out) == 2 {
expectedOut = nil
}