Skip to content

Commit

Permalink
e2e: Fix logger in e2e tests
Browse files Browse the repository at this point in the history
In e2e tests we can see the following error:
[controller-runtime] log.SetLogger(...) was never called; logs will not be displayed.
Detected at:
	>  goroutine 1 [running]:
	>  runtime/debug.Stack()
	>  	/opt/hostedtoolcache/go/1.21.4/x64/src/runtime/debug/stack.go:24 +0x5e
	>  sigs.k8s.io/controller-runtime/pkg/log.eventuallyFulfillRoot()
	>  	/home/runner/work/tetragon/tetragon/go/src/github.com/cilium/tetragon/vendor/sigs.k8s.io/controller-runtime/pkg/log/log.go:60 +0xcd
	>  sigs.k8s.io/controller-runtime/pkg/log.(*delegatingLogSink).WithName(0xc00027f740, {0x1ef22f6, 0x14})
	>  	/home/runner/work/tetragon/tetragon/go/src/github.com/cilium/tetragon/vendor/sigs.k8s.io/controller-runtime/pkg/log/deleg.go:147 +0x45
	>  github.com/go-logr/logr.Logger.WithName({{0x2208298, 0xc00027f740}, 0x0}, {0x1ef22f6?, 0x0?})
	>  	/home/runner/work/tetragon/tetragon/go/src/github.com/cilium/tetragon/vendor/github.com/go-logr/logr/logr.go:336 +0x3d
	>  sigs.k8s.io/controller-runtime/pkg/client.newClient(0x0?, {0x0, 0xc0002c2f50, {0x0, 0x0}, 0x0, {0x0, 0x0}, 0x0})
	>  	/home/runner/work/tetragon/tetragon/go/src/github.com/cilium/tetragon/vendor/sigs.k8s.io/controller-runtime/pkg/client/client.go:122 +0xec
	>  sigs.k8s.io/controller-runtime/pkg/client.New(0x50?, {0x0, 0xc0002c2f50, {0x0, 0x0}, 0x0, {0x0, 0x0}, 0x0})
	>  	/home/runner/work/tetragon/tetragon/go/src/github.com/cilium/tetragon/vendor/sigs.k8s.io/controller-runtime/pkg/client/client.go:103 +0x7d
	>  sigs.k8s.io/e2e-framework/klient/k8s/resources.New(0xc000804240)
	>  	/home/runner/work/tetragon/tetragon/go/src/github.com/cilium/tetragon/vendor/sigs.k8s.io/e2e-framework/klient/k8s/resources/resources.go:61 +0x79
	>  sigs.k8s.io/e2e-framework/klient.New(0xc000804240)
	>  	/home/runner/work/tetragon/tetragon/go/src/github.com/cilium/tetragon/vendor/sigs.k8s.io/e2e-framework/klient/client.go:51 +0x18
	>  sigs.k8s.io/e2e-framework/klient.NewWithKubeConfigFile({0xc0000e45c0?, 0x1b232c0?})
	>  	/home/runner/work/tetragon/tetragon/go/src/github.com/cilium/tetragon/vendor/sigs.k8s.io/e2e-framework/klient/client.go:64 +0x32
	>  sigs.k8s.io/e2e-framework/pkg/envconf.(*Config).Client(0xc00007e380)
	>  	/home/runner/work/tetragon/tetragon/go/src/github.com/cilium/tetragon/vendor/sigs.k8s.io/e2e-framework/pkg/envconf/config.go:137 +0x3c
	>  sigs.k8s.io/e2e-framework/pkg/envfuncs.CreateKindClusterWithConfig.func1({0x2202bc8, 0xc00001fd10}, 0xc00007e380)
	>  	/home/runner/work/tetragon/tetragon/go/src/github.com/cilium/tetragon/vendor/sigs.k8s.io/e2e-framework/pkg/envfuncs/kind_funcs.go:92 +0x27c
	>  github.com/cilium/tetragon/tests/e2e/runners.glob..func1.MaybeCreateTempKindCluster.func1({0x2202bc8, 0xc00001fd10}, 0x1d34ca0?)
	>  	/home/runner/work/tetragon/tetragon/go/src/github.com/cilium/tetragon/tests/e2e/helpers/cluster.go:149 +0x17e
	>  sigs.k8s.io/e2e-framework/pkg/env.(*action).run(0xc000285040?, {0x2202bc8?, 0xc00001fd10?}, 0xc00007e380)
	>  	/home/runner/work/tetragon/tetragon/go/src/github.com/cilium/tetragon/vendor/sigs.k8s.io/e2e-framework/pkg/env/action.go:135 +0xe3
	>  sigs.k8s.io/e2e-framework/pkg/env.(*testEnv).Run(0xc00027f6c0, 0x0?)
	>  	/home/runner/work/tetragon/tetragon/go/src/github.com/cilium/tetragon/vendor/sigs.k8s.io/e2e-framework/pkg/env/env.go:369 +0x152
	>  github.com/cilium/tetragon/tests/e2e/runners.(*Runner).Run(0xc00027f6c0?, 0xc0006063b0?)
	>  	/home/runner/work/tetragon/tetragon/go/src/github.com/cilium/tetragon/tests/e2e/runners/runners.go:210 +0xc8
	>  github.com/cilium/tetragon/tests/e2e/tests/labels_test.TestMain(0x1ed51c0?)
	>  	/home/runner/work/tetragon/tetragon/go/src/github.com/cilium/tetragon/tests/e2e/tests/labels/labels_test.go:92 +0xeb
	>  main.main()
	>  	_testmain.go:83 +0x1e6

Example: https://github.com/cilium/tetragon/actions/runs/6961675044/job/18943783744

This PR fixes that.

Signed-off-by: Anastasios Papagiannis <[email protected]>
  • Loading branch information
tpapagian committed Nov 29, 2023
1 parent e287ce8 commit 5bec879
Show file tree
Hide file tree
Showing 27 changed files with 1,843 additions and 178 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ require (
k8s.io/apimachinery v0.28.4
k8s.io/client-go v0.28.4
k8s.io/code-generator v0.28.4
k8s.io/klog/v2 v2.100.1
k8s.io/klog/v2 v2.110.1
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9
sigs.k8s.io/controller-runtime v0.16.3
sigs.k8s.io/controller-tools v0.13.0
Expand Down Expand Up @@ -83,7 +83,7 @@ require (
github.com/evanphx/json-patch v5.7.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/logr v1.3.0 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-openapi/analysis v0.21.4 // indirect
Expand Down
9 changes: 4 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,9 @@ github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V
github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas=
github.com/go-logr/logr v0.2.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU=
github.com/go-logr/logr v0.4.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU=
github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ=
github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY=
github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/go-logr/zapr v1.2.4 h1:QHVo+6stLbfJmYGkQ7uGHUCu5hnAFAj6mDe6Ea0SeOo=
Expand Down Expand Up @@ -1419,8 +1418,8 @@ k8s.io/gengo v0.0.0-20230829151522-9cce18d56c01/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAE
k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE=
k8s.io/klog/v2 v2.2.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y=
k8s.io/klog/v2 v2.8.0/go.mod h1:hy9LJ/NvuK+iVyP4Ehqva4HxZG/oXyIS3n3Jmire4Ec=
k8s.io/klog/v2 v2.100.1 h1:7WCHKK6K8fNhTqfBhISHQ97KrnJNFZMcQvKp7gP/tmg=
k8s.io/klog/v2 v2.100.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0=
k8s.io/klog/v2 v2.110.1 h1:U/Af64HJf7FcwMcXyKm2RPM22WZzyR7OSpYj5tg3cL0=
k8s.io/klog/v2 v2.110.1/go.mod h1:YGtd1984u+GgbuZ7e08/yBuAfKLSO0+uR1Fhi6ExXjo=
k8s.io/kube-openapi v0.0.0-20210305001622-591a79e4bda7/go.mod h1:wXW5VT87nVfh/iLV8FpR2uDvrFyomxbtb1KivDbvPTE=
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 h1:LyMgNKD2P8Wn1iAwQU5OhxCKlKJy0sHc+PcDwFB24dQ=
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9/go.mod h1:wZK2AVp1uHCp4VamDVgBP2COHZjqD1T68Rf0CM3YjSM=
Expand Down
10 changes: 9 additions & 1 deletion tests/e2e/runners/runners.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
appsv1 "k8s.io/api/apps/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/klog/v2"
"k8s.io/klog/v2/textlogger"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/e2e-framework/pkg/env"
"sigs.k8s.io/e2e-framework/pkg/envconf"
"sigs.k8s.io/e2e-framework/pkg/features"
Expand Down Expand Up @@ -134,9 +136,15 @@ func (r *Runner) Init() *Runner {
}
r.hasCalledInit = true

config := textlogger.NewConfig(
textlogger.Verbosity(4), // Matches Kubernetes "debug" level.
textlogger.Output(os.Stdout),
)
log.SetLogger(textlogger.NewLogger(config))

cfg, err := envconf.NewFromFlags()
if err != nil {
klog.Fatalf("Failed to configure test environment: %w", err)
klog.Fatalf("Failed to configure test environment")
}
klog.Info("IMPORTANT: Tetragon e2e tests require parallel tests enabled. User preferences will be ignored.")
cfg = cfg.WithParallelTestEnabled()
Expand Down
113 changes: 112 additions & 1 deletion vendor/github.com/go-logr/logr/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions vendor/github.com/go-logr/logr/SECURITY.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5bec879

Please sign in to comment.