Skip to content

Commit

Permalink
e2e: reject unknown providers
Browse files Browse the repository at this point in the history
This finishes the work started for 1.13: instead of merely warning
about an unknown value given to --profile, the test/e2e/e2e.test
binary will now print an error and refuse to run.

Fixes: kubernetes#70200
  • Loading branch information
pohly committed Jan 28, 2019
1 parent 8b98e80 commit f3d79e1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
11 changes: 11 additions & 0 deletions test/e2e/framework/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ func RegisterProvider(name string, factory Factory) {
providers[name] = factory
}

// GetProviders returns the names of all currently registered providers.
func GetProviders() []string {
mutex.Lock()
defer mutex.Unlock()
var providerNames []string
for name := range providers {
providerNames = append(providerNames, name)
}
return providerNames
}

func init() {
// "local" or "skeleton" can always be used.
RegisterProvider("local", func() (ProviderInterface, error) {
Expand Down
36 changes: 21 additions & 15 deletions test/e2e/framework/test_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"fmt"
"io/ioutil"
"os"
"sort"
"strings"
"time"

"github.com/onsi/ginkgo/config"
Expand Down Expand Up @@ -264,7 +266,7 @@ func RegisterClusterFlags() {
flag.StringVar(&TestContext.KubeVolumeDir, "volume-dir", "/var/lib/kubelet", "Path to the directory containing the kubelet volumes.")
flag.StringVar(&TestContext.CertDir, "cert-dir", "", "Path to the directory containing the certs. Default is empty, which doesn't use certs.")
flag.StringVar(&TestContext.RepoRoot, "repo-root", "../../", "Root directory of kubernetes repository, for finding test files.")
flag.StringVar(&TestContext.Provider, "provider", "", "The name of the Kubernetes provider (gce, gke, local, etc.)")
flag.StringVar(&TestContext.Provider, "provider", "", "The name of the Kubernetes provider (gce, gke, local, skeleton, etc.)")
flag.StringVar(&TestContext.Tooling, "tooling", "", "The tooling in use (kops, gke, etc.)")
flag.StringVar(&TestContext.KubectlPath, "kubectl-path", "kubectl", "The kubectl binary to use. For development, you might use 'cluster/kubectl.sh' here.")
flag.StringVar(&TestContext.OutputDir, "e2e-output-dir", "/tmp", "Output directory for interesting/useful test data, like performance data, benchmarks, and other metrics.")
Expand Down Expand Up @@ -399,22 +401,26 @@ func AfterReadingAllFlags(t *TestContextType) {
}

// Make sure that all test runs have a valid TestContext.CloudConfig.Provider.
// TODO: whether and how long this code is needed is getting discussed
// in https://github.com/kubernetes/kubernetes/issues/70194.
var err error
TestContext.CloudConfig.Provider, err = SetupProviderConfig(TestContext.Provider)
if err == nil {
return
}
if !os.IsNotExist(errors.Cause(err)) {
Failf("Failed to setup provider config: %v", err)
}
// We allow unknown provider parameters for historic reasons. At least log a
// warning to catch typos.
// TODO (https://github.com/kubernetes/kubernetes/issues/70200):
// - remove the fallback for unknown providers
// - proper error message instead of Failf (which panics)
klog.Warningf("Unknown provider %q, proceeding as for --provider=skeleton.", TestContext.Provider)
TestContext.CloudConfig.Provider, err = SetupProviderConfig("skeleton")
if err != nil {
Failf("Failed to setup fallback skeleton provider config: %v", err)
if os.IsNotExist(errors.Cause(err)) {
// Provide a more helpful error message when the provider is unknown.
var providers []string
for _, name := range GetProviders() {
// The empty string is accepted, but looks odd in the output below unless we quote it.
if name == "" {
name = `""`
}
providers = append(providers, name)
}
sort.Strings(providers)
klog.Errorf("Unknown provider %q. The following providers are known: %v", TestContext.Provider, strings.Join(providers, " "))
} else {
klog.Errorf("Failed to setup provider config for %q: %v", TestContext.Provider, err)
}
os.Exit(1)
}
}

0 comments on commit f3d79e1

Please sign in to comment.