Change:
What happened: We've been doing some release readiness and auditing all tagged ginkgo tests... Looks like The test seems to expect a GOPATH when running. Im seeing some failures in sonobuoy and suspect a possible relation there but havent dove into it. Either way, its clear this test might need some updating/fixing/cleanuping and parts can be rewritten/improved. What you expected to happen: No reliance on GOPATH for an e2e test ... I dont remember the whole history on this, but no tests that rely on static files currently look in gopath, from what i can tell ? instead we plumbed in a repo-root/ option a few years ago. There may be a state of the art in terms of how we do this.... but i thought it was at one point which was an option passed in. How to reproduce it (as minimally and precisely as possible): Try to run this in sonobuoy or any other environment where there's no GOPATH or non-standard source trees, pretty sure it might not work. Anything else we need to know?: I think the fix here is to just embed the YAML in golang like we do in other tests. along the way there's other cleanup we can do to improve this test. Environment: Kubernetes version (use ): master
/sig network
/assign
/triage unresolved Comment when the issue is assessed and confirmed. I am a bot run by vllry. ‍
the YAML files are pretty small, so +1 to embed them in i don't think testing the YAML from the separate repository () directly is required here. ref /help /kind cleanup /priority backlog
/remove-help
/assign Also I should say, I talked to Jay on slack and he is ok with me taking a look at it, if thats ok.
If this issue has been triaged, please comment . If you aren't able to handle this issue, consider unassigning yourself and/or adding the label. I am a bot run by vllry. ‍
Issues go stale after 90d of inactivity. Mark the issue as fresh with . Stale issues rot after an additional 30d of inactivity and eventually close. If this issue is safe to close now please do so with . Send feedback to sig-contributor-experience at . /lifecycle stale
/remove-lifecycle stale
xref: go 1.16 has built in support for embedding go 1.17 looks to be removing GOPATH
Issues go stale after 90d of inactivity. Mark the issue as fresh with . Stale issues rot after an additional 30d of inactivity and eventually close. If this issue is safe to close now please do so with . Send feedback to sig-contributor-experience at . /lifecycle stale
/remove-lifecycle stale
The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules: After 90d of inactivity, is applied After 30d of inactivity since was applied, is applied After 30d of inactivity since was applied, the issue is closed You can: Mark this issue or PR as fresh with Mark this issue or PR as rotten with Close this issue or PR with Offer to help out with [Issue Triage][1] Please send feedback to sig-contributor-experience at . /lifecycle stale [1]:
/help wanted
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules: After 90d of inactivity, is applied After 30d of inactivity since was applied, is applied After 30d of inactivity since was applied, the issue is closed You can: Mark this issue or PR as fresh with Close this issue or PR with Offer to help out with [Issue Triage][1] Please send feedback to sig-contributor-experience at . /lifecycle rotten [1]:
/remove-lifecycle rotten still a problem. FYI re: GOPATH removal
The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules: After 90d of inactivity, is applied After 30d of inactivity since was applied, is applied After 30d of inactivity since was applied, the issue is closed You can: Mark this issue or PR as fresh with Mark this issue or PR as rotten with Close this issue or PR with Offer to help out with [Issue Triage][1] Please send feedback to sig-contributor-experience at . /lifecycle stale [1]:
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules: After 90d of inactivity, is applied After 30d of inactivity since was applied, is applied After 30d of inactivity since was applied, the issue is closed You can: Mark this issue or PR as fresh with Close this issue or PR with Offer to help out with [Issue Triage][1] Please send feedback to sig-contributor-experience at . /lifecycle rotten [1]:
/assign

Discussion:
import ( "context" "fmt" <del> "io" "os" </del> "path/filepath" "strings" "time"

e2epod "k8s.io/kubernetes/test/e2e/framework/pod" e2eresource "k8s.io/kubernetes/test/e2e/framework/resource" e2eservice "k8s.io/kubernetes/test/e2e/framework/service" <ins> e2etestfiles "k8s.io/kubernetes/test/e2e/framework/testfiles" </ins> "k8s.io/kubernetes/test/e2e/network/common" )

c = f.ClientSet }) <del> ginkgo.It("should create pod that uses dns", func() { mkpath := func(file string) string { return filepath.Join(os.Getenv("GOPATH"), "src/k8s.io/examples/staging/cluster-dns", file) </del> <ins> read := func(file string) string { data, err := e2etestfiles.Read(file) if err != nil { framework.Fail(err.Error()) </ins> } <ins> return string(data) } ginkgo.It("should create pod that uses dns", func() { </ins> // contrary to the example, this test does not use contexts, for simplicity // namespaces are passed directly. // Also, for simplicity, we don't use yamls with namespaces, but we // create testing namespaces instead. <del> backendRcYaml := mkpath("dns-backend-rc.yaml") backendRcName := "dns-backend" backendSvcYaml := mkpath("dns-backend-service.yaml") backendSvcName := "dns-backend" backendPodName := "dns-backend" frontendPodYaml := mkpath("dns-frontend-pod.yaml") frontendPodName := "dns-frontend" frontendPodContainerName := "dns-frontend" </del> <ins> backendName := "dns-backend" frontendName := "dns-frontend" clusterDnsPath := "test/e2e/testing-manifests/cluster-dns" </ins> podOutput := "Hello World!" // we need two namespaces anyway, so let's forget about

} for _, ns := range namespaces { <del> framework.RunKubectlOrDie(ns.Name, "create", "-f", backendRcYaml, getNsCmdFlag(ns)) </del> <ins> framework.RunKubectlOrDieInput(ns.Name, read(filepath.Join(clusterDnsPath, "dns-backend-rc.yaml")), "create", "-f", "-") </ins> } for _, ns := range namespaces { <del> framework.RunKubectlOrDie(ns.Name, "create", "-f", backendSvcYaml, getNsCmdFlag(ns)) </del> <ins> framework.RunKubectlOrDieInput(ns.Name, read(filepath.Join(clusterDnsPath, "dns-backend-service.yaml")), "create", "-f", "-") </ins> } // wait for objects for _, ns := range namespaces { <del> e2eresource.WaitForControlledPodsRunning(c, ns.Name, backendRcName, api.Kind("ReplicationController")) e2enetwork.WaitForService(c, ns.Name, backendSvcName, true, framework.Poll, framework.ServiceStartTimeout) </del> <ins> e2eresource.WaitForControlledPodsRunning(c, ns.Name, backendName, api.Kind("ReplicationController")) e2enetwork.WaitForService(c, ns.Name, backendName, true, framework.Poll, framework.ServiceStartTimeout) </ins> } // it is not enough that pods are running because they may be set to running, but // the application itself may have not been initialized. Just query the application. for _, ns := range namespaces { <del> label := labels.SelectorFromSet(labels.Set(map[string]string{"name": backendRcName})) </del> <ins> label := labels.SelectorFromSet(labels.Set(map[string]string{"name": backendName})) </ins> options := metav1.ListOptions{LabelSelector: label.String()} pods, err := c.CoreV1().Pods(ns.Name).List(context.TODO(), options) framework.ExpectNoError(err, "failed to list pods in namespace: %s", ns.Name) <del> err = e2epod.PodsResponding(c, ns.Name, backendPodName, false, pods) </del> <ins> err = e2epod.PodsResponding(c, ns.Name, backendName, false, pods) </ins> framework.ExpectNoError(err, "waiting for all pods to respond") framework.Logf("found %d backend pods responding in namespace %s", len(pods.Items), ns.Name) <del> err = waitForServiceResponding(c, ns.Name, backendSvcName) </del> <ins> err = waitForServiceResponding(c, ns.Name, backendName) </ins> framework.ExpectNoError(err, "waiting for the service to respond") }

// This complicated code may be removed if the pod itself retried after // dns error or timeout. // This code is probably unnecessary, but let's stay on the safe side. <del> label := labels.SelectorFromSet(labels.Set(map[string]string{"name": backendPodName})) </del> <ins> label := labels.SelectorFromSet(labels.Set(map[string]string{"name": backendName})) </ins> options := metav1.ListOptions{LabelSelector: label.String()} pods, err := c.CoreV1().Pods(namespaces[0].Name).List(context.TODO(), options)

} podName := pods.Items[0].Name <del> queryDNS := fmt.Sprintf(queryDNSPythonTemplate, backendSvcName+"."+namespaces[0].Name) </del> <ins> queryDNS := fmt.Sprintf(queryDNSPythonTemplate, backendName+"."+namespaces[0].Name) </ins> _, err = framework.LookForStringInPodExec(namespaces[0].Name, podName, []string{"python", "-c", queryDNS}, "ok", dnsReadyTimeout) framework.ExpectNoError(err, "waiting for output from pod exec") <del> updatedPodYaml := prepareResourceWithReplacedString(frontendPodYaml, fmt.Sprintf("dns-backend.development.svc.%s", framework.TestContext.ClusterDNSDomain), fmt.Sprintf("dns-backend.%s.svc.%s", namespaces[0].Name, framework.TestContext.ClusterDNSDomain)) </del> <ins> updatedPodYaml := strings.Replace(read(filepath.Join(clusterDnsPath, "dns-frontend-pod.yaml")), fmt.Sprintf("dns-backend.development.svc.%s", framework.TestContext.ClusterDNSDomain), fmt.Sprintf("dns-backend.%s.svc.%s", namespaces[0].Name, framework.TestContext.ClusterDNSDomain), 1) </ins> // create a pod in each namespace for _, ns := range namespaces { <del> framework.NewKubectlCommand(ns.Name, "create", "-f", "-", getNsCmdFlag(ns)).WithStdinData(updatedPodYaml).ExecOrDie(ns.Name) </del> <ins> framework.RunKubectlOrDieInput(ns.Name, updatedPodYaml, "create", "-f", "-") </ins> } // wait until the pods have been scheduler, i.e. are not Pending anymore. Remember // that we cannot wait for the pods to be running because our pods terminate by themselves. for _, ns := range namespaces { <del> err := e2epod.WaitForPodNotPending(c, ns.Name, frontendPodName) </del> <ins> err := e2epod.WaitForPodNotPending(c, ns.Name, frontendName) </ins> framework.ExpectNoError(err) } // wait for pods to print their result for _, ns := range namespaces { <del> _, err := framework.LookForStringInLog(ns.Name, frontendPodName, frontendPodContainerName, podOutput, framework.PodStartTimeout) framework.ExpectNoError(err, "pod %s failed to print result in logs", frontendPodName) </del> <ins> _, err := framework.LookForStringInLog(ns.Name, frontendName, frontendName, podOutput, framework.PodStartTimeout) framework.ExpectNoError(err, "pod %s failed to print result in logs", frontendName) </ins> } }) }) <del> func getNsCmdFlag(ns *v1.Namespace) string { return fmt.Sprintf("--namespace=%v", ns.Name) } // pass enough context with the 'old' parameter so that it replaces what your really intended. func prepareResourceWithReplacedString(inputFile, old, new string) string { f, err := os.Open(inputFile) framework.ExpectNoError(err, "failed to open file: %s", inputFile) defer f.Close() data, err := io.ReadAll(f) framework.ExpectNoError(err, "failed to read from file: %s", inputFile) podYaml := strings.Replace(string(data), old, new, 1) return podYaml } </del> // waitForServiceResponding waits for the service to be responding. func waitForServiceResponding(c clientset.Interface, ns, name string) error { ginkgo.By(fmt.Sprintf("trying to dial the service %s.%s via the proxy", ns, name))

<ins> apiVersion: v1 kind: ReplicationController metadata: name: dns-backend labels: name: dns-backend spec: replicas: 1 selector: name: dns-backend template: metadata: labels: name: dns-backend spec: containers: - name: dns-backend image: k8s.gcr.io/example-dns-backend:v1 ports: - name: backend-port containerPort: 8000 </ins>

<ins> kind: Service apiVersion: v1 metadata: name: dns-backend spec: ports: - port: 8000 selector: name: dns-backend </ins>

<ins> apiVersion: v1 kind: Pod metadata: name: dns-frontend labels: name: dns-frontend spec: containers: - name: dns-frontend image: k8s.gcr.io/example-dns-frontend:v1 command: - python - client.py - http://dns-backend.development.svc.cluster.local:8000 imagePullPolicy: Always restartPolicy: Never </ins>

e2etestfiles "k8s.io/kubernetes/test/e2e/framework/testfiles" ) <del> //go:embed flexvolume guestbook kubectl sample-device-plugin.yaml scheduling/nvidia-driver-installer.yaml statefulset storage-csi </del> <ins> //go:embed cluster-dns flexvolume guestbook kubectl sample-device-plugin.yaml scheduling/nvidia-driver-installer.yaml statefulset storage-csi </ins> var e2eTestingManifestsFS embed.FS func GetE2ETestingManifestsFS() e2etestfiles.EmbeddedFileSource {