Merge pull request #124421 from danwinship/pod-host-ips-test

Fix up pod hostIPs e2e
This commit is contained in:
Kubernetes Prow Robot 2024-04-21 20:09:33 -07:00 committed by GitHub
commit c1924df0a8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 34 additions and 42 deletions

View File

@ -241,9 +241,6 @@ var (
// TODO: document the feature (owning SIG, when to use this feature for a test)
PodGarbageCollector = framework.WithFeature(framework.ValidFeatures.Add("PodGarbageCollector"))
// TODO: document the feature (owning SIG, when to use this feature for a test)
PodHostIPs = framework.WithFeature(framework.ValidFeatures.Add("PodHostIPs"))
// TODO: document the feature (owning SIG, when to use this feature for a test)
PodLifecycleSleepAction = framework.WithFeature(framework.ValidFeatures.Add("PodLifecycleSleepAction"))

View File

@ -85,9 +85,6 @@ var (
// TODO: document the feature (owning SIG, when to use this feature for a test)
PodDisruptionConditions = framework.WithNodeFeature(framework.ValidNodeFeatures.Add("PodDisruptionConditions"))
// TODO: document the feature (owning SIG, when to use this feature for a test)
PodHostIPs = framework.WithNodeFeature(framework.ValidNodeFeatures.Add("PodHostIPs"))
// TODO: document the feature (owning SIG, when to use this feature for a test)
PodResources = framework.WithNodeFeature(framework.ValidNodeFeatures.Add("PodResources"))

View File

@ -31,7 +31,7 @@ import (
utilfeature "k8s.io/apiserver/pkg/util/feature"
kubefeatures "k8s.io/kubernetes/pkg/features"
"k8s.io/kubernetes/test/e2e/feature"
utilnode "k8s.io/kubernetes/pkg/util/node"
"k8s.io/kubernetes/test/e2e/framework"
e2enetwork "k8s.io/kubernetes/test/e2e/framework/network"
e2enode "k8s.io/kubernetes/test/e2e/framework/node"
@ -39,18 +39,16 @@ import (
e2epodoutput "k8s.io/kubernetes/test/e2e/framework/pod/output"
e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper"
"k8s.io/kubernetes/test/e2e/network/common"
"k8s.io/kubernetes/test/e2e/nodefeature"
imageutils "k8s.io/kubernetes/test/utils/image"
admissionapi "k8s.io/pod-security-admission/api"
)
var _ = common.SIGDescribe("DualStack Host IP", framework.WithSerial(), nodefeature.PodHostIPs, feature.PodHostIPs, func() {
f := framework.NewDefaultFramework("dualstack")
var _ = common.SIGDescribe("Pod Host IPs", framework.WithSerial(), func() {
f := framework.NewDefaultFramework("host-ips")
f.NamespacePodSecurityLevel = admissionapi.LevelPrivileged
ginkgo.Context("when creating a Pod", func() {
ginkgo.It("should create pod, add ipv6 and ipv4 ip to host ips", func(ctx context.Context) {
ginkgo.It("should add node IPs of all supported families to hostIPs of pod-network pod", func(ctx context.Context) {
podName := "pod-dualstack-host-ips"
pod := genPodHostIPs(podName+string(uuid.NewUUID()), false)
@ -71,28 +69,17 @@ var _ = common.SIGDescribe("DualStack Host IP", framework.WithSerial(), nodefeat
}
}
nodeList, err := e2enode.GetReadySchedulableNodes(ctx, f.ClientSet)
framework.ExpectNoError(err)
for _, node := range nodeList.Items {
if node.Name == p.Spec.NodeName {
nodeIPs := []v1.HostIP{}
for _, address := range node.Status.Addresses {
if address.Type == v1.NodeInternalIP {
nodeIPs = append(nodeIPs, v1.HostIP{IP: address.Address})
}
}
gomega.Expect(p.Status.HostIPs).Should(gomega.Equal(nodeIPs))
break
}
}
ginkgo.By("comparing pod.Status.HostIPs against node.Status.Addresses")
hostIPs, err := genHostIPsForNode(ctx, f, p.Spec.NodeName)
framework.ExpectNoError(err, "failed to fetch node IPs")
gomega.Expect(p.Status.HostIPs).Should(gomega.Equal(hostIPs))
ginkgo.By("deleting the pod")
err = podClient.Delete(ctx, pod.Name, *metav1.NewDeleteOptions(1))
framework.ExpectNoError(err, "failed to delete pod")
})
ginkgo.It("should create pod with hostNetwork, add ipv6 and ipv4 ip to host ips", func(ctx context.Context) {
ginkgo.It("should add node IPs of all supported families to hostIPs of host-network pod", func(ctx context.Context) {
podName := "pod-dualstack-host-ips"
pod := genPodHostIPs(podName+string(uuid.NewUUID()), true)
@ -113,20 +100,10 @@ var _ = common.SIGDescribe("DualStack Host IP", framework.WithSerial(), nodefeat
}
}
nodeList, err := e2enode.GetReadySchedulableNodes(ctx, f.ClientSet)
framework.ExpectNoError(err)
for _, node := range nodeList.Items {
if node.Name == p.Spec.NodeName {
nodeIPs := []v1.HostIP{}
for _, address := range node.Status.Addresses {
if address.Type == v1.NodeInternalIP {
nodeIPs = append(nodeIPs, v1.HostIP{IP: address.Address})
}
}
gomega.Expect(p.Status.HostIPs).Should(gomega.Equal(nodeIPs))
break
}
}
ginkgo.By("comparing pod.Status.HostIPs against node.Status.Addresses")
hostIPs, err := genHostIPsForNode(ctx, f, p.Spec.NodeName)
framework.ExpectNoError(err, "failed to fetch node IPs")
gomega.Expect(p.Status.HostIPs).Should(gomega.Equal(hostIPs))
ginkgo.By("deleting the pod")
err = podClient.Delete(ctx, pod.Name, *metav1.NewDeleteOptions(1))
@ -179,6 +156,27 @@ func genPodHostIPs(podName string, hostNetwork bool) *v1.Pod {
}
}
func genHostIPsForNode(ctx context.Context, f *framework.Framework, nodeName string) ([]v1.HostIP, error) {
nodeList, err := e2enode.GetReadySchedulableNodes(ctx, f.ClientSet)
if err != nil {
return nil, err
}
for _, node := range nodeList.Items {
if node.Name == nodeName {
nodeIPs, err := utilnode.GetNodeHostIPs(&node)
if err != nil {
return nil, err
}
hostIPs := []v1.HostIP{}
for _, ip := range nodeIPs {
hostIPs = append(hostIPs, v1.HostIP{IP: ip.String()})
}
return hostIPs, nil
}
}
return nil, fmt.Errorf("no such node %q", nodeName)
}
func testDownwardAPI(ctx context.Context, f *framework.Framework, podName string, env []v1.EnvVar, expectations []string) {
pod := &v1.Pod{
ObjectMeta: metav1.ObjectMeta{