summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile11
-rw-r--r--cmd/podman/common/completion.go48
-rw-r--r--cmd/podman/images/scp.go2
-rw-r--r--docs/source/markdown/podman-pod-ps.1.md1
-rw-r--r--pkg/api/server/register_pods.go13
-rw-r--r--pkg/domain/filters/pods.go11
-rw-r--r--test/apiv2/40-pods.at3
-rw-r--r--test/e2e/pod_ps_test.go16
-rw-r--r--test/e2e/run_device_test.go33
9 files changed, 109 insertions, 29 deletions
diff --git a/Makefile b/Makefile
index fbd15bac7..bda10d0bf 100644
--- a/Makefile
+++ b/Makefile
@@ -90,8 +90,7 @@ else
ISODATE ?= $(shell date --iso-8601)
endif
LIBPOD := ${PROJECT}/v3/libpod
-GCFLAGS ?= all=-trimpath=$(CURDIR)
-ASMFLAGS ?= all=-trimpath=$(CURDIR)
+GOFLAGS ?= -trimpath
LDFLAGS_PODMAN ?= \
-X $(LIBPOD)/define.gitCommit=$(GIT_COMMIT) \
-X $(LIBPOD)/define.buildInfo=$(BUILD_INFO) \
@@ -295,8 +294,6 @@ endif
CGO_ENABLED=$(CGO_ENABLED) \
$(GO) build \
$(BUILDFLAGS) \
- -gcflags '$(GCFLAGS)' \
- -asmflags '$(ASMFLAGS)' \
-ldflags '$(LDFLAGS_PODMAN)' \
-tags "$(BUILDTAGS)" \
-o $@ ./cmd/podman
@@ -310,8 +307,6 @@ $(SRCBINDIR)/podman$(BINSFX): $(SRCBINDIR) .gopathok $(SOURCES) go.mod go.sum
GOOS=$(GOOS) \
$(GO) build \
$(BUILDFLAGS) \
- -gcflags '$(GCFLAGS)' \
- -asmflags '$(ASMFLAGS)' \
-ldflags '$(LDFLAGS_PODMAN)' \
-tags "${REMOTETAGS}" \
-o $@ ./cmd/podman
@@ -321,8 +316,6 @@ $(SRCBINDIR)/podman-remote-static: $(SRCBINDIR) .gopathok $(SOURCES) go.mod go.s
GOOS=$(GOOS) \
$(GO) build \
$(BUILDFLAGS) \
- -gcflags '$(GCFLAGS)' \
- -asmflags '$(ASMFLAGS)' \
-ldflags '$(LDFLAGS_PODMAN_STATIC)' \
-tags "${REMOTETAGS}" \
-o $@ ./cmd/podman
@@ -376,8 +369,6 @@ bin/podman.cross.%: .gopathok
CGO_ENABLED=0 \
$(GO) build \
$(BUILDFLAGS) \
- -gcflags '$(GCFLAGS)' \
- -asmflags '$(ASMFLAGS)' \
-ldflags '$(LDFLAGS_PODMAN)' \
-tags '$(BUILDTAGS_CROSS)' \
-o "$@" ./cmd/podman
diff --git a/cmd/podman/common/completion.go b/cmd/podman/common/completion.go
index 08b2f6235..9a4524b46 100644
--- a/cmd/podman/common/completion.go
+++ b/cmd/podman/common/completion.go
@@ -323,6 +323,18 @@ func prefixSlice(pre string, slice []string) []string {
return slice
}
+func suffixCompSlice(suf string, slice []string) []string {
+ for i := range slice {
+ split := strings.SplitN(slice[i], "\t", 2)
+ if len(split) > 1 {
+ slice[i] = split[0] + suf + "\t" + split[1]
+ } else {
+ slice[i] = slice[i] + suf
+ }
+ }
+ return slice
+}
+
func completeKeyValues(toComplete string, k keyValueCompletion) ([]string, cobra.ShellCompDirective) {
suggestions := make([]string, 0, len(k))
directive := cobra.ShellCompDirectiveNoFileComp
@@ -664,6 +676,42 @@ func AutocompleteSystemConnections(cmd *cobra.Command, args []string, toComplete
return suggestions, cobra.ShellCompDirectiveNoFileComp
}
+// AutocompleteScp returns a list of connections, images, or both, depending on the amount of arguments
+func AutocompleteScp(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
+ if !validCurrentCmdLine(cmd, args, toComplete) {
+ return nil, cobra.ShellCompDirectiveNoFileComp
+ }
+ switch len(args) {
+ case 0:
+ split := strings.SplitN(toComplete, "::", 2)
+ if len(split) > 1 {
+ imageSuggestions, _ := getImages(cmd, split[1])
+ return prefixSlice(split[0]+"::", imageSuggestions), cobra.ShellCompDirectiveNoFileComp
+ }
+ connectionSuggestions, _ := AutocompleteSystemConnections(cmd, args, toComplete)
+ imageSuggestions, _ := getImages(cmd, toComplete)
+ totalSuggestions := append(suffixCompSlice("::", connectionSuggestions), imageSuggestions...)
+ directive := cobra.ShellCompDirectiveNoFileComp
+ // if we have connections do not add a space after the completion
+ if len(connectionSuggestions) > 0 {
+ directive = cobra.ShellCompDirectiveNoFileComp | cobra.ShellCompDirectiveNoSpace
+ }
+ return totalSuggestions, directive
+ case 1:
+ split := strings.SplitN(args[0], "::", 2)
+ if len(split) > 1 {
+ if len(split[1]) > 0 {
+ return nil, cobra.ShellCompDirectiveNoFileComp
+ }
+ imageSuggestions, _ := getImages(cmd, toComplete)
+ return imageSuggestions, cobra.ShellCompDirectiveNoFileComp
+ }
+ connectionSuggestions, _ := AutocompleteSystemConnections(cmd, args, toComplete)
+ return suffixCompSlice("::", connectionSuggestions), cobra.ShellCompDirectiveNoFileComp
+ }
+ return nil, cobra.ShellCompDirectiveNoFileComp
+}
+
/* -------------- Flags ----------------- */
// AutocompleteDetachKeys - Autocomplete detach-keys options.
diff --git a/cmd/podman/images/scp.go b/cmd/podman/images/scp.go
index a47d01995..176563440 100644
--- a/cmd/podman/images/scp.go
+++ b/cmd/podman/images/scp.go
@@ -33,7 +33,7 @@ var (
Short: "securely copy images",
RunE: scp,
Args: cobra.RangeArgs(1, 2),
- ValidArgsFunction: common.AutocompleteImages,
+ ValidArgsFunction: common.AutocompleteScp,
Example: `podman image scp myimage:latest otherhost::`,
}
)
diff --git a/docs/source/markdown/podman-pod-ps.1.md b/docs/source/markdown/podman-pod-ps.1.md
index 156adccaa..ed0789e93 100644
--- a/docs/source/markdown/podman-pod-ps.1.md
+++ b/docs/source/markdown/podman-pod-ps.1.md
@@ -98,6 +98,7 @@ Valid filters are listed below:
| id | [ID] Pod's ID (accepts regex) |
| name | [Name] Pod's name (accepts regex) |
| label | [Key] or [Key=Value] Label assigned to a container |
+| until | Only list pods created before given timestamp |
| status | Pod's status: `stopped`, `running`, `paused`, `exited`, `dead`, `created`, `degraded` |
| network | [Network] name or full ID of network |
| ctr-names | Container name within the pod (accepts regex) |
diff --git a/pkg/api/server/register_pods.go b/pkg/api/server/register_pods.go
index 3bcc50ba4..58234005e 100644
--- a/pkg/api/server/register_pods.go
+++ b/pkg/api/server/register_pods.go
@@ -17,7 +17,18 @@ func (s *APIServer) registerPodsHandlers(r *mux.Router) error {
// - in: query
// name: filters
// type: string
- // description: needs description and plumbing for filters
+ // description: |
+ // JSON encoded value of the filters (a map[string][]string) to process on the pods list. Available filters:
+ // - `id=<pod-id>` Matches all of pod id.
+ // - `label=<key>` or `label=<key>:<value>` Matches pods based on the presence of a label alone or a label and a value.
+ // - `name=<pod-name>` Matches all of pod name.
+ // - `until=<timestamp>` List pods created before this timestamp. The `<timestamp>` can be Unix timestamps, date formatted timestamps, or Go duration strings (e.g. `10m`, `1h30m`) computed relative to the daemon machine’s time.
+ // - `status=<pod-status>` Pod's status: `stopped`, `running`, `paused`, `exited`, `dead`, `created`, `degraded`.
+ // - `network=<pod-network>` Name or full ID of network.
+ // - `ctr-names=<pod-ctr-names>` Container name within the pod.
+ // - `ctr-ids=<pod-ctr-ids>` Container ID within the pod.
+ // - `ctr-status=<pod-ctr-status>` Container status within the pod.
+ // - `ctr-number=<pod-ctr-number>` Number of containers in the pod.
// responses:
// 200:
// $ref: "#/responses/ListPodsResponse"
diff --git a/pkg/domain/filters/pods.go b/pkg/domain/filters/pods.go
index 9a1c7d19d..9a2f0a3ba 100644
--- a/pkg/domain/filters/pods.go
+++ b/pkg/domain/filters/pods.go
@@ -116,6 +116,17 @@ func GeneratePodFilterFunc(filter string, filterValues []string) (
labels := p.Labels()
return util.MatchLabelFilters(filterValues, labels)
}, nil
+ case "until":
+ return func(p *libpod.Pod) bool {
+ until, err := util.ComputeUntilTimestamp(filterValues)
+ if err != nil {
+ return false
+ }
+ if p.CreatedTime().Before(until) {
+ return true
+ }
+ return false
+ }, nil
case "network":
return func(p *libpod.Pod) bool {
infra, err := p.InfraContainer()
diff --git a/test/apiv2/40-pods.at b/test/apiv2/40-pods.at
index 94c72dbaa..985b26411 100644
--- a/test/apiv2/40-pods.at
+++ b/test/apiv2/40-pods.at
@@ -19,6 +19,9 @@ t GET libpod/pods/json 200 \
.[0].Id=$pod_id \
.[0].Containers\|length=1
+t GET libpod/pods/json?filters='{"until":["500000"]}' 200 length=0
+t GET libpod/pods/json?filters='{"until":["5000000000"]}' 200 length=1
+
# Cannot create a dup pod with the same name
t POST "libpod/pods/create (dup pod)" name=foo 409 \
.cause="pod already exists"
diff --git a/test/e2e/pod_ps_test.go b/test/e2e/pod_ps_test.go
index c27539d6f..b4a0df904 100644
--- a/test/e2e/pod_ps_test.go
+++ b/test/e2e/pod_ps_test.go
@@ -108,6 +108,22 @@ var _ = Describe("Podman ps", func() {
Expect(result).Should(Exit(0))
})
+ It("podman pod ps --filter until", func() {
+ name := "mypod"
+ _, ec, _ := podmanTest.CreatePod(map[string][]string{"--name": {name}})
+ Expect(ec).To(Equal(0))
+
+ result := podmanTest.Podman([]string{"pod", "ps", "--filter", "until=50"})
+ result.WaitWithDefaultTimeout()
+ Expect(result).Should(Exit(0))
+ Expect(result.OutputToString()).To(Not(ContainSubstring(name)))
+
+ result = podmanTest.Podman([]string{"pod", "ps", "--filter", "until=5000000000"})
+ result.WaitWithDefaultTimeout()
+ Expect(result).Should(Exit(0))
+ Expect(result.OutputToString()).To(ContainSubstring(name))
+ })
+
It("podman pod ps filter name regexp", func() {
_, ec, podid := podmanTest.CreatePod(map[string][]string{"--name": {"mypod"}})
Expect(ec).To(Equal(0))
diff --git a/test/e2e/run_device_test.go b/test/e2e/run_device_test.go
index 40de1d50d..08905aed2 100644
--- a/test/e2e/run_device_test.go
+++ b/test/e2e/run_device_test.go
@@ -41,36 +41,35 @@ var _ = Describe("Podman run device", func() {
})
It("podman run device test", func() {
- session := podmanTest.Podman([]string{"run", "-q", "--security-opt", "label=disable", "--device", "/dev/kmsg", ALPINE, "ls", "--color=never", "/dev/kmsg"})
+ session := podmanTest.Podman([]string{"run", "-q", "--security-opt", "label=disable", "--device", "/dev/kmsg", ALPINE, "test", "-c", "/dev/kmsg"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
- Expect(session.OutputToString()).To(Equal("/dev/kmsg"))
})
It("podman run device rename test", func() {
- session := podmanTest.Podman([]string{"run", "-q", "--security-opt", "label=disable", "--device", "/dev/kmsg:/dev/kmsg1", ALPINE, "ls", "--color=never", "/dev/kmsg1"})
+ // TODO: Confirm absence of /dev/kmsg in container
+ session := podmanTest.Podman([]string{"run", "-q", "--security-opt", "label=disable", "--device", "/dev/kmsg:/dev/kmsg1", ALPINE, "test", "-c", "/dev/kmsg1"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
- Expect(session.OutputToString()).To(Equal("/dev/kmsg1"))
})
It("podman run device permission test", func() {
- session := podmanTest.Podman([]string{"run", "-q", "--security-opt", "label=disable", "--device", "/dev/kmsg:r", ALPINE, "ls", "--color=never", "/dev/kmsg"})
+ // TODO: Confirm write-permission failure
+ session := podmanTest.Podman([]string{"run", "-q", "--security-opt", "label=disable", "--device", "/dev/kmsg:r", ALPINE, "test", "-r", "/dev/kmsg"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
- Expect(session.OutputToString()).To(Equal("/dev/kmsg"))
})
It("podman run device rename and permission test", func() {
- session := podmanTest.Podman([]string{"run", "-q", "--security-opt", "label=disable", "--device", "/dev/kmsg:/dev/kmsg1:r", ALPINE, "ls", "--color=never", "/dev/kmsg1"})
+ // TODO: Confirm write-permission failure
+ session := podmanTest.Podman([]string{"run", "-q", "--security-opt", "label=disable", "--device", "/dev/kmsg:/dev/kmsg1:r", ALPINE, "test", "-r", "/dev/kmsg1"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
- Expect(session.OutputToString()).To(Equal("/dev/kmsg1"))
})
It("podman run device rename and bad permission test", func() {
- session := podmanTest.Podman([]string{"run", "-q", "--security-opt", "label=disable", "--device", "/dev/kmsg:/dev/kmsg1:rd", ALPINE, "ls", "--color=never", "/dev/kmsg1"})
+ session := podmanTest.Podman([]string{"run", "-q", "--security-opt", "label=disable", "--device", "/dev/kmsg:/dev/kmsg1:rd", ALPINE, "true"})
session.WaitWithDefaultTimeout()
- Expect(session).To(ExitWithError())
+ Expect(session).Should(Exit(125))
})
It("podman run device host device and container device parameter are directories", func() {
@@ -89,12 +88,13 @@ var _ = Describe("Podman run device", func() {
})
It("podman run device host device with --privileged", func() {
- if _, err := os.Stat("/dev/kvm"); err != nil {
- Skip("/dev/kvm not available")
- }
- session := podmanTest.Podman([]string{"run", "--privileged", ALPINE, "ls", "/dev/kvm"})
+ session := podmanTest.Podman([]string{"run", "--privileged", ALPINE, "test", "-c", "/dev/kmsg"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
+ // verify --privileged is required
+ session2 := podmanTest.Podman([]string{"run", ALPINE, "test", "-c", "/dev/kmsg"})
+ session2.WaitWithDefaultTimeout()
+ Expect(session2).Should((Exit(1)))
})
It("podman run CDI device test", func() {
@@ -109,14 +109,13 @@ var _ = Describe("Podman run device", func() {
err = cmd.Run()
Expect(err).To(BeNil())
- session := podmanTest.Podman([]string{"run", "-q", "--security-opt", "label=disable", "--device", "myKmsg", ALPINE, "ls", "--color=never", "/dev/kmsg1"})
+ session := podmanTest.Podman([]string{"run", "-q", "--security-opt", "label=disable", "--device", "myKmsg", ALPINE, "test", "-c", "/dev/kmsg1"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
- Expect(session.OutputToString()).To(Equal("/dev/kmsg1"))
})
It("podman run --gpus noop", func() {
- session := podmanTest.Podman([]string{"run", "--gpus", "all", ALPINE, "ls", "/"})
+ session := podmanTest.Podman([]string{"run", "--gpus", "all", ALPINE, "true"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
})