mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 20:53:33 +00:00
Merge pull request #80947 from Nordix/kubeadm-ds-e2e-pod-network-cidr
kubeadm e2e networking test for dual-stack podSubnet check.
This commit is contained in:
commit
f96fcd095f
@ -49,7 +49,6 @@ var _ = KubeadmDescribe("networking [setup-networking]", func() {
|
|||||||
// We can determine this from the kubeadm config by looking at the number of
|
// We can determine this from the kubeadm config by looking at the number of
|
||||||
// IPs specified in networking.podSubnet
|
// IPs specified in networking.podSubnet
|
||||||
ginkgo.BeforeEach(func() {
|
ginkgo.BeforeEach(func() {
|
||||||
|
|
||||||
// gets the ClusterConfiguration from the kubeadm kubeadm-config ConfigMap as a untyped map
|
// gets the ClusterConfiguration from the kubeadm kubeadm-config ConfigMap as a untyped map
|
||||||
cc := getClusterConfiguration(f.ClientSet)
|
cc := getClusterConfiguration(f.ClientSet)
|
||||||
// Extract the networking.podSubnet
|
// Extract the networking.podSubnet
|
||||||
@ -88,7 +87,7 @@ var _ = KubeadmDescribe("networking [setup-networking]", func() {
|
|||||||
if ps, ok := netCC["podSubnet"]; ok {
|
if ps, ok := netCC["podSubnet"]; ok {
|
||||||
// Check that the pod CIDR allocated to the node(s) is within the kubeadm-config podCIDR.
|
// Check that the pod CIDR allocated to the node(s) is within the kubeadm-config podCIDR.
|
||||||
nodes, err := f.ClientSet.CoreV1().Nodes().List(metav1.ListOptions{})
|
nodes, err := f.ClientSet.CoreV1().Nodes().List(metav1.ListOptions{})
|
||||||
framework.ExpectNoError(err)
|
framework.ExpectNoError(err, "error listing nodes")
|
||||||
for _, node := range nodes.Items {
|
for _, node := range nodes.Items {
|
||||||
if !subnetWithinSubnet(ps.(string), node.Spec.PodCIDR) {
|
if !subnetWithinSubnet(ps.(string), node.Spec.PodCIDR) {
|
||||||
e2elog.Failf("failed due to node(%v) IP %v not inside configured pod subnet: %s", node.Name, node.Spec.PodCIDR, ps)
|
e2elog.Failf("failed due to node(%v) IP %v not inside configured pod subnet: %s", node.Name, node.Spec.PodCIDR, ps)
|
||||||
@ -113,7 +112,7 @@ var _ = KubeadmDescribe("networking [setup-networking]", func() {
|
|||||||
// Get the kubernetes service in the default namespace.
|
// Get the kubernetes service in the default namespace.
|
||||||
// Check that service CIDR allocated is within the serviceSubnet range.
|
// Check that service CIDR allocated is within the serviceSubnet range.
|
||||||
svc, err := f.ClientSet.CoreV1().Services("default").Get("kubernetes", metav1.GetOptions{})
|
svc, err := f.ClientSet.CoreV1().Services("default").Get("kubernetes", metav1.GetOptions{})
|
||||||
framework.ExpectNoError(err)
|
framework.ExpectNoError(err, "error getting Service %q from namespace %q", "kubernetes", "default")
|
||||||
if !ipWithinSubnet(ss.(string), svc.Spec.ClusterIP) {
|
if !ipWithinSubnet(ss.(string), svc.Spec.ClusterIP) {
|
||||||
e2elog.Failf("failed due to service(%v) cluster-IP %v not inside configured service subnet: %s", svc.Name, svc.Spec.ClusterIP, ss)
|
e2elog.Failf("failed due to service(%v) cluster-IP %v not inside configured service subnet: %s", svc.Name, svc.Spec.ClusterIP, ss)
|
||||||
}
|
}
|
||||||
@ -122,6 +121,43 @@ var _ = KubeadmDescribe("networking [setup-networking]", func() {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
ginkgo.Context("dual-stack [Feature:IPv6DualStack]", func() {
|
||||||
|
ginkgo.Context("podSubnet", func() {
|
||||||
|
ginkgo.It("should be properly configured if specified in kubeadm-config", func() {
|
||||||
|
if !dualStack {
|
||||||
|
framework.Skipf("Skipping because cluster is not dual-stack")
|
||||||
|
}
|
||||||
|
if !podSubnetInKubeadmConfig {
|
||||||
|
framework.Skipf("Skipping because podSubnet was not specified in kubeadm-config")
|
||||||
|
}
|
||||||
|
cc := getClusterConfiguration(f.ClientSet)
|
||||||
|
if _, ok := cc["networking"]; ok {
|
||||||
|
netCC := cc["networking"].(map[interface{}]interface{})
|
||||||
|
if ps, ok := netCC["podSubnet"]; ok {
|
||||||
|
nodes, err := f.ClientSet.CoreV1().Nodes().List(metav1.ListOptions{})
|
||||||
|
framework.ExpectNoError(err, "error listing nodes")
|
||||||
|
// Check that the pod CIDRs allocated to the node(s) are within the kubeadm-config podCIDR.
|
||||||
|
var found bool
|
||||||
|
configCIDRs := strings.Split(ps.(string), ",")
|
||||||
|
for _, node := range nodes.Items {
|
||||||
|
for _, nCIDR := range node.Spec.PodCIDRs {
|
||||||
|
found = false
|
||||||
|
for _, cCIDR := range configCIDRs {
|
||||||
|
if subnetWithinSubnet(cCIDR, nCIDR) {
|
||||||
|
found = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !found {
|
||||||
|
e2elog.Failf("failed due to the PodCIDRs (%v) of Node %q not being inside the configuration podSubnet CIDR %q", node.Spec.PodCIDRs, node.Name, configCIDRs)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
// ipWithinSubnet returns true if an IP (targetIP) falls within the reference subnet (refIPNet)
|
// ipWithinSubnet returns true if an IP (targetIP) falls within the reference subnet (refIPNet)
|
||||||
|
Loading…
Reference in New Issue
Block a user