Skip to content

Commit fb704d3

Browse files
authored
Merge pull request kubernetes#77184 from draveness/feature/refactor-logger
feat: add logger package in test e2e framework
2 parents 31d36d8 + f3d444d commit fb704d3

File tree

5 files changed

+67
-2
lines changed

5 files changed

+67
-2
lines changed

test/e2e/framework/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ filegroup(
154154
"//test/e2e/framework/gpu:all-srcs",
155155
"//test/e2e/framework/ingress:all-srcs",
156156
"//test/e2e/framework/job:all-srcs",
157+
"//test/e2e/framework/log:all-srcs",
157158
"//test/e2e/framework/metrics:all-srcs",
158159
"//test/e2e/framework/podlogs:all-srcs",
159160
"//test/e2e/framework/providers/aws:all-srcs",

test/e2e/framework/job/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ go_library(
2020
"//staging/src/k8s.io/apimachinery/pkg/util/wait:go_default_library",
2121
"//staging/src/k8s.io/client-go/kubernetes:go_default_library",
2222
"//test/e2e/framework:go_default_library",
23+
"//test/e2e/framework/log:go_default_library",
2324
],
2425
)
2526

test/e2e/framework/job/rest.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ import (
2020
"fmt"
2121

2222
batch "k8s.io/api/batch/v1"
23-
"k8s.io/api/core/v1"
23+
v1 "k8s.io/api/core/v1"
2424
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2525
"k8s.io/apimachinery/pkg/labels"
2626
"k8s.io/apimachinery/pkg/util/wait"
2727
clientset "k8s.io/client-go/kubernetes"
2828
"k8s.io/kubernetes/test/e2e/framework"
29+
e2elog "k8s.io/kubernetes/test/e2e/framework/log"
2930
)
3031

3132
// GetJob uses c to get the Job in namespace ns named name. If the returned error is nil, the returned Job is valid.
@@ -63,7 +64,7 @@ func UpdateJobWithRetries(c clientset.Interface, namespace, name string, applyUp
6364
// Apply the update, then attempt to push it to the apiserver.
6465
applyUpdate(job)
6566
if job, err = jobs.Update(job); err == nil {
66-
framework.Logf("Updating job %s", name)
67+
e2elog.Logf("Updating job %s", name)
6768
return true, nil
6869
}
6970
updateErr = err

test/e2e/framework/log/BUILD

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
load("@io_bazel_rules_go//go:def.bzl", "go_library")
2+
3+
go_library(
4+
name = "go_default_library",
5+
srcs = ["logger.go"],
6+
importpath = "k8s.io/kubernetes/test/e2e/framework/log",
7+
visibility = ["//visibility:public"],
8+
deps = [
9+
"//vendor/github.com/onsi/ginkgo:go_default_library",
10+
],
11+
)
12+
13+
filegroup(
14+
name = "package-srcs",
15+
srcs = glob(["**"]),
16+
tags = ["automanaged"],
17+
visibility = ["//visibility:private"],
18+
)
19+
20+
filegroup(
21+
name = "all-srcs",
22+
srcs = [":package-srcs"],
23+
tags = ["automanaged"],
24+
visibility = ["//visibility:public"],
25+
)

test/e2e/framework/log/logger.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
Copyright 2019 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package log
18+
19+
import (
20+
"fmt"
21+
"time"
22+
23+
"github.com/onsi/ginkgo"
24+
)
25+
26+
func nowStamp() string {
27+
return time.Now().Format(time.StampMilli)
28+
}
29+
30+
func log(level string, format string, args ...interface{}) {
31+
fmt.Fprintf(ginkgo.GinkgoWriter, nowStamp()+": "+level+": "+format+"\n", args...)
32+
}
33+
34+
// Logf logs the info.
35+
func Logf(format string, args ...interface{}) {
36+
log("INFO", format, args...)
37+
}

0 commit comments

Comments
 (0)