test/e2e: add kubelet test for hostAliases with hostNetwork=true

Support for this was added in 1.8 by PR 50646 but there
is no e2e test.
This commit is contained in:
Lubomir I. Ivanov 2023-12-20 21:15:36 +02:00
parent 38f4f9d8c4
commit bc83cea0eb

View File

@ -214,3 +214,48 @@ var _ = SIGDescribe("Kubelet", func() {
})
})
})
var _ = SIGDescribe("Kubelet with pods in a privileged namespace", func() {
f := framework.NewDefaultFramework("kubelet-test")
f.NamespacePodSecurityLevel = admissionapi.LevelPrivileged
var podClient *e2epod.PodClient
ginkgo.BeforeEach(func() {
podClient = e2epod.NewPodClient(f)
})
ginkgo.Context("when scheduling an agnhost Pod with hostAliases and hostNetwork", func() {
podName := "agnhost-host-aliases" + string(uuid.NewUUID())
/*
Release: v1.30
Testname: Kubelet, hostAliases, hostNetwork
Description: Create a Pod with hostNetwork enabled, hostAliases and a container with command to output /etc/hosts entries. Pod's logs MUST have matching entries of specified hostAliases to the output of /etc/hosts entries.
*/
framework.It("should write entries to /etc/hosts when hostNetwork is enabled", f.WithNodeConformance(), func(ctx context.Context) {
pod := e2epod.NewAgnhostPod(f.Namespace.Name, podName, nil, nil, nil, "etc-hosts")
pod.Spec.HostNetwork = true
// Don't restart the Pod since it is expected to exit
pod.Spec.RestartPolicy = v1.RestartPolicyNever
pod.Spec.HostAliases = []v1.HostAlias{
{
IP: "123.45.67.89",
Hostnames: []string{"foo", "bar"},
},
}
pod = podClient.Create(ctx, pod)
ginkgo.By("Waiting for pod completion")
err := e2epod.WaitForPodNoLongerRunningInNamespace(ctx, f.ClientSet, pod.Name, f.Namespace.Name)
framework.ExpectNoError(err)
rc, err := podClient.GetLogs(podName, &v1.PodLogOptions{}).Stream(ctx)
framework.ExpectNoError(err)
defer rc.Close() // nolint:errcheck
buf := new(bytes.Buffer)
_, err = buf.ReadFrom(rc)
framework.ExpectNoError(err)
hostsFileContent := buf.String()
errMsg := fmt.Sprintf("expected hosts file to contain entries from HostAliases. Got:\n%+v", hostsFileContent)
gomega.Expect(hostsFileContent).To(gomega.ContainSubstring("123.45.67.89\tfoo\tbar"), errMsg)
})
})
})