diff --git a/test/e2e/e2e.go b/test/e2e/e2e.go index b28c33e463..343c099a71 100644 --- a/test/e2e/e2e.go +++ b/test/e2e/e2e.go @@ -103,6 +103,11 @@ var _ = ginkgo.SynchronizedBeforeSuite(func() []byte { // unschedulable, we need to wait until all of them are schedulable. framework.ExpectNoError(framework.WaitForAllNodesSchedulable(c, framework.TestContext.NodeSchedulableTimeout)) + // If NumNodes is not specified then auto-detect how many are scheduleable and not tainted + if framework.TestContext.CloudConfig.NumNodes == framework.DefaultNumNodes { + framework.TestContext.CloudConfig.NumNodes = len(framework.GetReadySchedulableNodesOrDie(c).Items) + } + // Ensure all pods are running and ready before starting tests (otherwise, // cluster infrastructure pods that are being pulled or started can block // test pods from running, and tests that ensure all pods are running and diff --git a/test/e2e/framework/test_context.go b/test/e2e/framework/test_context.go index 9e322f1c76..d98da8e18d 100644 --- a/test/e2e/framework/test_context.go +++ b/test/e2e/framework/test_context.go @@ -35,7 +35,12 @@ import ( kubeletconfig "k8s.io/kubernetes/pkg/kubelet/apis/config" ) -const defaultHost = "http://127.0.0.1:8080" +const ( + defaultHost = "http://127.0.0.1:8080" + + // DefaultNumNodes is the number of nodes. If not specified, then number of nodes is auto-detected + DefaultNumNodes = -1 +) // TestContextType contains test settings and global state. Due to // historic reasons, it is a mixture of items managed by the test @@ -298,7 +303,7 @@ func RegisterClusterFlags() { flag.StringVar(&cloudConfig.Cluster, "gke-cluster", "", "GKE name of cluster being used, if applicable") flag.StringVar(&cloudConfig.NodeInstanceGroup, "node-instance-group", "", "Name of the managed instance group for nodes. Valid only for gce, gke or aws. If there is more than one group: comma separated list of groups.") flag.StringVar(&cloudConfig.Network, "network", "e2e", "The cloud provider network for this e2e cluster.") - flag.IntVar(&cloudConfig.NumNodes, "num-nodes", -1, "Number of nodes in the cluster") + flag.IntVar(&cloudConfig.NumNodes, "num-nodes", DefaultNumNodes, fmt.Sprintf("Number of nodes in the cluster. If the default value of '%q' is used the number of schedulable nodes is auto-detected.", DefaultNumNodes)) flag.StringVar(&cloudConfig.ClusterIPRange, "cluster-ip-range", "10.64.0.0/14", "A CIDR notation IP range from which to assign IPs in the cluster.") flag.StringVar(&cloudConfig.NodeTag, "node-tag", "", "Network tags used on node instances. Valid only for gce, gke") flag.StringVar(&cloudConfig.MasterTag, "master-tag", "", "Network tags used on master instances. Valid only for gce, gke")