func()

in internal/kubectl.go [100:136]


func (c Kubectl) Copy(nsn types.NamespacedName, container string, path string, recordErr func(error)) (*io.PipeReader, error) {
	execErrOut := io.Discard
	if c.verbose {
		execErrOut = c.errOut
	}
	reader, outStream := io.Pipe()
	options := &exec.ExecOptions{
		StreamOptions: exec.StreamOptions{
			IOStreams: genericclioptions.IOStreams{
				In:     nil,
				Out:    outStream,
				ErrOut: execErrOut,
			},

			Namespace:     nsn.Namespace,
			PodName:       nsn.Name,
			ContainerName: container,
		},
		Config:    c.config,
		PodClient: c.CoreV1(),
		Command:   []string{"tar", "cf", "-", path},
		Executor:  &exec.DefaultRemoteExecutor{},
	}
	go func() {
		defer func() {
			// TODO: this routine never terminates in my experiments and this code never runs
			// we are effectively leaking go routines for every diagnostic we run
			outStream.Close()
		}()
		err := options.Run()
		if err != nil {
			recordErr(err)
			return
		}
	}()
	return reader, nil
}