mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-16 22:53:22 +00:00
kubeadm: skip ipv4 check if the cluster is using IPv6 address
Signed-off-by: Dave Chen <dave.chen@arm.com>
This commit is contained in:
@@ -26,6 +26,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/lithammer/dedent"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
@@ -36,7 +37,9 @@ import (
|
||||
fakeexec "k8s.io/utils/exec/testing"
|
||||
|
||||
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
|
||||
kubeadmapiv1 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta3"
|
||||
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
||||
configutil "k8s.io/kubernetes/cmd/kubeadm/app/util/config"
|
||||
utilruntime "k8s.io/kubernetes/cmd/kubeadm/app/util/runtime"
|
||||
)
|
||||
|
||||
@@ -1005,3 +1008,134 @@ func TestMemCheck(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestInitIPCheck(t *testing.T) {
|
||||
// skip this test, if OS in not Linux, since it will ONLY pass on Linux.
|
||||
if runtime.GOOS != "linux" {
|
||||
t.Skip("unsupported OS")
|
||||
}
|
||||
// should be a privileged user for the `init` command, otherwise just skip it.
|
||||
isPrivileged := IsPrivilegedUserCheck{}
|
||||
if _, err := isPrivileged.Check(); err != nil {
|
||||
t.Skip("not a privileged user")
|
||||
}
|
||||
internalcfg, err := configutil.DefaultedStaticInitConfiguration()
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected failure when defaulting InitConfiguration: %v", err)
|
||||
}
|
||||
internalcfg.LocalAPIEndpoint.AdvertiseAddress = "" // AdvertiseAddress is optional, it could be auto-detected.
|
||||
ipv4File := "FileContent--proc-sys-net-ipv4-ip_forward"
|
||||
ipv6File := "FileContent--proc-sys-net-ipv6-conf-default-forwarding"
|
||||
var tests = []struct {
|
||||
testName string
|
||||
PodSubnet string
|
||||
serviceCidr string
|
||||
expStr []string
|
||||
}{
|
||||
{
|
||||
testName: "dual stack",
|
||||
PodSubnet: "fda9:d324:354d:0::/56",
|
||||
serviceCidr: "10.96.0.0/16,fda9:d324:354d:1::/112",
|
||||
expStr: []string{"FileContent--proc-sys-net-ipv4-ip_forward", "FileContent--proc-sys-net-ipv6-conf-default-forwarding"},
|
||||
},
|
||||
{
|
||||
testName: "single stack ipv4",
|
||||
PodSubnet: "10.244.0.0/16",
|
||||
serviceCidr: "10.96.0.0/16",
|
||||
expStr: []string{"FileContent--proc-sys-net-ipv4-ip_forward"},
|
||||
},
|
||||
{
|
||||
testName: "single stack ipv6",
|
||||
PodSubnet: "fda9:d324:354d:0::/56",
|
||||
serviceCidr: "fda9:d324:354d:1::/112",
|
||||
expStr: []string{"FileContent--proc-sys-net-ipv6-conf-default-forwarding"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, rt := range tests {
|
||||
t.Run(rt.testName, func(t *testing.T) {
|
||||
checkList := []string{}
|
||||
internalcfg.Networking.ServiceSubnet = rt.serviceCidr
|
||||
internalcfg.Networking.PodSubnet = rt.PodSubnet
|
||||
checks, err := InitNodeChecks(exec.New(), internalcfg, nil, false, false)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
for _, check := range checks {
|
||||
if check.Name() == ipv4File {
|
||||
checkList = append(checkList, ipv4File)
|
||||
}
|
||||
if check.Name() == ipv6File {
|
||||
checkList = append(checkList, ipv6File)
|
||||
}
|
||||
}
|
||||
if diff := cmp.Diff(checkList, rt.expStr); diff != "" {
|
||||
t.Fatalf("unexpected file content check (-want,+got):\n%s", diff)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestJoinIPCheck(t *testing.T) {
|
||||
// skip this test, if OS in not Linux, since it will ONLY pass on Linux.
|
||||
if runtime.GOOS != "linux" {
|
||||
t.Skip("unsupported OS")
|
||||
}
|
||||
// should be a privileged user for the `join` command, otherwise just skip it.
|
||||
isPrivileged := IsPrivilegedUserCheck{}
|
||||
if _, err := isPrivileged.Check(); err != nil {
|
||||
t.Skip("not a privileged user")
|
||||
}
|
||||
internalcfg, err := configutil.DefaultedJoinConfiguration(&kubeadmapiv1.JoinConfiguration{
|
||||
Discovery: kubeadmapiv1.Discovery{
|
||||
BootstrapToken: &kubeadmapiv1.BootstrapTokenDiscovery{
|
||||
Token: configutil.PlaceholderToken.Token.String(),
|
||||
APIServerEndpoint: "kube-apiserver:6443",
|
||||
UnsafeSkipCAVerification: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected failure when defaulting JoinConfiguration: %v", err)
|
||||
}
|
||||
ipv4File := "FileContent--proc-sys-net-ipv4-ip_forward"
|
||||
ipv6File := "FileContent--proc-sys-net-ipv6-conf-default-forwarding"
|
||||
var tests = []struct {
|
||||
testName string
|
||||
endpoint string
|
||||
expStr []string
|
||||
}{
|
||||
{
|
||||
testName: "single stack ipv4",
|
||||
endpoint: "10.244.0.0:1234",
|
||||
expStr: []string{"FileContent--proc-sys-net-ipv4-ip_forward"},
|
||||
},
|
||||
{
|
||||
testName: "single stack ipv6",
|
||||
endpoint: "[fda9:d324:354d:0::]:1234",
|
||||
expStr: []string{"FileContent--proc-sys-net-ipv6-conf-default-forwarding"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, rt := range tests {
|
||||
t.Run(rt.testName, func(t *testing.T) {
|
||||
checkList := []string{}
|
||||
internalcfg.Discovery.BootstrapToken.APIServerEndpoint = rt.endpoint
|
||||
checks, err := JoinNodeChecks(exec.New(), internalcfg, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
for _, check := range checks {
|
||||
if check.Name() == ipv4File {
|
||||
checkList = append(checkList, ipv4File)
|
||||
}
|
||||
if check.Name() == ipv6File {
|
||||
checkList = append(checkList, ipv6File)
|
||||
}
|
||||
}
|
||||
if diff := cmp.Diff(checkList, rt.expStr); diff != "" {
|
||||
t.Fatalf("unexpected file content check (-want,+got):\n%s", diff)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user