Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Image import exec failure logs are hidden #1171

Closed
rhbuf opened this issue Oct 11, 2022 · 1 comment · Fixed by #1172
Closed

[BUG] Image import exec failure logs are hidden #1171

rhbuf opened this issue Oct 11, 2022 · 1 comment · Fixed by #1172
Labels
bug Something isn't working

Comments

@rhbuf
Copy link
Contributor

rhbuf commented Oct 11, 2022

What did you do

  • How was the cluster created?
k3d cluster create local
  • What did you do afterwards?
    Import a non-image tar into k3d to deliberately cause ctr to error
tar -cf test.tar README.md
k3d image import -c local -m direct test.tar

What did you expect to happen

I expected to see the error message from the exec appear in the logs from k3d, but it is shadowed by the err from reading the logs

func execInNode(ctx context.Context, node *k3d.Node, cmd []string, stdin io.ReadCloser) error {
execConnection, err := executeInNode(ctx, node, cmd, stdin)
if execConnection != nil {
defer execConnection.Close()
}
if err != nil {
if execConnection != nil && execConnection.Reader != nil {
logs, err := io.ReadAll(execConnection.Reader)
if err != nil {
return fmt.Errorf("failed to get logs from errored exec process in node '%s': %w", node.Name, err)
}
err = fmt.Errorf("%w: Logs from failed access process:\n%s", err, string(logs))
}
}
return err
}

Screenshots or terminal output

$ k3d image import -c local -m direct out.tar
INFO[0000] Importing image(s) into cluster 'local'      
INFO[0000] Importing images from 1 tarball(s)...        
INFO[0000] Importing images '[out.tar]' into node 'k3d-local-server-0'... 
ERRO[0008] Failed to import image(s) into cluster 'local': could not load image to cluster from stream out.tar: error loading image to cluster, first error: failed to import images in node 'k3d-local-server-0': Exec process in node 'k3d-local-server-0' failed with exit code '1' 
WARN[0008] At least one error occured while trying to import the image(s) into the selected cluster(s) 

Which OS & Architecture

arch: aarch64
cgroupdriver: cgroupfs
cgroupversion: "2"
endpoint: /var/run/docker.sock
filesystem: extfs
name: docker
os: Docker Desktop
ostype: linux
version: 20.10.17

Which version of k3d

k3d version v5.4.4
k3s version v1.23.8-k3s1 (default)

Which version of docker

$ docker version
Client: Docker Engine - Community
 Version:           20.10.18
 API version:       1.41
 Go version:        go1.19.1
 Git commit:        b40c2f6b5d
 Built:             Thu Sep  8 08:19:02 2022
 OS/Arch:           darwin/arm64
 Context:           default
 Experimental:      true

Server: Docker Desktop 4.12.0 (85629)
 Engine:
  Version:          20.10.17
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.17.11
  Git commit:       a89b842
  Built:            Mon Jun  6 23:01:01 2022
  OS/Arch:          linux/arm64
  Experimental:     false
 containerd:
  Version:          1.6.8
  GitCommit:        9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6
 runc:
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
@rhbuf rhbuf added the bug Something isn't working label Oct 11, 2022
@rhbuf
Copy link
Contributor Author

rhbuf commented Oct 11, 2022

The fix for this is to assign the error from reading the logs to its own variable:

diff --git a/pkg/runtimes/docker/node.go b/pkg/runtimes/docker/node.go
index 5ea6d05d..c73efca2 100644
--- a/pkg/runtimes/docker/node.go
+++ b/pkg/runtimes/docker/node.go
@@ -352,8 +352,8 @@ func execInNode(ctx context.Context, node *k3d.Node, cmd []string, stdin io.Read
 	}
 	if err != nil {
 		if execConnection != nil && execConnection.Reader != nil {
-			logs, err := io.ReadAll(execConnection.Reader)
-			if err != nil {
+			logs, logsErr := io.ReadAll(execConnection.Reader)
+			if logsErr != nil {
 				return fmt.Errorf("failed to get logs from errored exec process in node '%s': %w", node.Name, err)
 			}
 			err = fmt.Errorf("%w: Logs from failed access process:\n%s", err, string(logs))

then the output can be logged successfully:

$ ../k3d/bin/k3d image import -c local -m direct test.tar
INFO[0000] Importing image(s) into cluster 'local'      
INFO[0000] Importing images from 1 tarball(s)...        
INFO[0000] Importing images '[test.tar]' into node 'k3d-local-server-0'... 
ERRO[0001] Failed to import image(s) into cluster 'local': could not load image to cluster from stream test.tar: error loading image to cluster, first error: failed to import images in node 'k3d-local-server-0': Exec process in node 'k3d-local-server-0' failed with exit code '1': Logs from failed access process:
ctr: unrecognized image format 
WARN[0001] At least one error occured while trying to import the image(s) into the selected cluster(s)

I'll put up a PR to fix

rhbuf added a commit to rhbuf/k3d that referenced this issue Oct 11, 2022
The assignment from io.ReadAll was overwriting the value of the
original error and stopping the logs of the failed exec from being
printed

fixes k3d-io#1171
iwilltry42 pushed a commit that referenced this issue Dec 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant