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

support dry-run for exec command #10252

Merged
merged 2 commits into from Feb 17, 2023
Merged

support dry-run for exec command #10252

merged 2 commits into from Feb 17, 2023

Conversation

glours
Copy link
Contributor

@glours glours commented Feb 8, 2023

What I did
Add support of dry run mode for exec command

Related issue
https://docker.atlassian.net/browse/ENV-55

(not mandatory) A picture of a cute animal, if possible in relation to what you did
image

Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com>
@glours glours self-assigned this Feb 8, 2023
@glours glours requested review from a team, nicksieger, ndeloof, StefanScherer, ulyssessouza, milas and laurazard and removed request for a team February 8, 2023 10:23
@codecov
Copy link

codecov bot commented Feb 8, 2023

Codecov Report

Base: 73.89% // Head: 72.79% // Decreases project coverage by -1.11% ⚠️

Coverage data is based on head (9765f17) compared to base (70ab9f8).
Patch has no changes to coverable lines.

Additional details and impacted files
@@            Coverage Diff             @@
##               v2   #10252      +/-   ##
==========================================
- Coverage   73.89%   72.79%   -1.11%     
==========================================
  Files           2        2              
  Lines         272      272              
==========================================
- Hits          201      198       -3     
- Misses         60       62       +2     
- Partials       11       12       +1     
Impacted Files Coverage Δ
pkg/e2e/framework.go 70.98% <0.00%> (-1.18%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

}

func (d *DryRunClient) ContainerExecStart(ctx context.Context, execID string, config moby.ExecStartCheck) error {
fmt.Printf("%sExecuting command in detach mode\n", DRYRUN_PREFIX)
Copy link
Contributor

Choose a reason for hiding this comment

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

why "in detach(ed) mode" ?
when starting exec command, you can't tell if client did/will attach or not

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When I tested all the potential cases, I identified that ContainerExecStart was only called when the detached mode is activated
https://github.com/docker/cli/blob/24b4924410dc1db788ce1ee59e2cc7fa8459f8b0/cli/command/container/exec.go#L139

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think it's worth having something like map[string]ExecDetails on the DryRunClient?

That way, ExecCreate could be silent, but here we could log out DRY-RUN Running command "rm -rf /" in app-svc-1.

(Don't feel strongly about this, also seems fine as-is!)

Copy link
Contributor

Choose a reason for hiding this comment

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

ContainerExecAttach in the client indeed calls the /start engine endpoint with Detach set but this can be used to distinguish detached mode.

Copy link
Contributor

Choose a reason for hiding this comment

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

@milas I've implemented suggested change with execDetails, could you please review ?

func (d *DryRunClient) ContainerExecCreate(ctx context.Context, container string, config moby.ExecConfig) (moby.IDResponse, error) {
fmt.Printf("%sCreating Exec configuration for container %s with command '%s'\n", DRYRUN_PREFIX, container, strings.Join(config.Cmd, " "))
config.Cmd = []string{"true"}
return d.apiClient.ContainerExecCreate(ctx, container, config)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be return nil?

I know we aren't starting the command here, but not sure of any other possible implications here

}

func (d *DryRunClient) ContainerExecStart(ctx context.Context, execID string, config moby.ExecStartCheck) error {
fmt.Printf("%sExecuting command in detach mode\n", DRYRUN_PREFIX)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think it's worth having something like map[string]ExecDetails on the DryRunClient?

That way, ExecCreate could be silent, but here we could log out DRY-RUN Running command "rm -rf /" in app-svc-1.

(Don't feel strongly about this, also seems fine as-is!)

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
@milas milas merged commit 762cf9d into docker:v2 Feb 17, 2023
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.

None yet

3 participants