Skip to content

Commit

Permalink
add -E to version command
Browse files Browse the repository at this point in the history
Signed-off-by: Ang Zhou <[email protected]>
  • Loading branch information
azhouwd committed Mar 24, 2023
1 parent f37ec71 commit 95b2fa4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions cmd/finch/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ func (va *versionAction) printVersion() error {
if status != lima.Running {
return errors.New("detailed version info is unavailable because VM is not running")
}

limaArgs := []string{"shell", limaInstanceName, "sudo", "nerdctl", "version", "--format", "json"}
// Add -E to sudo command in order to preserve existing environment variables, more info:
// https://stackoverflow.com/questions/8633461/how-to-keep-environment-variables-when-using-sudo/8633575#8633575
limaArgs := []string{"shell", limaInstanceName, "sudo", "-E", "nerdctl", "version", "--format", "json"}
out, err := va.creator.CreateWithoutStdio(limaArgs...).Output()
if err != nil {
return fmt.Errorf("failed to create the nerdctl version command: %w", err)
Expand Down
4 changes: 2 additions & 2 deletions cmd/finch/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestVersionAction_runAdaptor(t *testing.T) {
logger.EXPECT().Debugf("Status of virtual machine: %s", "Running")

command := mocks.NewCommand(ctrl)
lcc.EXPECT().CreateWithoutStdio("shell", limaInstanceName, "sudo", "nerdctl", "version", "--format", "json").Return(command)
lcc.EXPECT().CreateWithoutStdio("shell", limaInstanceName, "sudo", "-E", "nerdctl", "version", "--format", "json").Return(command)
//nolint: lll // Version output format is larger than 500
command.EXPECT().Output().Return([]byte(`{"Client":{"Version":"v1.0.0","GitCommit":"c00780a1f5b905b09812722459c54936c9e070e6","GoVersion":"go1.19.2","Os":"linux","Arch":"arm64","Components":[{"Name":"buildctl","Version":"v0.10.5","Details":{"GitCommit":"bc26045116045516ff2427201abd299043eaf8f7"}}]},"Server":{"Components":[{"Name":"containerd","Version":"v1.6.8","Details":{"GitCommit":"9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6"}},{"Name":"runc","Version":"1.1.4","Details":{"GitCommit":"v1.1.4-0-g5fd4c4d1"}}]}}`), nil)
},
Expand Down Expand Up @@ -98,7 +98,7 @@ func TestVersionAction_run(t *testing.T) {
logger.EXPECT().Debugf("Status of virtual machine: %s", "Running")

command := mocks.NewCommand(ctrl)
lcc.EXPECT().CreateWithoutStdio("shell", limaInstanceName, "sudo", "nerdctl", "version", "--format", "json").Return(command)
lcc.EXPECT().CreateWithoutStdio("shell", limaInstanceName, "sudo", "-E", "nerdctl", "version", "--format", "json").Return(command)
command.EXPECT().Output().Return([]byte(`{
"Client":{
"Version":"v1.0.0",
Expand Down

0 comments on commit 95b2fa4

Please sign in to comment.