mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Add log.go back to core of e2e test framework
We tried to separate logger functionality as subpackage of e2e test framework, but we've recognized that should be core functionality and we should keep it as core of e2e test framework after facing circular dependency issues. So this adds log.go back to core of e2e test framework. In addition, this makes volume sub package use the core logger as a sample.
This commit is contained in:
parent
32dc42ed34
commit
5e1743cfb1
@ -12,6 +12,7 @@ go_library(
|
||||
"framework.go",
|
||||
"get-kubemark-resource-usage.go",
|
||||
"google_compute.go",
|
||||
"log.go",
|
||||
"log_size_monitoring.go",
|
||||
"networking_utils.go",
|
||||
"nodes_util.go",
|
||||
|
41
test/e2e/framework/log.go
Normal file
41
test/e2e/framework/log.go
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
Copyright 2019 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 (
|
||||
"fmt"
|
||||
|
||||
"k8s.io/kubernetes/test/e2e/framework/ginkgowrapper"
|
||||
)
|
||||
|
||||
// Logf logs the info.
|
||||
func Logf(format string, args ...interface{}) {
|
||||
log("INFO", format, args...)
|
||||
}
|
||||
|
||||
// Failf logs the fail info.
|
||||
func Failf(format string, args ...interface{}) {
|
||||
FailfWithOffset(1, format, args...)
|
||||
}
|
||||
|
||||
// FailfWithOffset calls "Fail" and logs the error at "offset" levels above its caller
|
||||
// (for example, for call chain f -> g -> FailfWithOffset(1, ...) error would be logged for "f").
|
||||
func FailfWithOffset(offset int, format string, args ...interface{}) {
|
||||
msg := fmt.Sprintf(format, args...)
|
||||
log("INFO", msg)
|
||||
ginkgowrapper.Fail(nowStamp()+": "+msg, 1+offset)
|
||||
}
|
@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// Package log should be removed after switching to use core framework log.
|
||||
package log
|
||||
|
||||
import (
|
||||
|
@ -13,7 +13,6 @@ go_library(
|
||||
"//staging/src/k8s.io/apimachinery/pkg/labels:go_default_library",
|
||||
"//staging/src/k8s.io/client-go/kubernetes:go_default_library",
|
||||
"//test/e2e/framework:go_default_library",
|
||||
"//test/e2e/framework/log:go_default_library",
|
||||
"//test/e2e/framework/pod:go_default_library",
|
||||
"//test/e2e/storage/utils:go_default_library",
|
||||
"//test/utils/image:go_default_library",
|
||||
|
@ -51,7 +51,6 @@ import (
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
clientset "k8s.io/client-go/kubernetes"
|
||||
"k8s.io/kubernetes/test/e2e/framework"
|
||||
e2elog "k8s.io/kubernetes/test/e2e/framework/log"
|
||||
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
|
||||
"k8s.io/kubernetes/test/e2e/storage/utils"
|
||||
imageutils "k8s.io/kubernetes/test/utils/image"
|
||||
@ -249,7 +248,7 @@ func NewRBDServer(cs clientset.Interface, namespace string) (config TestConfig,
|
||||
|
||||
secret, err := cs.CoreV1().Secrets(config.Namespace).Create(secret)
|
||||
if err != nil {
|
||||
e2elog.Failf("Failed to create secrets for Ceph RBD: %v", err)
|
||||
framework.Failf("Failed to create secrets for Ceph RBD: %v", err)
|
||||
}
|
||||
|
||||
return config, pod, secret, ip
|
||||
@ -263,7 +262,7 @@ func CreateStorageServer(cs clientset.Interface, config TestConfig) (pod *v1.Pod
|
||||
gomega.Expect(pod).NotTo(gomega.BeNil(), "storage server pod should not be nil")
|
||||
ip = pod.Status.PodIP
|
||||
gomega.Expect(len(ip)).NotTo(gomega.BeZero(), fmt.Sprintf("pod %s's IP should not be empty", pod.Name))
|
||||
e2elog.Logf("%s server pod IP address: %s", config.Prefix, ip)
|
||||
framework.Logf("%s server pod IP address: %s", config.Prefix, ip)
|
||||
return pod, ip
|
||||
}
|
||||
|
||||
@ -357,7 +356,7 @@ func StartVolumeServer(client clientset.Interface, config TestConfig) *v1.Pod {
|
||||
// ok if the server pod already exists. TODO: make this controllable by callers
|
||||
if err != nil {
|
||||
if apierrs.IsAlreadyExists(err) {
|
||||
e2elog.Logf("Ignore \"already-exists\" error, re-get pod...")
|
||||
framework.Logf("Ignore \"already-exists\" error, re-get pod...")
|
||||
ginkgo.By(fmt.Sprintf("re-getting the %q server pod", serverPodName))
|
||||
serverPod, err = podClient.Get(serverPodName, metav1.GetOptions{})
|
||||
framework.ExpectNoError(err, "Cannot re-get the server pod %q: %v", serverPodName, err)
|
||||
@ -395,17 +394,17 @@ func CleanUpVolumeServerWithSecret(f *framework.Framework, serverPod *v1.Pod, se
|
||||
ns := f.Namespace
|
||||
|
||||
if secret != nil {
|
||||
e2elog.Logf("Deleting server secret %q...", secret.Name)
|
||||
framework.Logf("Deleting server secret %q...", secret.Name)
|
||||
err := cs.CoreV1().Secrets(ns.Name).Delete(secret.Name, &metav1.DeleteOptions{})
|
||||
if err != nil {
|
||||
e2elog.Logf("Delete secret failed: %v", err)
|
||||
framework.Logf("Delete secret failed: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
e2elog.Logf("Deleting server pod %q...", serverPod.Name)
|
||||
framework.Logf("Deleting server pod %q...", serverPod.Name)
|
||||
err := framework.DeletePodWithWait(f, cs, serverPod)
|
||||
if err != nil {
|
||||
e2elog.Logf("Server pod delete failed: %v", err)
|
||||
framework.Logf("Server pod delete failed: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -549,7 +548,7 @@ func testVolumeContent(client clientset.Interface, pod *v1.Pod, fsGroup *int64,
|
||||
func TestVolumeClient(client clientset.Interface, config TestConfig, fsGroup *int64, fsType string, tests []Test) {
|
||||
clientPod, err := runVolumeTesterPod(client, config, "client", fsGroup, tests)
|
||||
if err != nil {
|
||||
e2elog.Failf("Failed to create client pod: %v", err)
|
||||
framework.Failf("Failed to create client pod: %v", err)
|
||||
|
||||
}
|
||||
framework.ExpectNoError(e2epod.WaitForPodRunningInNamespace(client, clientPod))
|
||||
@ -562,7 +561,7 @@ func TestVolumeClient(client clientset.Interface, config TestConfig, fsGroup *in
|
||||
func InjectContent(client clientset.Interface, config TestConfig, fsGroup *int64, fsType string, tests []Test) {
|
||||
injectorPod, err := runVolumeTesterPod(client, config, "injector", fsGroup, tests)
|
||||
if err != nil {
|
||||
e2elog.Failf("Failed to create injector pod: %v", err)
|
||||
framework.Failf("Failed to create injector pod: %v", err)
|
||||
return
|
||||
}
|
||||
defer func() {
|
||||
@ -676,7 +675,7 @@ func GenerateWriteandExecuteScriptFileCmd(content, fileName, filePath string) []
|
||||
fullPath := filepath.Join(filePath, scriptName)
|
||||
|
||||
cmd := "echo \"" + content + "\" > " + fullPath + "; .\\" + fullPath
|
||||
e2elog.Logf("generated pod command %s", cmd)
|
||||
framework.Logf("generated pod command %s", cmd)
|
||||
return []string{"powershell", "/c", cmd}
|
||||
}
|
||||
scriptName := fmt.Sprintf("%s.sh", fileName)
|
||||
|
Loading…
Reference in New Issue
Block a user