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

exec command #27

Merged
merged 1 commit into from
Nov 20, 2019
Merged

exec command #27

merged 1 commit into from
Nov 20, 2019

Conversation

ksimon1
Copy link
Contributor

@ksimon1 ksimon1 commented Nov 19, 2019

this command can run user commands inside container.

We need this command, because kubevirtci needs to copy some files from container to host. And with this, we can copy these files to folder which is mounted in host and in container.
/cc @fromanirh
Signed-off-by: Karel Šimon ksimon@redhat.com

Copy link
Owner

@ffromani ffromani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd call this exec mimicing podman. Also, please describe in the commit message what is this command useful for.

@ksimon1 ksimon1 changed the title run-command command exec command Nov 19, 2019
cmd/exec.go Outdated Show resolved Hide resolved
cmd/exec.go Outdated Show resolved Hide resolved
cmd/exec.go Outdated
return err
}

return hnd.Exec(containerID, []string{execOpt.command}, os.Stdout)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...so this slice will always have len == 1
Is that what you want?

@ksimon1 ksimon1 force-pushed the run-command-command branch 2 times, most recently from 56497bd to ddc200c Compare November 19, 2019 12:09
Copy link
Owner

@ffromani ffromani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

almost there

exec := &cobra.Command{
Use: "exec",
Short: "exec runs given command in container",
RunE: execCommand,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd use

Args:  cobra.MinimumNArgs(1),

Copy link
Owner

@ffromani ffromani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Looking forward to learn how you want to use this.
We most likely need to update kubevirt/kubevirtci#183

@@ -64,6 +65,7 @@ func NewRunCommand() *cobra.Command {
run.Flags().UintVar(&okdRunOpts.sshWorkerPort, "ssh-worker-port", 0, "port on localhost to ssh to worker node")
run.Flags().BoolVar(&okdRunOpts.background, "background", false, "go to background after nodes are up")
run.Flags().BoolVar(&okdRunOpts.randomPorts, "random-ports", true, "expose all ports on random localhost ports")
run.Flags().StringVar(&okdRunOpts.volume, "volume", "", "Bind mount a volume into the container")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will be the volume automatically unbound? Do we need some cleanup?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still relevant

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine. But does this also mean that the more exec we do on a container, the more volumes we pile in? what does it happen if we do two pack8s exec one after the other? will it work? will it pile up temporary volumes in the container?
Each call of pack8s exec must be idenpotent and do proper cleanup after itself; is not OK to rely on external tools (e.g. kubevirtci scripts) to do cleaning, because it's fragile and leads to surprising (and most likely unwanted) results.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The volume is bind during start of container and persist till stop of container. It will not add or remove any volume during exec. I agree pack8s should handle cleanup and as i mentioned in previous comment, it removes all binded volumes with rm command

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% sure it's a good idea to have this volume bound between host and container, but since this is strictly for development and we are in the early stage of development, I'm incline to try it out and see how it looks.

cmd/exec.go Outdated
return err
}

return hnd.Exec(containerID, execOpt.commands, os.Stdout)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now that I see how you want to use this, I think --commands is bad UX.
First, it should be --command (singular), because exec can run just a single command - not more than one.
Second, we should not require it to be comma separated. It should be a regular shell line. The simplest way is probably to pass through args from line 31 in hnd.Exec() here on line 46, perhaps with some minimal massaging.
This can improved later, but we should have it before submitting the kubevirtci PR.

@@ -64,6 +65,7 @@ func NewRunCommand() *cobra.Command {
run.Flags().UintVar(&okdRunOpts.sshWorkerPort, "ssh-worker-port", 0, "port on localhost to ssh to worker node")
run.Flags().BoolVar(&okdRunOpts.background, "background", false, "go to background after nodes are up")
run.Flags().BoolVar(&okdRunOpts.randomPorts, "random-ports", true, "expose all ports on random localhost ports")
run.Flags().StringVar(&okdRunOpts.volume, "volume", "", "Bind mount a volume into the container")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still relevant

@ffromani ffromani self-requested a review November 20, 2019 08:45
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>
@ffromani
Copy link
Owner

I was expecting a flow like

bind volume
exec command
unbind volume

but actually adding a utility volume to the container is viable too. Let's try this out.

@ffromani ffromani merged commit 05455e9 into ffromani:master Nov 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants