mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 10:51:29 +00:00
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:
parent
0f1f1711fe
commit
77e0fbe774
@ -1120,7 +1120,7 @@ func RunKubelet(kubeServer *options.KubeletServer, kubeDeps *kubelet.Dependencie
|
|||||||
// Setup event recorder if required.
|
// Setup event recorder if required.
|
||||||
makeEventRecorder(kubeDeps, nodeName)
|
makeEventRecorder(kubeDeps, nodeName)
|
||||||
|
|
||||||
nodeIPs, err := nodeutil.ParseNodeIPArgument(kubeServer.NodeIP, kubeServer.CloudProvider)
|
nodeIPs, err := nodeutil.ParseNodeIPArgument(kubeServer.NodeIP, kubeServer.CloudProvider, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("bad --node-ip %q: %v", kubeServer.NodeIP, err)
|
return fmt.Errorf("bad --node-ip %q: %v", kubeServer.NodeIP, err)
|
||||||
}
|
}
|
||||||
|
@ -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
|
// 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
|
// values, they will be logged and ignored. Dual-stack node IPs are allowed if
|
||||||
// cloudProvider is unset.
|
// cloudProvider is unset, or if it is `"external"` and allowCloudDualStack is true.
|
||||||
func ParseNodeIPArgument(nodeIP, cloudProvider string) ([]net.IP, error) {
|
func ParseNodeIPArgument(nodeIP, cloudProvider string, allowCloudDualStack bool) ([]net.IP, error) {
|
||||||
return parseNodeIP(nodeIP, cloudProvider == cloudProviderNone, true)
|
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,
|
// ParseNodeIPAnnotation parses the `alpha.kubernetes.io/provided-node-ip` annotation,
|
||||||
|
@ -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 _, tc := range testCases {
|
||||||
for _, cloudProvider := range []string{cloudProviderNone, cloudProviderExternal, "gce"} {
|
for _, conf := range configurations {
|
||||||
desc := fmt.Sprintf("%s, cloudProvider=%q", tc.desc, cloudProvider)
|
desc := fmt.Sprintf("%s, cloudProvider=%q, allowCloudDualStack=%v", tc.desc, conf.cloudProvider, conf.allowCloudDualStack)
|
||||||
t.Run(desc, func(t *testing.T) {
|
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
|
expectedOut := tc.out
|
||||||
expectedErr := tc.err
|
expectedErr := tc.err
|
||||||
|
|
||||||
// Dual-stack is only supported with no cloudProvider
|
if !conf.dualStackSupported {
|
||||||
if cloudProvider != "" {
|
|
||||||
if len(tc.out) == 2 {
|
if len(tc.out) == 2 {
|
||||||
expectedOut = nil
|
expectedOut = nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user