Skip to content

Commit b6c3a96

Browse files
authored
Merge pull request #11662 from sbueringer/pr-test-log-flags
🌱 Add log command line flags to e2e test binary
2 parents 5a7ab0b + a432c06 commit b6c3a96

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

test/e2e/e2e_suite_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ import (
3232
. "github.com/onsi/gomega"
3333
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3434
"k8s.io/apimachinery/pkg/runtime"
35+
"k8s.io/component-base/logs"
36+
logsv1 "k8s.io/component-base/logs/api/v1"
3537
"k8s.io/klog/v2"
3638
ctrl "sigs.k8s.io/controller-runtime"
3739

@@ -63,6 +65,8 @@ var (
6365

6466
// skipCleanup prevents cleanup of test resources e.g. for debug purposes.
6567
skipCleanup bool
68+
69+
logOptions = logs.NewOptions()
6670
)
6771

6872
// Test suite global vars.
@@ -94,11 +98,19 @@ func init() {
9498
flag.BoolVar(&skipCleanup, "e2e.skip-resource-cleanup", false, "if true, the resource cleanup after tests will be skipped")
9599
flag.StringVar(&clusterctlConfig, "e2e.clusterctl-config", "", "file which tests will use as a clusterctl config. If it is not set, a local clusterctl repository (including a clusterctl config) will be created automatically.")
96100
flag.BoolVar(&useExistingCluster, "e2e.use-existing-cluster", false, "if true, the test uses the current cluster instead of creating a new one (default discovery rules apply)")
101+
102+
logsv1.AddGoFlags(logOptions, flag.CommandLine)
97103
}
98104

99105
func TestE2E(t *testing.T) {
100106
g := NewWithT(t)
101107

108+
if err := logsv1.ValidateAndApply(logOptions, nil); err != nil {
109+
fmt.Printf("Unable to start tests: %v\n", err)
110+
os.Exit(1)
111+
}
112+
113+
// klog.Background will automatically use the right logger.
102114
ctrl.SetLogger(klog.Background())
103115

104116
// If running in prow, make sure to use the artifacts folder that will be reported in test grid (ignoring the value provided by flag).

0 commit comments

Comments
 (0)