diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index e3bea9e5507..ebf5228018e 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -110,7 +110,11 @@ func TestMain(m *testing.M) { File string `yaml:"file"` } - data := testfiles.ReadOrDie("test/conformance/testdata/conformance.yaml") + data, err := testfiles.Read("test/conformance/testdata/conformance.yaml") + if err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } if err := yaml.Unmarshal(data, &tests); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) diff --git a/test/e2e/examples.go b/test/e2e/examples.go index 169048ff519..4e030bdb240 100644 --- a/test/e2e/examples.go +++ b/test/e2e/examples.go @@ -155,5 +155,9 @@ var _ = framework.KubeDescribe("[Feature:Example]", func() { func readFile(test, file string) string { from := filepath.Join(test, file) - return commonutils.SubstituteImageName(string(testfiles.ReadOrDie(from))) + data, err := testfiles.Read(from) + if err != nil { + framework.Fail(err.Error()) + } + return commonutils.SubstituteImageName(string(data)) } diff --git a/test/e2e/framework/ingress/ingress_utils.go b/test/e2e/framework/ingress/ingress_utils.go index 99b52a660df..ebe8d096826 100644 --- a/test/e2e/framework/ingress/ingress_utils.go +++ b/test/e2e/framework/ingress/ingress_utils.go @@ -445,10 +445,18 @@ func NewIngressTestJig(c clientset.Interface) *TestJig { func (j *TestJig) CreateIngress(manifestPath, ns string, ingAnnotations map[string]string, svcAnnotations map[string]string) { var err error read := func(file string) string { - return string(e2etestfiles.ReadOrDie(filepath.Join(manifestPath, file))) + data, err := e2etestfiles.Read(filepath.Join(manifestPath, file)) + if err != nil { + framework.Fail(err.Error()) + } + return string(data) } exists := func(file string) bool { - return e2etestfiles.Exists(filepath.Join(manifestPath, file)) + found, err := e2etestfiles.Exists(filepath.Join(manifestPath, file)) + if err != nil { + framework.Fail(fmt.Sprintf("fatal error looking for test file %s: %s", file, err)) + } + return found } j.Logger.Infof("creating replication controller") @@ -1018,8 +1026,13 @@ func (cont *NginxIngressController) Init() { framework.ExpectNoError(err) read := func(file string) string { - return string(e2etestfiles.ReadOrDie(filepath.Join(IngressManifestPath, "nginx", file))) + data, err := e2etestfiles.Read(filepath.Join(IngressManifestPath, "nginx", file)) + if err != nil { + framework.Fail(err.Error()) + } + return string(data) } + framework.Logf("initializing nginx ingress controller") framework.RunKubectlOrDieInput(cont.Ns, read("rc.yaml"), "create", "-f", "-", fmt.Sprintf("--namespace=%v", cont.Ns)) diff --git a/test/e2e/framework/testfiles/BUILD b/test/e2e/framework/testfiles/BUILD index 2761a9d7a26..fbc7055edd3 100644 --- a/test/e2e/framework/testfiles/BUILD +++ b/test/e2e/framework/testfiles/BUILD @@ -5,7 +5,6 @@ go_library( srcs = ["testfiles.go"], importpath = "k8s.io/kubernetes/test/e2e/framework/testfiles", visibility = ["//visibility:public"], - deps = ["//test/e2e/framework:go_default_library"], ) filegroup( diff --git a/test/e2e/framework/testfiles/testfiles.go b/test/e2e/framework/testfiles/testfiles.go index 175a664ff75..a0251abfbab 100644 --- a/test/e2e/framework/testfiles/testfiles.go +++ b/test/e2e/framework/testfiles/testfiles.go @@ -33,8 +33,6 @@ import ( "path/filepath" "sort" "strings" - - "k8s.io/kubernetes/test/e2e/framework" ) var filesources []FileSource @@ -66,18 +64,6 @@ type FileSource interface { DescribeFiles() string } -// ReadOrDie tries to retrieve the desired file content from -// one of the registered file sources. In contrast to FileSource, it -// will either return a valid slice or abort the test by calling the fatal function, -// i.e. the caller doesn't have to implement error checking. -func ReadOrDie(filePath string) []byte { - data, err := Read(filePath) - if err != nil { - framework.Fail(err.Error(), 1) - } - return data -} - // Read tries to retrieve the desired file content from // one of the registered file sources. func Read(filePath string) ([]byte, error) { @@ -106,17 +92,17 @@ func Read(filePath string) ([]byte, error) { // Exists checks whether a file could be read. Unexpected errors // are handled by calling the fail function, which then should // abort the current test. -func Exists(filePath string) bool { +func Exists(filePath string) (bool, error) { for _, filesource := range filesources { data, err := filesource.ReadTestFile(filePath) if err != nil { - framework.Fail(fmt.Sprintf("fatal error looking for test file %s: %s", filePath, err), 1) + return false, err } if data != nil { - return true + return true, nil } } - return false + return false, nil } // RootFileSource looks for files relative to a root directory. diff --git a/test/e2e/kubectl/kubectl.go b/test/e2e/kubectl/kubectl.go index 5862213b1f5..2b67fcf5ee9 100644 --- a/test/e2e/kubectl/kubectl.go +++ b/test/e2e/kubectl/kubectl.go @@ -210,7 +210,11 @@ func assertCleanup(ns string, selectors ...string) { } func readTestFileOrDie(file string) []byte { - return e2etestfiles.ReadOrDie(path.Join(kubeCtlManifestPath, file)) + data, err := e2etestfiles.Read(path.Join(kubeCtlManifestPath, file)) + if err != nil { + framework.Fail(err.Error(), 1) + } + return data } func runKubectlRetryOrDie(ns string, args ...string) string { @@ -302,7 +306,11 @@ var _ = SIGDescribe("Kubectl client", func() { var nautilus string ginkgo.BeforeEach(func() { updateDemoRoot := "test/fixtures/doc-yaml/user-guide/update-demo" - nautilus = commonutils.SubstituteImageName(string(e2etestfiles.ReadOrDie(filepath.Join(updateDemoRoot, "nautilus-rc.yaml.in")))) + data, err := e2etestfiles.Read(filepath.Join(updateDemoRoot, "nautilus-rc.yaml.in")) + if err != nil { + framework.Fail(err.Error()) + } + nautilus = commonutils.SubstituteImageName(string(data)) }) /* Release : v1.9 @@ -350,7 +358,11 @@ var _ = SIGDescribe("Kubectl client", func() { "agnhost-primary-deployment.yaml.in", "agnhost-replica-deployment.yaml.in", } { - contents := commonutils.SubstituteImageName(string(e2etestfiles.ReadOrDie(filepath.Join(guestbookRoot, gbAppFile)))) + data, err := e2etestfiles.Read(filepath.Join(guestbookRoot, gbAppFile)) + if err != nil { + framework.Fail(err.Error()) + } + contents := commonutils.SubstituteImageName(string(data)) run(contents) } } diff --git a/test/e2e/storage/flexvolume.go b/test/e2e/storage/flexvolume.go index 8ff76526f19..e4d403e5848 100644 --- a/test/e2e/storage/flexvolume.go +++ b/test/e2e/storage/flexvolume.go @@ -91,7 +91,10 @@ func installFlex(c clientset.Interface, node *v1.Node, vendor, driver, filePath cmd := fmt.Sprintf("sudo mkdir -p %s", flexDir) sshAndLog(cmd, host, true /*failOnError*/) - data := e2etestfiles.ReadOrDie(filePath) + data, err := e2etestfiles.Read(filePath) + if err != nil { + framework.Fail(err.Error()) + } cmd = fmt.Sprintf("sudo tee <<'EOF' %s\n%s\nEOF", flexFile, string(data)) sshAndLog(cmd, host, true /*failOnError*/) diff --git a/test/e2e/upgrades/cassandra.go b/test/e2e/upgrades/cassandra.go index b093586c42e..2acb054e5b3 100644 --- a/test/e2e/upgrades/cassandra.go +++ b/test/e2e/upgrades/cassandra.go @@ -60,7 +60,11 @@ func (CassandraUpgradeTest) Skip(upgCtx UpgradeContext) bool { } func cassandraKubectlCreate(ns, file string) { - input := string(e2etestfiles.ReadOrDie(filepath.Join(cassandraManifestPath, file))) + data, err := e2etestfiles.Read(filepath.Join(cassandraManifestPath, file)) + if err != nil { + framework.Fail(err.Error()) + } + input := string(data) framework.RunKubectlOrDieInput(ns, input, "create", "-f", "-", fmt.Sprintf("--namespace=%s", ns)) } diff --git a/test/e2e/upgrades/etcd.go b/test/e2e/upgrades/etcd.go index feeafd2b081..32ca170fd59 100644 --- a/test/e2e/upgrades/etcd.go +++ b/test/e2e/upgrades/etcd.go @@ -59,7 +59,11 @@ func (EtcdUpgradeTest) Skip(upgCtx UpgradeContext) bool { } func kubectlCreate(ns, file string) { - input := string(e2etestfiles.ReadOrDie(filepath.Join(manifestPath, file))) + data, err := e2etestfiles.Read(filepath.Join(manifestPath, file)) + if err != nil { + framework.Fail(err.Error()) + } + input := string(data) framework.RunKubectlOrDieInput(ns, input, "create", "-f", "-", fmt.Sprintf("--namespace=%s", ns)) } diff --git a/test/e2e/upgrades/mysql.go b/test/e2e/upgrades/mysql.go index edb3a599a21..89f735b55ef 100644 --- a/test/e2e/upgrades/mysql.go +++ b/test/e2e/upgrades/mysql.go @@ -61,7 +61,11 @@ func (MySQLUpgradeTest) Skip(upgCtx UpgradeContext) bool { } func mysqlKubectlCreate(ns, file string) { - input := string(e2etestfiles.ReadOrDie(filepath.Join(mysqlManifestPath, file))) + data, err := e2etestfiles.Read(filepath.Join(mysqlManifestPath, file)) + if err != nil { + framework.Fail(err.Error()) + } + input := string(data) framework.RunKubectlOrDieInput(ns, input, "create", "-f", "-", fmt.Sprintf("--namespace=%s", ns)) } diff --git a/test/e2e_node/device_plugin_test.go b/test/e2e_node/device_plugin_test.go index 83a962493dd..f00a5a33650 100644 --- a/test/e2e_node/device_plugin_test.go +++ b/test/e2e_node/device_plugin_test.go @@ -80,7 +80,12 @@ func numberOfSampleResources(node *v1.Node) int64 { // getSampleDevicePluginPod returns the Device Plugin pod for sample resources in e2e tests. func getSampleDevicePluginPod() *v1.Pod { - ds := readDaemonSetV1OrDie(e2etestfiles.ReadOrDie(sampleDevicePluginDSYAML)) + data, err := e2etestfiles.Read(sampleDevicePluginDSYAML) + if err != nil { + framework.Fail(err.Error()) + } + + ds := readDaemonSetV1OrDie(data) p := &v1.Pod{ ObjectMeta: metav1.ObjectMeta{ Name: sampleDevicePluginName, diff --git a/test/e2e_node/topology_manager_test.go b/test/e2e_node/topology_manager_test.go index d398f7395a5..09285f42dad 100644 --- a/test/e2e_node/topology_manager_test.go +++ b/test/e2e_node/topology_manager_test.go @@ -246,7 +246,12 @@ func configureTopologyManagerInKubelet(f *framework.Framework, oldCfg *kubeletco // getSRIOVDevicePluginPod returns the Device Plugin pod for sriov resources in e2e tests. func getSRIOVDevicePluginPod() *v1.Pod { - ds := readDaemonSetV1OrDie(e2etestfiles.ReadOrDie(SRIOVDevicePluginDSYAML)) + data, err := e2etestfiles.Read(SRIOVDevicePluginDSYAML) + if err != nil { + framework.Fail(err.Error()) + } + + ds := readDaemonSetV1OrDie(data) p := &v1.Pod{ ObjectMeta: metav1.ObjectMeta{ Name: SRIOVDevicePluginName, @@ -415,13 +420,15 @@ func isTopologyAffinityError(pod *v1.Pod) bool { } func getSRIOVDevicePluginConfigMap(cmFile string) *v1.ConfigMap { - cmData := e2etestfiles.ReadOrDie(SRIOVDevicePluginCMYAML) - var err error + data, err := e2etestfiles.Read(SRIOVDevicePluginCMYAML) + if err != nil { + framework.Fail(err.Error()) + } // the SRIOVDP configuration is hw-dependent, so we allow per-test-host customization. framework.Logf("host-local SRIOV Device Plugin Config Map %q", cmFile) if cmFile != "" { - cmData, err = ioutil.ReadFile(cmFile) + data, err = ioutil.ReadFile(cmFile) if err != nil { framework.Failf("unable to load the SRIOV Device Plugin ConfigMap: %v", err) } @@ -429,7 +436,7 @@ func getSRIOVDevicePluginConfigMap(cmFile string) *v1.ConfigMap { framework.Logf("Using built-in SRIOV Device Plugin Config Map") } - return readConfigMapV1OrDie(cmData) + return readConfigMapV1OrDie(data) } type sriovData struct { @@ -449,7 +456,11 @@ func setupSRIOVConfigOrFail(f *framework.Framework, configMap *v1.ConfigMap) *sr framework.Failf("unable to create test configMap %s: %v", configMap.Name, err) } - serviceAccount := readServiceAccountV1OrDie(e2etestfiles.ReadOrDie(SRIOVDevicePluginSAYAML)) + data, err := e2etestfiles.Read(SRIOVDevicePluginSAYAML) + if err != nil { + framework.Fail(err.Error()) + } + serviceAccount := readServiceAccountV1OrDie(data) ginkgo.By(fmt.Sprintf("Creating serviceAccount %v/%v", metav1.NamespaceSystem, serviceAccount.Name)) if _, err = f.ClientSet.CoreV1().ServiceAccounts(metav1.NamespaceSystem).Create(context.TODO(), serviceAccount, metav1.CreateOptions{}); err != nil { framework.Failf("unable to create test serviceAccount %s: %v", serviceAccount.Name, err)