kubectl icon indicating copy to clipboard operation
kubectl copied to clipboard

goleak in RunNoErrOutput

Open Zeel-Patel opened this issue 1 year ago • 5 comments

What is the issue?

I am trying to write UTs for a function which internally calls cli.RunNoErrOutput(command)

cli -> "k8s.io/component-base/cli"

But there seems to be goleak

goleak: Errors on successful test run: found unexpected goroutines:
[Goroutine 25 in state select, with k8s.io/klog/v2.(*flushDaemon).run.func1 on top of the stack:
k8s.io/klog/v2.(*flushDaemon).run.func1()
	external/io_k8s_klog_v2/klog.go:1157 +0xec
created by k8s.io/klog/v2.(*flushDaemon).run in goroutine 43
	external/io_k8s_klog_v2/klog.go:1153 +0x19c
]

What can be possible reason?

How to reproduce?

Define run method

func run(args []string) error {
	command := cmd.NewDefaultKubectlCommandWithArgs(cmd.KubectlOptions{
		PluginHandler: cmd.NewDefaultPluginHandler(plugin.ValidPluginFilenamePrefixes),
		Arguments:     args,
		IOStreams:     genericclioptions.IOStreams{In: os.Stdin, Out: os.Stdout, ErrOut: os.Stderr},
		ConfigFlags: genericclioptions.NewConfigFlags(true).
			WithWrapConfigFn(func(c *rest.Config) *rest.Config {

				return c
			}),
	})
	return cli.RunNoErrOutput(command)
}

Define test for run() in test file

func Test_run(t *testing.T) {

	tests := []struct {
		name    string
		args    []string
		wantErr bool
	}{
		{
			name:    "success",
			args:    []string{"kubectl", "get", "--help"},
			wantErr: false,
		},
	}
	for _, test := range tests {
		t.Run(test.name, func(t *testing.T) {
			err := run(test.args)
			if test.wantErr {
				require.NotNil(t, err)
			} else {
				require.Nil(t, err)
			}
		})
	}
}

Run test, test run will fail with error above

Zeel-Patel avatar Feb 28 '24 16:02 Zeel-Patel

This issue is currently awaiting triage.

SIG CLI takes a lead on issue triage for this repo, but any Kubernetes member can accept issues by applying the triage/accepted label.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

k8s-ci-robot avatar Feb 28 '24 16:02 k8s-ci-robot

/sig cli

Zeel-Patel avatar Feb 28 '24 16:02 Zeel-Patel

/needs-information Please provide a method of reproduction so we can verify this and investigate further.

mpuckett159 avatar Feb 29 '24 00:02 mpuckett159

/triage needs-information

mpuckett159 avatar Feb 29 '24 00:02 mpuckett159

@mpuckett159 , edited the question with info.

Zeel-Patel avatar Feb 29 '24 03:02 Zeel-Patel

/close Closing the issue, this seems to be related to klog according to the output in the error trace (if I'm wrong please correct me) which is not something that SIG-CLI owns, this would be better suited in the kubernetes/klog repo, but as I also understand this is a fork of golang/glog, so this may be something to fix even farther upstream in that repo, I'm unsure. If the fix truly needs to happen in our code, we would accept a PR to fix it.

mpuckett159 avatar Mar 27 '24 22:03 mpuckett159

@mpuckett159: Closing this issue.

In response to this:

/close Closing the issue, this seems to be related to klog according to the output in the error trace (if I'm wrong please correct me) which is not something that SIG-CLI owns, this would be better suited in the kubernetes/klog repo, but as I also understand this is a fork of golang/glog, so this may be something to fix even farther upstream in that repo, I'm unsure. If the fix truly needs to happen in our code, we would accept a PR to fix it.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

k8s-ci-robot avatar Mar 27 '24 22:03 k8s-ci-robot