summaryrefslogtreecommitdiff
path: root/pkg/domain/infra
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2021-05-06 14:50:26 -0400
committerGitHub <noreply@github.com>2021-05-06 14:50:26 -0400
commit034470e5be8cfeef8ce0e0d2f47587a660682219 (patch)
tree74af195993a2fd2136c980b8035629fe4863051d /pkg/domain/infra
parent44184167e495a64f1a565a2bc2cccb6b5bc56eaa (diff)
parentefdc7d84652bbdbf398c88d0287b0740f040a588 (diff)
downloadpodman-034470e5be8cfeef8ce0e0d2f47587a660682219.tar.gz
podman-034470e5be8cfeef8ce0e0d2f47587a660682219.tar.bz2
podman-034470e5be8cfeef8ce0e0d2f47587a660682219.zip
Merge pull request #9689 from boaz0/boaz-1
add restart-policy to container filters & --filter to podman start
Diffstat (limited to 'pkg/domain/infra')
-rw-r--r--pkg/domain/infra/abi/containers.go28
-rw-r--r--pkg/domain/infra/tunnel/containers.go25
2 files changed, 51 insertions, 2 deletions
diff --git a/pkg/domain/infra/abi/containers.go b/pkg/domain/infra/abi/containers.go
index ef3ccab0c..d0a2b1bae 100644
--- a/pkg/domain/infra/abi/containers.go
+++ b/pkg/domain/infra/abi/containers.go
@@ -694,7 +694,33 @@ func (ic *ContainerEngine) ContainerExecDetached(ctx context.Context, nameOrID s
func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []string, options entities.ContainerStartOptions) ([]*entities.ContainerStartReport, error) {
reports := []*entities.ContainerStartReport{}
var exitCode = define.ExecErrorCodeGeneric
- ctrs, rawInputs, err := getContainersAndInputByContext(options.All, options.Latest, namesOrIds, ic.Libpod)
+ containersNamesOrIds := namesOrIds
+ if len(options.Filters) > 0 {
+ filterFuncs := make([]libpod.ContainerFilter, 0, len(options.Filters))
+ if len(options.Filters) > 0 {
+ for k, v := range options.Filters {
+ generatedFunc, err := dfilters.GenerateContainerFilterFuncs(k, v, ic.Libpod)
+ if err != nil {
+ return nil, err
+ }
+ filterFuncs = append(filterFuncs, generatedFunc)
+ }
+ }
+ candidates, err := ic.Libpod.GetContainers(filterFuncs...)
+ if err != nil {
+ return nil, err
+ }
+ containersNamesOrIds = []string{}
+ for _, candidate := range candidates {
+ for _, nameOrID := range namesOrIds {
+ if nameOrID == candidate.ID() || nameOrID == candidate.Name() {
+ containersNamesOrIds = append(containersNamesOrIds, nameOrID)
+ }
+ }
+ }
+ }
+
+ ctrs, rawInputs, err := getContainersAndInputByContext(options.All, options.Latest, containersNamesOrIds, ic.Libpod)
if err != nil {
return nil, err
}
diff --git a/pkg/domain/infra/tunnel/containers.go b/pkg/domain/infra/tunnel/containers.go
index aa26825e0..3830835cc 100644
--- a/pkg/domain/infra/tunnel/containers.go
+++ b/pkg/domain/infra/tunnel/containers.go
@@ -506,7 +506,30 @@ func startAndAttach(ic *ContainerEngine, name string, detachKeys *string, input,
func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []string, options entities.ContainerStartOptions) ([]*entities.ContainerStartReport, error) {
reports := []*entities.ContainerStartReport{}
var exitCode = define.ExecErrorCodeGeneric
- ctrs, err := getContainersByContext(ic.ClientCtx, options.All, false, namesOrIds)
+ containersNamesOrIds := namesOrIds
+ if len(options.Filters) > 0 {
+ containersNamesOrIds = []string{}
+ opts := new(containers.ListOptions).WithFilters(options.Filters).WithAll(true)
+ candidates, listErr := containers.List(ic.ClientCtx, opts)
+ if listErr != nil {
+ return nil, listErr
+ }
+ for _, candidate := range candidates {
+ for _, nameOrID := range namesOrIds {
+ if nameOrID == candidate.ID {
+ containersNamesOrIds = append(containersNamesOrIds, nameOrID)
+ continue
+ }
+ for _, containerName := range candidate.Names {
+ if containerName == nameOrID {
+ containersNamesOrIds = append(containersNamesOrIds, nameOrID)
+ continue
+ }
+ }
+ }
+ }
+ }
+ ctrs, err := getContainersByContext(ic.ClientCtx, options.All, false, containersNamesOrIds)
if err != nil {
return nil, err
}