diff --git a/test/e2e/framework/BUILD b/test/e2e/framework/BUILD index eba25b2c3aa..40ccfeceafe 100644 --- a/test/e2e/framework/BUILD +++ b/test/e2e/framework/BUILD @@ -18,6 +18,7 @@ go_library( "resource_usage_gatherer.go", "size.go", "test_context.go", + "timeouts.go", "util.go", ], importpath = "k8s.io/kubernetes/test/e2e/framework", diff --git a/test/e2e/framework/framework.go b/test/e2e/framework/framework.go index 8073f80aa43..63e85fc485a 100644 --- a/test/e2e/framework/framework.go +++ b/test/e2e/framework/framework.go @@ -119,6 +119,9 @@ type Framework struct { // Place to keep ClusterAutoscaler metrics from before test in order to compute delta. clusterAutoscalerMetricsBeforeTest e2emetrics.Collection + + // Timeouts contains the custom timeouts used during the test execution. + Timeouts *TimeoutContext } // AfterEachActionFunc is a function that can be called after each test @@ -138,6 +141,13 @@ type Options struct { GroupVersion *schema.GroupVersion } +// NewFrameworkWithCustomTimeouts makes a framework with with custom timeouts. +func NewFrameworkWithCustomTimeouts(baseName string, timeouts *TimeoutContext) *Framework { + f := NewDefaultFramework(baseName) + f.Timeouts = timeouts + return f +} + // NewDefaultFramework makes a new framework and sets up a BeforeEach/AfterEach for // you (you can write additional before/after each functions). func NewDefaultFramework(baseName string) *Framework { @@ -155,6 +165,7 @@ func NewFramework(baseName string, options Options, client clientset.Interface) AddonResourceConstraints: make(map[string]ResourceConstraint), Options: options, ClientSet: client, + Timeouts: NewTimeoutContextWithDefaults(), } f.AddAfterEach("dumpNamespaceInfo", func(f *Framework, failed bool) { diff --git a/test/e2e/framework/pv/pv.go b/test/e2e/framework/pv/pv.go index 64e6dbbe360..4a4c4f9b9e6 100644 --- a/test/e2e/framework/pv/pv.go +++ b/test/e2e/framework/pv/pv.go @@ -19,9 +19,10 @@ package framework import ( "context" "fmt" - "k8s.io/kubernetes/test/e2e/storage/utils" "time" + "k8s.io/kubernetes/test/e2e/storage/utils" + "github.com/onsi/ginkgo" v1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" @@ -38,18 +39,6 @@ const ( pdRetryTimeout = 5 * time.Minute pdRetryPollTime = 5 * time.Second - // PVBindingTimeout is how long PVs have to become bound. - PVBindingTimeout = 3 * time.Minute - - // ClaimBindingTimeout is how long claims have to become bound. - ClaimBindingTimeout = 3 * time.Minute - - // PVReclaimingTimeout is how long PVs have to beome reclaimed. - PVReclaimingTimeout = 3 * time.Minute - - // PVDeletingTimeout is how long PVs have to become deleted. - PVDeletingTimeout = 3 * time.Minute - // VolumeSelectorKey is the key for volume selector. VolumeSelectorKey = "e2e-pv-pool" diff --git a/test/e2e/framework/timeouts.go b/test/e2e/framework/timeouts.go new file mode 100644 index 00000000000..93e17332de2 --- /dev/null +++ b/test/e2e/framework/timeouts.go @@ -0,0 +1,94 @@ +/* +Copyright 2020 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package framework + +import "time" + +const ( + // Default timeouts to be used in TimeoutContext + podStartTimeout = 5 * time.Minute + podStartShortTimeout = 2 * time.Minute + podStartSlowTimeout = 15 * time.Minute + podDeleteTimeout = 5 * time.Minute + claimProvisionTimeout = 5 * time.Minute + claimProvisionShortTimeout = 1 * time.Minute + claimBoundTimeout = 3 * time.Minute + pvReclaimTimeout = 3 * time.Minute + pvBoundTimeout = 3 * time.Minute + pvDeleteTimeout = 3 * time.Minute + snapshotCreateTimeout = 5 * time.Minute + snapshotDeleteTimeout = 5 * time.Minute +) + +// TimeoutContext contains timeout settings for several actions. +type TimeoutContext struct { + // PodStart is how long to wait for the pod to be started. + PodStart time.Duration + + // PodStartShort is same as `PodStart`, but shorter. + // Use it in a case-by-case basis, mostly when you are sure pod start will not be delayed. + PodStartShort time.Duration + + // PodStartSlow is same as `PodStart`, but longer. + // Use it in a case-by-case basis, mostly when you are sure pod start will take longer than usual. + PodStartSlow time.Duration + + // PodDelete is how long to wait for the pod to be deleted. + PodDelete time.Duration + + // ClaimProvision is how long claims have to become dynamically provisioned. + ClaimProvision time.Duration + + // ClaimProvisionShort is the same as `ClaimProvision`, but shorter. + ClaimProvisionShort time.Duration + + // ClaimBound is how long claims have to become bound. + ClaimBound time.Duration + + // PVReclaim is how long PVs have to become reclaimed. + PVReclaim time.Duration + + // PVBound is how long PVs have to become bound. + PVBound time.Duration + + // PVDelete is how long PVs have to become deleted. + PVDelete time.Duration + + // SnapshotCreate is how long for snapshot to create snapshotContent. + SnapshotCreate time.Duration + + // SnapshotDelete is how long for snapshot to delete snapshotContent. + SnapshotDelete time.Duration +} + +// NewTimeoutContextWithDefaults returns a TimeoutContext with default values. +func NewTimeoutContextWithDefaults() *TimeoutContext { + return &TimeoutContext{ + PodStart: podStartTimeout, + PodStartShort: podStartShortTimeout, + PodStartSlow: podStartSlowTimeout, + PodDelete: podDeleteTimeout, + ClaimProvision: claimProvisionTimeout, + ClaimProvisionShort: claimProvisionShortTimeout, + ClaimBound: claimBoundTimeout, + PVReclaim: pvReclaimTimeout, + PVBound: pvBoundTimeout, + PVDelete: pvDeleteTimeout, + SnapshotCreate: snapshotCreateTimeout, + SnapshotDelete: snapshotDeleteTimeout, + } +} diff --git a/test/e2e/framework/util.go b/test/e2e/framework/util.go index 2931e3eaaa9..6cac730eb5b 100644 --- a/test/e2e/framework/util.go +++ b/test/e2e/framework/util.go @@ -71,9 +71,23 @@ import ( e2epod "k8s.io/kubernetes/test/e2e/framework/pod" ) +const ( + // Minimal number of nodes for the cluster to be considered large. + largeClusterThreshold = 100 + + // TODO(justinsb): Avoid hardcoding this. + awsMasterIP = "172.20.0.9" + + // AllContainers specifies that all containers be visited + // Copied from pkg/api/v1/pod to avoid pulling extra dependencies + AllContainers = InitContainers | Containers | EphemeralContainers +) + +// DEPRECATED constants. Use the timeouts in framework.Framework instead. const ( // PodListTimeout is how long to wait for the pod to be listable. PodListTimeout = time.Minute + // PodStartTimeout is how long to wait for the pod to be started. PodStartTimeout = 5 * time.Minute @@ -136,16 +150,6 @@ const ( // SnapshotDeleteTimeout is how long for snapshot to delete snapshotContent. SnapshotDeleteTimeout = 5 * time.Minute - - // Minimal number of nodes for the cluster to be considered large. - largeClusterThreshold = 100 - - // TODO(justinsb): Avoid hardcoding this. - awsMasterIP = "172.20.0.9" - - // AllContainers specifies that all containers be visited - // Copied from pkg/api/v1/pod to avoid pulling extra dependencies - AllContainers = InitContainers | Containers | EphemeralContainers ) var (