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

Fix handling of podman-remote stop --ignore #7697

Merged
merged 1 commit into from
Sep 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions pkg/domain/infra/tunnel/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (ic *ContainerEngine) ContainerExists(ctx context.Context, nameOrID string)
}

func (ic *ContainerEngine) ContainerWait(ctx context.Context, namesOrIds []string, options entities.WaitOptions) ([]entities.WaitReport, error) {
cons, err := getContainersByContext(ic.ClientCxt, false, namesOrIds)
cons, err := getContainersByContext(ic.ClientCxt, false, false, namesOrIds)
if err != nil {
return nil, err
}
Expand All @@ -54,7 +54,7 @@ func (ic *ContainerEngine) ContainerWait(ctx context.Context, namesOrIds []strin
}

func (ic *ContainerEngine) ContainerPause(ctx context.Context, namesOrIds []string, options entities.PauseUnPauseOptions) ([]*entities.PauseUnpauseReport, error) {
ctrs, err := getContainersByContext(ic.ClientCxt, options.All, namesOrIds)
ctrs, err := getContainersByContext(ic.ClientCxt, options.All, false, namesOrIds)
if err != nil {
return nil, err
}
Expand All @@ -67,7 +67,7 @@ func (ic *ContainerEngine) ContainerPause(ctx context.Context, namesOrIds []stri
}

func (ic *ContainerEngine) ContainerUnpause(ctx context.Context, namesOrIds []string, options entities.PauseUnPauseOptions) ([]*entities.PauseUnpauseReport, error) {
ctrs, err := getContainersByContext(ic.ClientCxt, options.All, namesOrIds)
ctrs, err := getContainersByContext(ic.ClientCxt, options.All, false, namesOrIds)
if err != nil {
return nil, err
}
Expand All @@ -89,8 +89,8 @@ func (ic *ContainerEngine) ContainerStop(ctx context.Context, namesOrIds []strin
id := strings.Split(string(content), "\n")[0]
namesOrIds = append(namesOrIds, id)
}
ctrs, err := getContainersByContext(ic.ClientCxt, options.All, namesOrIds)
if err != nil && !(options.Ignore && errors.Cause(err) == define.ErrNoSuchCtr) {
ctrs, err := getContainersByContext(ic.ClientCxt, options.All, options.Ignore, namesOrIds)
if err != nil {
return nil, err
}
for _, c := range ctrs {
Expand Down Expand Up @@ -120,7 +120,7 @@ func (ic *ContainerEngine) ContainerStop(ctx context.Context, namesOrIds []strin
}

func (ic *ContainerEngine) ContainerKill(ctx context.Context, namesOrIds []string, options entities.KillOptions) ([]*entities.KillReport, error) {
ctrs, err := getContainersByContext(ic.ClientCxt, options.All, namesOrIds)
ctrs, err := getContainersByContext(ic.ClientCxt, options.All, false, namesOrIds)
if err != nil {
return nil, err
}
Expand All @@ -144,7 +144,7 @@ func (ic *ContainerEngine) ContainerRestart(ctx context.Context, namesOrIds []st
timeout = &t
}

ctrs, err := getContainersByContext(ic.ClientCxt, options.All, namesOrIds)
ctrs, err := getContainersByContext(ic.ClientCxt, options.All, false, namesOrIds)
if err != nil {
return nil, err
}
Expand All @@ -169,8 +169,8 @@ func (ic *ContainerEngine) ContainerRm(ctx context.Context, namesOrIds []string,
id := strings.Split(string(content), "\n")[0]
namesOrIds = append(namesOrIds, id)
}
ctrs, err := getContainersByContext(ic.ClientCxt, options.All, namesOrIds)
if err != nil && !(options.Ignore && errors.Cause(err) == define.ErrNoSuchCtr) {
ctrs, err := getContainersByContext(ic.ClientCxt, options.All, options.Ignore, namesOrIds)
if err != nil {
return nil, err
}
// TODO there is no endpoint for container eviction. Need to discuss
Expand Down Expand Up @@ -283,7 +283,7 @@ func (ic *ContainerEngine) ContainerCheckpoint(ctx context.Context, namesOrIds [
)

if options.All {
allCtrs, err := getContainersByContext(ic.ClientCxt, true, []string{})
allCtrs, err := getContainersByContext(ic.ClientCxt, true, false, []string{})
if err != nil {
return nil, err
}
Expand All @@ -295,7 +295,7 @@ func (ic *ContainerEngine) ContainerCheckpoint(ctx context.Context, namesOrIds [
}

} else {
ctrs, err = getContainersByContext(ic.ClientCxt, false, namesOrIds)
ctrs, err = getContainersByContext(ic.ClientCxt, false, false, namesOrIds)
if err != nil {
return nil, err
}
Expand All @@ -317,7 +317,7 @@ func (ic *ContainerEngine) ContainerRestore(ctx context.Context, namesOrIds []st
ctrs = []entities.ListContainer{}
)
if options.All {
allCtrs, err := getContainersByContext(ic.ClientCxt, true, []string{})
allCtrs, err := getContainersByContext(ic.ClientCxt, true, false, []string{})
if err != nil {
return nil, err
}
Expand All @@ -329,7 +329,7 @@ func (ic *ContainerEngine) ContainerRestore(ctx context.Context, namesOrIds []st
}

} else {
ctrs, err = getContainersByContext(ic.ClientCxt, false, namesOrIds)
ctrs, err = getContainersByContext(ic.ClientCxt, false, false, namesOrIds)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -607,7 +607,7 @@ func (ic *ContainerEngine) ContainerCleanup(ctx context.Context, namesOrIds []st
}

func (ic *ContainerEngine) ContainerInit(ctx context.Context, namesOrIds []string, options entities.ContainerInitOptions) ([]*entities.ContainerInitReport, error) {
ctrs, err := getContainersByContext(ic.ClientCxt, options.All, namesOrIds)
ctrs, err := getContainersByContext(ic.ClientCxt, options.All, false, namesOrIds)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -647,7 +647,7 @@ func (ic *ContainerEngine) ContainerPort(ctx context.Context, nameOrID string, o
if len(nameOrID) > 0 {
namesOrIds = append(namesOrIds, nameOrID)
}
ctrs, err := getContainersByContext(ic.ClientCxt, options.All, namesOrIds)
ctrs, err := getContainersByContext(ic.ClientCxt, options.All, false, namesOrIds)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/domain/infra/tunnel/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/pkg/errors"
)

func getContainersByContext(contextWithConnection context.Context, all bool, namesOrIDs []string) ([]entities.ListContainer, error) {
func getContainersByContext(contextWithConnection context.Context, all, ignore bool, namesOrIDs []string) ([]entities.ListContainer, error) {
var (
cons []entities.ListContainer
)
Expand All @@ -36,7 +36,7 @@ func getContainersByContext(contextWithConnection context.Context, all bool, nam
break
}
}
if !found {
if !found && !ignore {
return nil, errors.Wrapf(define.ErrNoSuchCtr, "unable to find container %q", id)
}
}
Expand Down
2 changes: 0 additions & 2 deletions test/e2e/stop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ var _ = Describe("Podman stop", func() {
})

It("podman stop --ignore bogus container", func() {
SkipIfRemote()

session := podmanTest.RunTopContainer("")
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expand Down