mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 03:11:40 +00:00
Merge pull request #81393 from oomichi/cleanup-ReadOrDie
Remove fail argument from ReadOrDie()
This commit is contained in:
commit
dd0fb73a61
@ -155,5 +155,5 @@ var _ = framework.KubeDescribe("[Feature:Example]", func() {
|
|||||||
|
|
||||||
func readFile(test, file string) string {
|
func readFile(test, file string) string {
|
||||||
from := filepath.Join(test, file)
|
from := filepath.Join(test, file)
|
||||||
return commonutils.SubstituteImageName(string(testfiles.ReadOrDie(from, ginkgo.Fail)))
|
return commonutils.SubstituteImageName(string(testfiles.ReadOrDie(from)))
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,6 @@ go_library(
|
|||||||
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/runtime/serializer:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/runtime/serializer:go_default_library",
|
||||||
"//test/e2e/framework/testfiles:go_default_library",
|
"//test/e2e/framework/testfiles:go_default_library",
|
||||||
"//vendor/github.com/onsi/ginkgo:go_default_library",
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -23,8 +23,6 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/apimachinery/pkg/runtime/serializer"
|
"k8s.io/apimachinery/pkg/runtime/serializer"
|
||||||
"k8s.io/kubernetes/test/e2e/framework/testfiles"
|
"k8s.io/kubernetes/test/e2e/framework/testfiles"
|
||||||
|
|
||||||
"github.com/onsi/ginkgo"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -54,7 +52,7 @@ func NumberOfSampleResources(node *v1.Node) int64 {
|
|||||||
|
|
||||||
// GetSampleDevicePluginPod returns the Device Plugin pod for sample resources in e2e tests
|
// GetSampleDevicePluginPod returns the Device Plugin pod for sample resources in e2e tests
|
||||||
func GetSampleDevicePluginPod() *v1.Pod {
|
func GetSampleDevicePluginPod() *v1.Pod {
|
||||||
ds := ReadDaemonSetV1OrDie(testfiles.ReadOrDie(sampleDevicePluginDSYAML, ginkgo.Fail))
|
ds := ReadDaemonSetV1OrDie(testfiles.ReadOrDie(sampleDevicePluginDSYAML))
|
||||||
p := &v1.Pod{
|
p := &v1.Pod{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: sampleDevicePluginName,
|
Name: sampleDevicePluginName,
|
||||||
|
@ -399,10 +399,10 @@ func NewIngressTestJig(c clientset.Interface) *TestJig {
|
|||||||
func (j *TestJig) CreateIngress(manifestPath, ns string, ingAnnotations map[string]string, svcAnnotations map[string]string) {
|
func (j *TestJig) CreateIngress(manifestPath, ns string, ingAnnotations map[string]string, svcAnnotations map[string]string) {
|
||||||
var err error
|
var err error
|
||||||
read := func(file string) string {
|
read := func(file string) string {
|
||||||
return string(testfiles.ReadOrDie(filepath.Join(manifestPath, file), ginkgo.Fail))
|
return string(testfiles.ReadOrDie(filepath.Join(manifestPath, file)))
|
||||||
}
|
}
|
||||||
exists := func(file string) bool {
|
exists := func(file string) bool {
|
||||||
return testfiles.Exists(filepath.Join(manifestPath, file), ginkgo.Fail)
|
return testfiles.Exists(filepath.Join(manifestPath, file))
|
||||||
}
|
}
|
||||||
|
|
||||||
j.Logger.Infof("creating replication controller")
|
j.Logger.Infof("creating replication controller")
|
||||||
@ -844,7 +844,7 @@ type NginxIngressController struct {
|
|||||||
// Init initializes the NginxIngressController
|
// Init initializes the NginxIngressController
|
||||||
func (cont *NginxIngressController) Init() {
|
func (cont *NginxIngressController) Init() {
|
||||||
read := func(file string) string {
|
read := func(file string) string {
|
||||||
return string(testfiles.ReadOrDie(filepath.Join(IngressManifestPath, "nginx", file), ginkgo.Fail))
|
return string(testfiles.ReadOrDie(filepath.Join(IngressManifestPath, "nginx", file)))
|
||||||
}
|
}
|
||||||
e2elog.Logf("initializing nginx ingress controller")
|
e2elog.Logf("initializing nginx ingress controller")
|
||||||
framework.RunKubectlOrDieInput(read("rc.yaml"), "create", "-f", "-", fmt.Sprintf("--namespace=%v", cont.Ns))
|
framework.RunKubectlOrDieInput(read("rc.yaml"), "create", "-f", "-", fmt.Sprintf("--namespace=%v", cont.Ns))
|
||||||
|
@ -5,6 +5,7 @@ go_library(
|
|||||||
srcs = ["testfiles.go"],
|
srcs = ["testfiles.go"],
|
||||||
importpath = "k8s.io/kubernetes/test/e2e/framework/testfiles",
|
importpath = "k8s.io/kubernetes/test/e2e/framework/testfiles",
|
||||||
visibility = ["//visibility:public"],
|
visibility = ["//visibility:public"],
|
||||||
|
deps = ["//vendor/github.com/onsi/ginkgo:go_default_library"],
|
||||||
)
|
)
|
||||||
|
|
||||||
filegroup(
|
filegroup(
|
||||||
|
@ -33,6 +33,8 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/onsi/ginkgo"
|
||||||
)
|
)
|
||||||
|
|
||||||
var filesources []FileSource
|
var filesources []FileSource
|
||||||
@ -64,20 +66,14 @@ type FileSource interface {
|
|||||||
DescribeFiles() string
|
DescribeFiles() string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fail is an error handler function with the same prototype and
|
|
||||||
// semantic as ginkgo.Fail. Typically ginkgo.Fail is what callers
|
|
||||||
// of ReadOrDie and Exists will pass. This way this package
|
|
||||||
// avoids depending on Ginkgo.
|
|
||||||
type Fail func(failure string, callerSkip ...int)
|
|
||||||
|
|
||||||
// ReadOrDie tries to retrieve the desired file content from
|
// ReadOrDie tries to retrieve the desired file content from
|
||||||
// one of the registered file sources. In contrast to FileSource, it
|
// 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,
|
// 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.
|
// i.e. the caller doesn't have to implement error checking.
|
||||||
func ReadOrDie(filePath string, fail Fail) []byte {
|
func ReadOrDie(filePath string) []byte {
|
||||||
data, err := Read(filePath)
|
data, err := Read(filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fail(err.Error(), 1)
|
ginkgo.Fail(err.Error(), 1)
|
||||||
}
|
}
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
@ -110,11 +106,11 @@ func Read(filePath string) ([]byte, error) {
|
|||||||
// Exists checks whether a file could be read. Unexpected errors
|
// Exists checks whether a file could be read. Unexpected errors
|
||||||
// are handled by calling the fail function, which then should
|
// are handled by calling the fail function, which then should
|
||||||
// abort the current test.
|
// abort the current test.
|
||||||
func Exists(filePath string, fail Fail) bool {
|
func Exists(filePath string) bool {
|
||||||
for _, filesource := range filesources {
|
for _, filesource := range filesources {
|
||||||
data, err := filesource.ReadTestFile(filePath)
|
data, err := filesource.ReadTestFile(filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fail(fmt.Sprintf("fatal error looking for test file %s: %s", filePath, err), 1)
|
ginkgo.Fail(fmt.Sprintf("fatal error looking for test file %s: %s", filePath, err), 1)
|
||||||
}
|
}
|
||||||
if data != nil {
|
if data != nil {
|
||||||
return true
|
return true
|
||||||
|
@ -134,7 +134,7 @@ func cleanupKubectlInputs(fileContents string, ns string, selectors ...string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func readTestFileOrDie(file string) []byte {
|
func readTestFileOrDie(file string) []byte {
|
||||||
return testfiles.ReadOrDie(path.Join(kubeCtlManifestPath, file), ginkgo.Fail)
|
return testfiles.ReadOrDie(path.Join(kubeCtlManifestPath, file))
|
||||||
}
|
}
|
||||||
|
|
||||||
func runKubectlRetryOrDie(args ...string) string {
|
func runKubectlRetryOrDie(args ...string) string {
|
||||||
@ -276,8 +276,8 @@ var _ = SIGDescribe("Kubectl client", func() {
|
|||||||
var nautilus, kitten string
|
var nautilus, kitten string
|
||||||
ginkgo.BeforeEach(func() {
|
ginkgo.BeforeEach(func() {
|
||||||
updateDemoRoot := "test/fixtures/doc-yaml/user-guide/update-demo"
|
updateDemoRoot := "test/fixtures/doc-yaml/user-guide/update-demo"
|
||||||
nautilus = commonutils.SubstituteImageName(string(testfiles.ReadOrDie(filepath.Join(updateDemoRoot, "nautilus-rc.yaml.in"), ginkgo.Fail)))
|
nautilus = commonutils.SubstituteImageName(string(testfiles.ReadOrDie(filepath.Join(updateDemoRoot, "nautilus-rc.yaml.in"))))
|
||||||
kitten = commonutils.SubstituteImageName(string(testfiles.ReadOrDie(filepath.Join(updateDemoRoot, "kitten-rc.yaml.in"), ginkgo.Fail)))
|
kitten = commonutils.SubstituteImageName(string(testfiles.ReadOrDie(filepath.Join(updateDemoRoot, "kitten-rc.yaml.in"))))
|
||||||
})
|
})
|
||||||
/*
|
/*
|
||||||
Release : v1.9
|
Release : v1.9
|
||||||
@ -341,7 +341,7 @@ var _ = SIGDescribe("Kubectl client", func() {
|
|||||||
"redis-master-deployment.yaml.in",
|
"redis-master-deployment.yaml.in",
|
||||||
"redis-slave-deployment.yaml.in",
|
"redis-slave-deployment.yaml.in",
|
||||||
} {
|
} {
|
||||||
contents := commonutils.SubstituteImageName(string(testfiles.ReadOrDie(filepath.Join(guestbookRoot, gbAppFile), ginkgo.Fail)))
|
contents := commonutils.SubstituteImageName(string(testfiles.ReadOrDie(filepath.Join(guestbookRoot, gbAppFile))))
|
||||||
run(contents)
|
run(contents)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -94,7 +94,7 @@ func installFlex(c clientset.Interface, node *v1.Node, vendor, driver, filePath
|
|||||||
cmd := fmt.Sprintf("sudo mkdir -p %s", flexDir)
|
cmd := fmt.Sprintf("sudo mkdir -p %s", flexDir)
|
||||||
sshAndLog(cmd, host, true /*failOnError*/)
|
sshAndLog(cmd, host, true /*failOnError*/)
|
||||||
|
|
||||||
data := testfiles.ReadOrDie(filePath, ginkgo.Fail)
|
data := testfiles.ReadOrDie(filePath)
|
||||||
cmd = fmt.Sprintf("sudo tee <<'EOF' %s\n%s\nEOF", flexFile, string(data))
|
cmd = fmt.Sprintf("sudo tee <<'EOF' %s\n%s\nEOF", flexFile, string(data))
|
||||||
sshAndLog(cmd, host, true /*failOnError*/)
|
sshAndLog(cmd, host, true /*failOnError*/)
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ func (CassandraUpgradeTest) Skip(upgCtx UpgradeContext) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func cassandraKubectlCreate(ns, file string) {
|
func cassandraKubectlCreate(ns, file string) {
|
||||||
input := string(testfiles.ReadOrDie(filepath.Join(cassandraManifestPath, file), ginkgo.Fail))
|
input := string(testfiles.ReadOrDie(filepath.Join(cassandraManifestPath, file)))
|
||||||
framework.RunKubectlOrDieInput(input, "create", "-f", "-", fmt.Sprintf("--namespace=%s", ns))
|
framework.RunKubectlOrDieInput(input, "create", "-f", "-", fmt.Sprintf("--namespace=%s", ns))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ func (EtcdUpgradeTest) Skip(upgCtx UpgradeContext) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func kubectlCreate(ns, file string) {
|
func kubectlCreate(ns, file string) {
|
||||||
input := string(testfiles.ReadOrDie(filepath.Join(manifestPath, file), ginkgo.Fail))
|
input := string(testfiles.ReadOrDie(filepath.Join(manifestPath, file)))
|
||||||
framework.RunKubectlOrDieInput(input, "create", "-f", "-", fmt.Sprintf("--namespace=%s", ns))
|
framework.RunKubectlOrDieInput(input, "create", "-f", "-", fmt.Sprintf("--namespace=%s", ns))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ func (MySQLUpgradeTest) Skip(upgCtx UpgradeContext) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func mysqlKubectlCreate(ns, file string) {
|
func mysqlKubectlCreate(ns, file string) {
|
||||||
input := string(testfiles.ReadOrDie(filepath.Join(mysqlManifestPath, file), ginkgo.Fail))
|
input := string(testfiles.ReadOrDie(filepath.Join(mysqlManifestPath, file)))
|
||||||
framework.RunKubectlOrDieInput(input, "create", "-f", "-", fmt.Sprintf("--namespace=%s", ns))
|
framework.RunKubectlOrDieInput(input, "create", "-f", "-", fmt.Sprintf("--namespace=%s", ns))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user