e2e: accept context from Ginkgo

Every ginkgo callback should return immediately when a timeout occurs or the
test run manually gets aborted with CTRL-C. To do that, they must take a ctx
parameter and pass it through to all code which might block.

This is a first automated step towards that: the additional parameter got added
with

    sed -i 's/\(framework.ConformanceIt\|ginkgo.It\)\(.*\)func() {$/\1\2func(ctx context.Context) {/' \
        $(git grep -l -e framework.ConformanceIt -e ginkgo.It )
    $GOPATH/bin/goimports -w $(git status | grep modified: | sed -e 's/.* //')

log_test.go was left unchanged.
This commit is contained in:
Patrick Ohly
2022-10-17 14:47:15 +02:00
parent 63ff4a2659
commit df5d84ae81
291 changed files with 1542 additions and 1454 deletions

View File

@@ -42,7 +42,7 @@ var _ = SIGDescribe("[Feature:Windows] Cpu Resources [Serial]", func() {
powershellImage := imageutils.GetConfig(imageutils.BusyBox)
ginkgo.Context("Container limits", func() {
ginkgo.It("should not be exceeded after waiting 2 minutes", func() {
ginkgo.It("should not be exceeded after waiting 2 minutes", func(ctx context.Context) {
ginkgo.By("Creating one pod with limit set to '0.5'")
podsDecimal := newCPUBurnPods(1, powershellImage, "0.5", "1Gi")
e2epod.NewPodClient(f).CreateBatch(podsDecimal)

View File

@@ -65,7 +65,7 @@ var _ = SIGDescribe("[Feature:Windows] Density [Serial] [Slow]", func() {
for _, testArg := range dTests {
itArg := testArg
desc := fmt.Sprintf("latency/resource should be within limit when create %d pods with %v interval", itArg.podsNr, itArg.interval)
ginkgo.It(desc, func() {
ginkgo.It(desc, func(ctx context.Context) {
itArg.createMethod = "batch"
runDensityBatchTest(f, itArg)
})

View File

@@ -50,7 +50,7 @@ var _ = SIGDescribe("[Feature:GPUDevicePlugin] Device Plugin", func() {
e2eskipper.SkipUnlessNodeOSDistroIs("windows")
cs = f.ClientSet
})
ginkgo.It("should be able to create a functioning device plugin for Windows", func() {
ginkgo.It("should be able to create a functioning device plugin for Windows", func(ctx context.Context) {
ginkgo.By("creating Windows device plugin daemonset")
dsName := "directx-device-plugin"
daemonsetNameLabel := "daemonset-name"

View File

@@ -38,7 +38,7 @@ var _ = SIGDescribe("[Feature:Windows] DNS", func() {
f := framework.NewDefaultFramework("dns")
f.NamespacePodSecurityEnforceLevel = admissionapi.LevelPrivileged
ginkgo.It("should support configurable pod DNS servers", func() {
ginkgo.It("should support configurable pod DNS servers", func(ctx context.Context) {
ginkgo.By("Getting the IP address of the internal Kubernetes service")

View File

@@ -95,7 +95,7 @@ var _ = SIGDescribe("[Feature:Windows] GMSA Full [Serial] [Slow]", func() {
f.NamespacePodSecurityEnforceLevel = admissionapi.LevelPrivileged
ginkgo.Describe("GMSA support", func() {
ginkgo.It("works end to end", func() {
ginkgo.It("works end to end", func(ctx context.Context) {
defer ginkgo.GinkgoRecover()
ginkgo.By("finding the worker node that fulfills this test's assumptions")
@@ -165,7 +165,7 @@ var _ = SIGDescribe("[Feature:Windows] GMSA Full [Serial] [Slow]", func() {
}, 1*time.Minute, 1*time.Second).Should(gomega.BeTrue())
})
ginkgo.It("can read and write file to remote SMB folder", func() {
ginkgo.It("can read and write file to remote SMB folder", func(ctx context.Context) {
defer ginkgo.GinkgoRecover()
ginkgo.By("finding the worker node that fulfills this test's assumptions")

View File

@@ -22,6 +22,7 @@ limitations under the License.
package windows
import (
"context"
"fmt"
"strings"
"time"
@@ -44,7 +45,7 @@ var _ = SIGDescribe("[Feature:Windows] GMSA Kubelet [Slow]", func() {
ginkgo.Describe("kubelet GMSA support", func() {
ginkgo.Context("when creating a pod with correct GMSA credential specs", func() {
ginkgo.It("passes the credential specs down to the Pod's containers", func() {
ginkgo.It("passes the credential specs down to the Pod's containers", func(ctx context.Context) {
defer ginkgo.GinkgoRecover()
podName := "with-correct-gmsa-specs"

View File

@@ -89,7 +89,7 @@ var _ = SIGDescribe("[Feature:WindowsHostProcessContainers] [MinimumKubeletVersi
f := framework.NewDefaultFramework("host-process-test-windows")
f.NamespacePodSecurityEnforceLevel = admissionapi.LevelPrivileged
ginkgo.It("should run as a process on the host/node", func() {
ginkgo.It("should run as a process on the host/node", func(ctx context.Context) {
ginkgo.By("selecting a Windows node")
targetNode, err := findWindowsNode(f)
@@ -138,7 +138,7 @@ var _ = SIGDescribe("[Feature:WindowsHostProcessContainers] [MinimumKubeletVersi
framework.ExpectEqual(p.Status.Phase, v1.PodSucceeded)
})
ginkgo.It("should support init containers", func() {
ginkgo.It("should support init containers", func(ctx context.Context) {
ginkgo.By("scheduling a pod with a container that verifies init container can configure the node")
podName := "host-process-init-pods"
filename := fmt.Sprintf("/testfile%s.txt", string(uuid.NewUUID()))
@@ -198,7 +198,7 @@ var _ = SIGDescribe("[Feature:WindowsHostProcessContainers] [MinimumKubeletVersi
framework.ExpectEqual(p.Status.Phase, v1.PodSucceeded)
})
ginkgo.It("container command path validation", func() {
ginkgo.It("container command path validation", func(ctx context.Context) {
// The way hostprocess containers are created is being updated in container
// v1.7 to better support volume mounts and part of these changes include
@@ -446,7 +446,7 @@ var _ = SIGDescribe("[Feature:WindowsHostProcessContainers] [MinimumKubeletVersi
})
ginkgo.It("should support various volume mount types", func() {
ginkgo.It("should support various volume mount types", func(ctx context.Context) {
ns := f.Namespace
ginkgo.By("Creating a configmap containing test data and a validation script")
@@ -507,7 +507,7 @@ var _ = SIGDescribe("[Feature:WindowsHostProcessContainers] [MinimumKubeletVersi
framework.ExpectEqual(p.Status.Phase, v1.PodSucceeded)
})
ginkgo.It("metrics should report count of started and failed to start HostProcess containers", func() {
ginkgo.It("metrics should report count of started and failed to start HostProcess containers", func(ctx context.Context) {
ginkgo.By("Selecting a Windows node")
targetNode, err := findWindowsNode(f)
framework.ExpectNoError(err, "Error finding Windows node")
@@ -613,7 +613,7 @@ var _ = SIGDescribe("[Feature:WindowsHostProcessContainers] [MinimumKubeletVersi
gomega.Expect(beforeMetrics.StartedInitContainersErrorCount).To(gomega.BeNumerically("<", afterMetrics.StartedInitContainersErrorCount), "Count of started HostProcess errors init containers should increase")
})
ginkgo.It("container stats validation", func() {
ginkgo.It("container stats validation", func(ctx context.Context) {
ginkgo.By("selecting a Windows node")
targetNode, err := findWindowsNode(f)
framework.ExpectNoError(err, "Error finding Windows node")
@@ -692,7 +692,7 @@ var _ = SIGDescribe("[Feature:WindowsHostProcessContainers] [MinimumKubeletVersi
}
})
ginkgo.It("should support querying api-server using in-cluster config", func() {
ginkgo.It("should support querying api-server using in-cluster config", func(ctx context.Context) {
// This functionality is only support on containerd v1.7+
ginkgo.By("Ensuring Windows nodes are running containerd v1.7+")
windowsNode, err := findWindowsNode(f)
@@ -771,7 +771,7 @@ var _ = SIGDescribe("[Feature:WindowsHostProcessContainers] [MinimumKubeletVersi
"app logs should not contain 'status=failed")
})
ginkgo.It("should run as localgroup accounts", func() {
ginkgo.It("should run as localgroup accounts", func(ctx context.Context) {
// This functionality is only supported on containerd v1.7+
ginkgo.By("Ensuring Windows nodes are running containerd v1.7+")
windowsNode, err := findWindowsNode(f)

View File

@@ -17,6 +17,7 @@ limitations under the License.
package windows
import (
"context"
"fmt"
v1 "k8s.io/api/core/v1"
@@ -53,7 +54,7 @@ var _ = SIGDescribe("Hybrid cluster network", func() {
ginkgo.Context("for all supported CNIs", func() {
ginkgo.It("should have stable networking for Linux and Windows pods", func() {
ginkgo.It("should have stable networking for Linux and Windows pods", func(ctx context.Context) {
linuxPod := createTestPod(f, linuxBusyBoxImage, linuxOS)
ginkgo.By("creating a linux pod and waiting for it to be running")
@@ -75,7 +76,7 @@ var _ = SIGDescribe("Hybrid cluster network", func() {
})
ginkgo.It("should provide Internet connection for Linux containers using DNS [Feature:Networking-DNS]", func() {
ginkgo.It("should provide Internet connection for Linux containers using DNS [Feature:Networking-DNS]", func(ctx context.Context) {
linuxPod := createTestPod(f, linuxBusyBoxImage, linuxOS)
ginkgo.By("creating a linux pod and waiting for it to be running")
linuxPod = e2epod.NewPodClient(f).CreateSync(linuxPod)
@@ -86,7 +87,7 @@ var _ = SIGDescribe("Hybrid cluster network", func() {
assertConsistentConnectivity(f, linuxPod.ObjectMeta.Name, linuxOS, linuxCheck("8.8.8.8", 53))
})
ginkgo.It("should provide Internet connection for Windows containers using DNS [Feature:Networking-DNS]", func() {
ginkgo.It("should provide Internet connection for Windows containers using DNS [Feature:Networking-DNS]", func(ctx context.Context) {
windowsPod := createTestPod(f, windowsBusyBoximage, windowsOS)
ginkgo.By("creating a windows pod and waiting for it to be running")
windowsPod = e2epod.NewPodClient(f).CreateSync(windowsPod)

View File

@@ -44,7 +44,7 @@ var _ = SIGDescribe("[Feature:Windows] Kubelet-Stats [Serial]", func() {
ginkgo.Context("when running 10 pods", func() {
// 10 seconds is the default scrape timeout for metrics-server and kube-prometheus
ginkgo.It("should return within 10 seconds", func() {
ginkgo.It("should return within 10 seconds", func(ctx context.Context) {
ginkgo.By("Selecting a Windows node")
targetNode, err := findWindowsNode(f)
@@ -119,7 +119,7 @@ var _ = SIGDescribe("[Feature:Windows] Kubelet-Stats", func() {
ginkgo.Describe("Kubelet stats collection for Windows nodes", func() {
ginkgo.Context("when windows is booted", func() {
ginkgo.It("should return bootid within 10 seconds", func() {
ginkgo.It("should return bootid within 10 seconds", func(ctx context.Context) {
ginkgo.By("Selecting a Windows node")
targetNode, err := findWindowsNode(f)
framework.ExpectNoError(err, "Error finding Windows node")
@@ -134,7 +134,7 @@ var _ = SIGDescribe("[Feature:Windows] Kubelet-Stats", func() {
ginkgo.Context("when running 3 pods", func() {
// 10 seconds is the default scrape timeout for metrics-server and kube-prometheus
ginkgo.It("should return within 10 seconds", func() {
ginkgo.It("should return within 10 seconds", func(ctx context.Context) {
ginkgo.By("Selecting a Windows node")
targetNode, err := findWindowsNode(f)

View File

@@ -51,13 +51,13 @@ var _ = SIGDescribe("[Feature:Windows] Memory Limits [Serial] [Slow]", func() {
})
ginkgo.Context("Allocatable node memory", func() {
ginkgo.It("should be equal to a calculated allocatable memory value", func() {
ginkgo.It("should be equal to a calculated allocatable memory value", func(ctx context.Context) {
checkNodeAllocatableTest(f)
})
})
ginkgo.Context("attempt to deploy past allocatable memory limits", func() {
ginkgo.It("should fail deployments of pods once there isn't enough memory", func() {
ginkgo.It("should fail deployments of pods once there isn't enough memory", func(ctx context.Context) {
overrideAllocatableMemoryTest(f, framework.TestContext.CloudConfig.NumNodes)
})
})

View File

@@ -41,7 +41,7 @@ var _ = SIGDescribe("[Feature:Windows] [Excluded:WindowsDocker] [MinimumKubeletV
f := framework.NewDefaultFramework("reboot-host-test-windows")
f.NamespacePodSecurityEnforceLevel = admissionapi.LevelPrivileged
ginkgo.It("should run as a reboot process on the host/node", func() {
ginkgo.It("should run as a reboot process on the host/node", func(ctx context.Context) {
ginkgo.By("selecting a Windows node")
targetNode, err := findWindowsNode(f)

View File

@@ -44,7 +44,7 @@ var _ = SIGDescribe("[Feature:Windows] SecurityContext", func() {
f := framework.NewDefaultFramework("windows-run-as-username")
f.NamespacePodSecurityEnforceLevel = admissionapi.LevelPrivileged
ginkgo.It("should be able create pods and run containers with a given username", func() {
ginkgo.It("should be able create pods and run containers with a given username", func(ctx context.Context) {
ginkgo.By("Creating 2 pods: 1 with the default user, and one with a custom one.")
podDefault := runAsUserNamePod(nil)
e2eoutput.TestContainerOutput(f, "check default user", podDefault, 0, []string{"ContainerUser"})
@@ -53,7 +53,7 @@ var _ = SIGDescribe("[Feature:Windows] SecurityContext", func() {
e2eoutput.TestContainerOutput(f, "check set user", podUserName, 0, []string{"ContainerAdministrator"})
})
ginkgo.It("should not be able to create pods with unknown usernames at Pod level", func() {
ginkgo.It("should not be able to create pods with unknown usernames at Pod level", func(ctx context.Context) {
ginkgo.By("Creating a pod with an invalid username")
podInvalid := e2epod.NewPodClient(f).Create(runAsUserNamePod(toPtr("FooLish")))
@@ -100,7 +100,7 @@ var _ = SIGDescribe("[Feature:Windows] SecurityContext", func() {
}, framework.PodStartTimeout, 1*time.Second).Should(gomega.BeTrue())
})
ginkgo.It("should not be able to create pods with unknown usernames at Container level", func() {
ginkgo.It("should not be able to create pods with unknown usernames at Container level", func(ctx context.Context) {
ginkgo.By("Creating a pod with an invalid username at container level and pod running as ContainerUser")
p := runAsUserNamePod(toPtr("FooLish"))
p.Spec.SecurityContext.WindowsOptions.RunAsUserName = toPtr("ContainerUser")
@@ -116,7 +116,7 @@ var _ = SIGDescribe("[Feature:Windows] SecurityContext", func() {
}
})
ginkgo.It("should override SecurityContext username if set", func() {
ginkgo.It("should override SecurityContext username if set", func(ctx context.Context) {
ginkgo.By("Creating a pod with 2 containers with different username configurations.")
pod := runAsUserNamePod(toPtr("ContainerAdministrator"))
@@ -131,7 +131,7 @@ var _ = SIGDescribe("[Feature:Windows] SecurityContext", func() {
e2eoutput.TestContainerOutput(f, "check pod SecurityContext username", pod, 1, []string{"ContainerAdministrator"})
})
ginkgo.It("should ignore Linux Specific SecurityContext if set", func() {
ginkgo.It("should ignore Linux Specific SecurityContext if set", func(ctx context.Context) {
ginkgo.By("Creating a pod with SELinux options")
// It is sufficient to show that the pod comes up here. Since we're stripping the SELinux and other linux
// security contexts in apiserver and not updating the pod object in the apiserver, we cannot validate the
@@ -155,7 +155,7 @@ var _ = SIGDescribe("[Feature:Windows] SecurityContext", func() {
f.Namespace.Name), "failed to wait for pod %s to be running", windowsPodWithSELinux.Name)
})
ginkgo.It("should not be able to create pods with containers running as ContainerAdministrator when runAsNonRoot is true", func() {
ginkgo.It("should not be able to create pods with containers running as ContainerAdministrator when runAsNonRoot is true", func(ctx context.Context) {
ginkgo.By("Creating a pod")
p := runAsUserNamePod(toPtr("ContainerAdministrator"))
@@ -173,7 +173,7 @@ var _ = SIGDescribe("[Feature:Windows] SecurityContext", func() {
framework.ExpectEqual(true, strings.Contains(event.Message, expectedEventError), "Event error should indicate non-root policy caused container to not start")
})
ginkgo.It("should not be able to create pods with containers running as CONTAINERADMINISTRATOR when runAsNonRoot is true", func() {
ginkgo.It("should not be able to create pods with containers running as CONTAINERADMINISTRATOR when runAsNonRoot is true", func(ctx context.Context) {
ginkgo.By("Creating a pod")
p := runAsUserNamePod(toPtr("CONTAINERADMINISTRATOR"))

View File

@@ -17,6 +17,7 @@ limitations under the License.
package windows
import (
"context"
"fmt"
"net"
"strconv"
@@ -45,7 +46,7 @@ var _ = SIGDescribe("Services", func() {
e2eskipper.SkipUnlessNodeOSDistroIs("windows")
cs = f.ClientSet
})
ginkgo.It("should be able to create a functioning NodePort service for Windows", func() {
ginkgo.It("should be able to create a functioning NodePort service for Windows", func(ctx context.Context) {
serviceName := "nodeport-test"
ns := f.Namespace.Name

View File

@@ -17,6 +17,7 @@ limitations under the License.
package windows
import (
"context"
"fmt"
v1 "k8s.io/api/core/v1"
@@ -65,7 +66,7 @@ var _ = SIGDescribe("[Feature:Windows] Windows volume mounts ", func() {
ginkgo.Context("check volume mount permissions", func() {
ginkgo.It("container should have readOnly permissions on emptyDir", func() {
ginkgo.It("container should have readOnly permissions on emptyDir", func(ctx context.Context) {
ginkgo.By("creating a container with readOnly permissions on emptyDir volume")
doReadOnlyTest(f, emptyDirSource, emptyDirVolumePath)
@@ -74,7 +75,7 @@ var _ = SIGDescribe("[Feature:Windows] Windows volume mounts ", func() {
doReadWriteReadOnlyTest(f, emptyDirSource, emptyDirVolumePath)
})
ginkgo.It("container should have readOnly permissions on hostMapPath", func() {
ginkgo.It("container should have readOnly permissions on hostMapPath", func(ctx context.Context) {
ginkgo.By("creating a container with readOnly permissions on hostMap volume")
doReadOnlyTest(f, hostMapSource, hostMapPath)