aboutsummaryrefslogtreecommitdiff
path: root/cmd/podman
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/podman')
-rw-r--r--cmd/podman/containers/kill.go7
-rw-r--r--cmd/podman/containers/rm.go24
-rw-r--r--cmd/podman/containers/stop.go7
-rw-r--r--cmd/podman/kube/down.go39
-rw-r--r--cmd/podman/kube/play.go67
-rw-r--r--cmd/podman/system/info.go1
6 files changed, 111 insertions, 34 deletions
diff --git a/cmd/podman/containers/kill.go b/cmd/podman/containers/kill.go
index 5a5379389..c08b3abb6 100644
--- a/cmd/podman/containers/kill.go
+++ b/cmd/podman/containers/kill.go
@@ -49,7 +49,8 @@ var (
)
var (
- killOptions = entities.KillOptions{}
+ killOptions = entities.KillOptions{}
+ killCidFiles = []string{}
)
func killFlags(cmd *cobra.Command) {
@@ -61,7 +62,7 @@ func killFlags(cmd *cobra.Command) {
flags.StringVarP(&killOptions.Signal, signalFlagName, "s", "KILL", "Signal to send to the container")
_ = cmd.RegisterFlagCompletionFunc(signalFlagName, common.AutocompleteStopSignal)
cidfileFlagName := "cidfile"
- flags.StringArrayVar(&cidFiles, cidfileFlagName, []string{}, "Read the container ID from the file")
+ flags.StringArrayVar(&killCidFiles, cidfileFlagName, nil, "Read the container ID from the file")
_ = cmd.RegisterFlagCompletionFunc(cidfileFlagName, completion.AutocompleteDefault)
}
@@ -94,7 +95,7 @@ func kill(_ *cobra.Command, args []string) error {
if sig < 1 || sig > 64 {
return errors.New("valid signals are 1 through 64")
}
- for _, cidFile := range cidFiles {
+ for _, cidFile := range killCidFiles {
content, err := ioutil.ReadFile(cidFile)
if err != nil {
return fmt.Errorf("error reading CIDFile: %w", err)
diff --git a/cmd/podman/containers/rm.go b/cmd/podman/containers/rm.go
index 056e32651..1e3976389 100644
--- a/cmd/podman/containers/rm.go
+++ b/cmd/podman/containers/rm.go
@@ -52,8 +52,10 @@ var (
)
var (
- rmOptions = entities.RmOptions{}
- cidFiles = []string{}
+ rmOptions = entities.RmOptions{
+ Filters: make(map[string][]string),
+ }
+ rmCidFiles = []string{}
)
func rmFlags(cmd *cobra.Command) {
@@ -69,9 +71,13 @@ func rmFlags(cmd *cobra.Command) {
flags.BoolVarP(&rmOptions.Volumes, "volumes", "v", false, "Remove anonymous volumes associated with the container")
cidfileFlagName := "cidfile"
- flags.StringArrayVar(&cidFiles, cidfileFlagName, nil, "Read the container ID from the file")
+ flags.StringArrayVar(&rmCidFiles, cidfileFlagName, nil, "Read the container ID from the file")
_ = cmd.RegisterFlagCompletionFunc(cidfileFlagName, completion.AutocompleteDefault)
+ filterFlagName := "filter"
+ flags.StringSliceVar(&filters, filterFlagName, []string{}, "Filter output based on conditions given")
+ _ = cmd.RegisterFlagCompletionFunc(filterFlagName, common.AutocompletePsFilters)
+
if !registry.IsRemote() {
// This option is deprecated, but needs to still exists for backwards compatibility
flags.Bool("storage", false, "Remove container from storage library")
@@ -101,7 +107,7 @@ func rm(cmd *cobra.Command, args []string) error {
}
rmOptions.Timeout = &stopTimeout
}
- for _, cidFile := range cidFiles {
+ for _, cidFile := range rmCidFiles {
content, err := ioutil.ReadFile(cidFile)
if err != nil {
return fmt.Errorf("error reading CIDFile: %w", err)
@@ -110,6 +116,14 @@ func rm(cmd *cobra.Command, args []string) error {
args = append(args, id)
}
+ for _, f := range filters {
+ split := strings.SplitN(f, "=", 2)
+ if len(split) < 2 {
+ return fmt.Errorf("invalid filter %q", f)
+ }
+ rmOptions.Filters[split[0]] = append(rmOptions.Filters[split[0]], split[1])
+ }
+
if rmOptions.All {
logrus.Debug("--all is set: enforcing --depend=true")
rmOptions.Depend = true
@@ -147,7 +161,7 @@ func removeContainers(namesOrIDs []string, rmOptions entities.RmOptions, setExit
}
errs = append(errs, r.Err)
} else {
- fmt.Println(r.Id)
+ fmt.Println(r.RawInput)
}
}
return errs.PrintErrors()
diff --git a/cmd/podman/containers/stop.go b/cmd/podman/containers/stop.go
index 261f441c3..b0f449266 100644
--- a/cmd/podman/containers/stop.go
+++ b/cmd/podman/containers/stop.go
@@ -52,7 +52,8 @@ var (
stopOptions = entities.StopOptions{
Filters: make(map[string][]string),
}
- stopTimeout uint
+ stopCidFiles = []string{}
+ stopTimeout uint
)
func stopFlags(cmd *cobra.Command) {
@@ -62,7 +63,7 @@ func stopFlags(cmd *cobra.Command) {
flags.BoolVarP(&stopOptions.Ignore, "ignore", "i", false, "Ignore errors when a specified container is missing")
cidfileFlagName := "cidfile"
- flags.StringArrayVar(&cidFiles, cidfileFlagName, nil, "Read the container ID from the file")
+ flags.StringArrayVar(&stopCidFiles, cidfileFlagName, nil, "Read the container ID from the file")
_ = cmd.RegisterFlagCompletionFunc(cidfileFlagName, completion.AutocompleteDefault)
timeFlagName := "time"
@@ -103,7 +104,7 @@ func stop(cmd *cobra.Command, args []string) error {
if cmd.Flag("time").Changed {
stopOptions.Timeout = &stopTimeout
}
- for _, cidFile := range cidFiles {
+ for _, cidFile := range stopCidFiles {
content, err := ioutil.ReadFile(cidFile)
if err != nil {
return fmt.Errorf("error reading CIDFile: %w", err)
diff --git a/cmd/podman/kube/down.go b/cmd/podman/kube/down.go
new file mode 100644
index 000000000..b8c025928
--- /dev/null
+++ b/cmd/podman/kube/down.go
@@ -0,0 +1,39 @@
+package pods
+
+import (
+ "github.com/containers/podman/v4/cmd/podman/common"
+ "github.com/containers/podman/v4/cmd/podman/registry"
+ "github.com/spf13/cobra"
+)
+
+var (
+ downDescription = `Reads in a structured file of Kubernetes YAML.
+
+ Removes pods that have been based on the Kubernetes kind described in the YAML.`
+
+ downCmd = &cobra.Command{
+ Use: "down KUBEFILE|-",
+ Short: "Remove pods based on Kubernetes YAML.",
+ Long: downDescription,
+ RunE: down,
+ Args: cobra.ExactArgs(1),
+ ValidArgsFunction: common.AutocompleteDefaultOneArg,
+ Example: `podman kube down nginx.yml
+ cat nginx.yml | podman kube down -`,
+ }
+)
+
+func init() {
+ registry.Commands = append(registry.Commands, registry.CliCommand{
+ Command: downCmd,
+ Parent: kubeCmd,
+ })
+}
+
+func down(cmd *cobra.Command, args []string) error {
+ reader, err := readerFromArg(args[0])
+ if err != nil {
+ return err
+ }
+ return teardown(reader)
+}
diff --git a/cmd/podman/kube/play.go b/cmd/podman/kube/play.go
index 685cb521c..4811bcf4b 100644
--- a/cmd/podman/kube/play.go
+++ b/cmd/podman/kube/play.go
@@ -1,8 +1,10 @@
package pods
import (
+ "bytes"
"errors"
"fmt"
+ "io"
"net"
"os"
"strings"
@@ -37,9 +39,9 @@ var (
// https://kubernetes.io/docs/reference/command-line-tools-reference/kubelet/
defaultSeccompRoot = "/var/lib/kubelet/seccomp"
playOptions = playKubeOptionsWrapper{}
- playDescription = `Command reads in a structured file of Kubernetes YAML.
+ playDescription = `Reads in a structured file of Kubernetes YAML.
- It creates pods or volumes based on the Kubernetes kind described in the YAML. Supported kinds are Pods, Deployments and PersistentVolumeClaims.`
+ Creates pods or volumes based on the Kubernetes kind described in the YAML. Supported kinds are Pods, Deployments and PersistentVolumeClaims.`
playCmd = &cobra.Command{
Use: "play [options] KUBEFILE|-",
@@ -139,6 +141,7 @@ func playFlags(cmd *cobra.Command) {
downFlagName := "down"
flags.BoolVar(&playOptions.Down, downFlagName, false, "Stop pods defined in the YAML file")
+ _ = flags.MarkHidden("down")
replaceFlagName := "replace"
flags.BoolVar(&playOptions.Replace, replaceFlagName, false, "Delete and recreate pods defined in the YAML file")
@@ -223,10 +226,6 @@ func Play(cmd *cobra.Command, args []string) error {
}
playOptions.Annotations[splitN[0]] = annotation
}
- yamlfile := args[0]
- if yamlfile == "-" {
- yamlfile = "/dev/stdin"
- }
for _, mac := range playOptions.macs {
m, err := net.ParseMAC(mac)
@@ -235,36 +234,62 @@ func Play(cmd *cobra.Command, args []string) error {
}
playOptions.StaticMACs = append(playOptions.StaticMACs, m)
}
+
+ reader, err := readerFromArg(args[0])
+ if err != nil {
+ return err
+ }
+
if playOptions.Down {
- return teardown(yamlfile)
+ return teardown(reader)
}
+
if playOptions.Replace {
- if err := teardown(yamlfile); err != nil && !errorhandling.Contains(err, define.ErrNoSuchPod) {
+ if err := teardown(reader); err != nil && !errorhandling.Contains(err, define.ErrNoSuchPod) {
+ return err
+ }
+ if _, err := reader.Seek(0, 0); err != nil {
return err
}
}
- return kubeplay(yamlfile)
+ return kubeplay(reader)
}
func playKube(cmd *cobra.Command, args []string) error {
return Play(cmd, args)
}
-func teardown(yamlfile string) error {
+func readerFromArg(fileName string) (*bytes.Reader, error) {
+ if fileName == "-" { // Read from stdin
+ data, err := io.ReadAll(os.Stdin)
+ if err != nil {
+ return nil, err
+ }
+ return bytes.NewReader(data), nil
+ }
+ f, err := os.Open(fileName)
+ if err != nil {
+ return nil, err
+ }
+ defer f.Close()
+
+ data, err := io.ReadAll(f)
+ if err != nil {
+ return nil, err
+ }
+ return bytes.NewReader(data), nil
+}
+
+func teardown(body io.Reader) error {
var (
podStopErrors utils.OutputErrors
podRmErrors utils.OutputErrors
)
options := new(entities.PlayKubeDownOptions)
- f, err := os.Open(yamlfile)
+ reports, err := registry.ContainerEngine().PlayKubeDown(registry.GetContext(), body, *options)
if err != nil {
return err
}
- defer f.Close()
- reports, err := registry.ContainerEngine().PlayKubeDown(registry.GetContext(), f, *options)
- if err != nil {
- return fmt.Errorf("%v: %w", yamlfile, err)
- }
// Output stopped pods
fmt.Println("Pods stopped:")
@@ -290,19 +315,15 @@ func teardown(yamlfile string) error {
podRmErrors = append(podRmErrors, removed.Err)
}
}
+
return podRmErrors.PrintErrors()
}
-func kubeplay(yamlfile string) error {
- f, err := os.Open(yamlfile)
+func kubeplay(body io.Reader) error {
+ report, err := registry.ContainerEngine().PlayKube(registry.GetContext(), body, playOptions.PlayKubeOptions)
if err != nil {
return err
}
- defer f.Close()
- report, err := registry.ContainerEngine().PlayKube(registry.GetContext(), f, playOptions.PlayKubeOptions)
- if err != nil {
- return fmt.Errorf("%s: %w", yamlfile, err)
- }
// Print volumes report
for i, volume := range report.Volumes {
if i == 0 {
diff --git a/cmd/podman/system/info.go b/cmd/podman/system/info.go
index f8fd946cd..296fa4def 100644
--- a/cmd/podman/system/info.go
+++ b/cmd/podman/system/info.go
@@ -63,6 +63,7 @@ func infoFlags(cmd *cobra.Command) {
flags := cmd.Flags()
flags.BoolVarP(&debug, "debug", "D", false, "Display additional debug information")
+ _ = flags.MarkHidden("debug") // It's a NOP since Podman version 2.0
formatFlagName := "format"
flags.StringVarP(&inFormat, formatFlagName, "f", "", "Change the output format to JSON or a Go template")