Skip to content

Commit

Permalink
Set controller-runtime logger in inttest
Browse files Browse the repository at this point in the history
This suppresses log messages like the following:

    [controller-runtime] log.SetLogger(...) was never called; logs will not be displayed.
    Detected at:
    	>  goroutine 48 [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/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/log/log.go:60 +0xcd
    	>  sigs.k8s.io/controller-runtime/pkg/log.(*delegatingLogSink).WithName(0xc00034c0c0, {0x1b69724, 0x14})
    	>  	/home/runner/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/log/deleg.go:147 +0x45
    	>  github.com/go-logr/logr.Logger.WithName({{0x1de3cf0, 0xc00034c0c0}, 0x0}, {0x1b69724?, 0x1b57b4c?})
    	>  	/home/runner/go/pkg/mod/github.com/go-logr/[email protected]/logr.go:336 +0x3d
    	>  sigs.k8s.io/controller-runtime/pkg/client.newClient(0x531cde?, {0x0, 0xc000156540, {0x0, 0x0}, 0x0, {0x0, 0x0}, 0x0})
    	>  	/home/runner/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/client/client.go:122 +0xec
    	>  sigs.k8s.io/controller-runtime/pkg/client.New(0xc0003f7c70?, {0x0, 0xc000156540, {0x0, 0x0}, 0x0, {0x0, 0x0}, 0x0})
    	>  	/home/runner/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/client/client.go:103 +0x7d
    	>  github.com/k0sproject/k0s/inttest/addons.(*AddonsSuite).waitForTestRelease(0xc0004476c0, {0x1b5cb0b, 0xa}, {0x1b588f7, 0x5}, {0x1b59cd3, 0x7}, 0x1)
    	>  	/home/runner/work/k0s/k0s/inttest/addons/addons_test.go:129 +0x24a
    	>  github.com/k0sproject/k0s/inttest/addons.(*AddonsSuite).TestHelmBasedAddons(0xc0004476c0)
    	>  	/home/runner/work/k0s/k0s/inttest/addons/addons_test.go:57 +0x3b6
    	>  reflect.Value.call({0xc0003b7880?, 0xc00039c718?, 0x13?}, {0x1b583b1, 0x4}, {0xc0000d9e70, 0x1, 0x1?})
    	>  	/opt/hostedtoolcache/go/1.21.4/x64/src/reflect/value.go:596 +0xce7
    	>  reflect.Value.Call({0xc0003b7880?, 0xc00039c718?, 0xc0004476c0?}, {0xc000502e70?, 0x52c66d?, 0x2630f58?})
    	>  	/opt/hostedtoolcache/go/1.21.4/x64/src/reflect/value.go:380 +0xb9
    	>  github.com/stretchr/testify/suite.Run.func1(0xc0004621a0)
    	>  	/home/runner/go/pkg/mod/github.com/stretchr/[email protected]/suite/suite.go:197 +0x467
    	>  testing.tRunner(0xc0004621a0, 0xc0004081b0)
    	>  	/opt/hostedtoolcache/go/1.21.4/x64/src/testing/testing.go:1595 +0xff
    	>  created by testing.(*T).Run in goroutine 5
    	>  	/opt/hostedtoolcache/go/1.21.4/x64/src/testing/testing.go:1648 +0x3ad

Signed-off-by: Tom Wieczorek <[email protected]>
  • Loading branch information
twz123 committed Dec 7, 2023
1 parent b3ce700 commit f4825f0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ require (
github.com/estesp/manifest-tool/v2 v2.1.3
github.com/evanphx/json-patch v5.6.0+incompatible
github.com/fsnotify/fsnotify v1.7.0
github.com/go-logr/logr v1.2.4
github.com/go-openapi/jsonpointer v0.20.0
github.com/go-playground/validator/v10 v10.16.0
github.com/google/go-cmp v0.6.0
Expand Down Expand Up @@ -145,7 +146,6 @@ require (
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-errors/errors v1.4.2 // indirect
github.com/go-gorp/gorp/v3 v3.1.0 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.4 // indirect
Expand Down
14 changes: 9 additions & 5 deletions inttest/addons/addons_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,28 @@ import (
"testing"
"time"

"github.com/stretchr/testify/suite"

"github.com/k0sproject/k0s/internal/pkg/templatewriter"
"github.com/k0sproject/k0s/inttest/common"
"github.com/k0sproject/k0s/pkg/apis/helm/v1beta1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
k8s "k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/scheme"
"sigs.k8s.io/controller-runtime/pkg/client"
crlog "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/yaml"

"github.com/go-logr/logr/testr"
"github.com/stretchr/testify/suite"
)

type AddonsSuite struct {
common.BootlooseSuite
}

func (as *AddonsSuite) TestHelmBasedAddons() {
crlog.SetLogger(testr.New(as.T()))

addonName := "test-addon"
ociAddonName := "oci-addon"
fileAddonName := "tgz-addon"
Expand Down Expand Up @@ -100,7 +104,7 @@ func (as *AddonsSuite) deleteRelease(chart *v1beta1.Chart) {
as.Require().NoError(err)
as.Require().NoError(wait.PollUntilContextCancel(ctx, 1*time.Second, true, func(pollCtx context.Context) (done bool, err error) {
as.T().Logf("Expecting have no secrets left for release %s/%s", chart.Namespace, chart.Name)
items, err := k8sclient.CoreV1().Secrets("default").List(pollCtx, v1.ListOptions{
items, err := k8sclient.CoreV1().Secrets("default").List(pollCtx, metav1.ListOptions{
LabelSelector: fmt.Sprintf("name=%s", chart.Name),
})
if err != nil {
Expand Down Expand Up @@ -189,7 +193,7 @@ func (as *AddonsSuite) checkCustomValues(releaseName string) error {
}
return wait.PollUntilContextCancel(ctx, 1*time.Second, true, func(pollCtx context.Context) (done bool, err error) {
serverDeployment := fmt.Sprintf("%s-echo-server", releaseName)
d, err := kc.AppsV1().Deployments("default").Get(pollCtx, serverDeployment, v1.GetOptions{})
d, err := kc.AppsV1().Deployments("default").Get(pollCtx, serverDeployment, metav1.GetOptions{})
if err != nil {
if ctxErr := context.Cause(ctx); ctxErr != nil {
return false, errors.Join(err, ctxErr)
Expand Down

0 comments on commit f4825f0

Please sign in to comment.