-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
this command can run user commands inside container. This feature will be used in kubevirtci to copy file within container into speacial folder which is mounted at the same time in container and host. With this we can copy files from container to host, without any hacks. Signed-off-by: Karel Šimon <ksimon@redhat.com>
- Loading branch information
Showing
3 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"os" | ||
|
||
"github.com/fromanirh/pack8s/internal/pkg/podman" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type execOptions struct { | ||
commands []string | ||
} | ||
|
||
var execOpt execOptions | ||
|
||
// NewExecCommand runs given command inside container | ||
func NewExecCommand() *cobra.Command { | ||
exec := &cobra.Command{ | ||
Use: "exec", | ||
Short: "exec runs given command in container", | ||
RunE: execCommand, | ||
} | ||
|
||
exec.Flags().StringArrayVar(&execOpt.commands, "commands", []string{}, "commands which will be executed in container") | ||
|
||
return exec | ||
} | ||
|
||
func execCommand(cmd *cobra.Command, args []string) error { | ||
containerID := args[0] | ||
|
||
podmanSocket, err := cmd.Flags().GetString("podman-socket") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
ctx := context.Background() | ||
|
||
hnd, err := podman.NewHandle(ctx, podmanSocket) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return hnd.Exec(containerID, execOpt.commands, os.Stdout) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters