diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-06-15 12:54:36 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-15 12:54:36 -0400 |
commit | 10c6c806ea6d7830c248d9c89cd5ec3a7a515a63 (patch) | |
tree | 837474da079889daa027b66e5239915dd983f7ab /cmd/podman/pods/create.go | |
parent | b89729778c253f0eccd2dd762e5d0a6547aaea7d (diff) | |
parent | 6118ab494884eea62c388fa1536349f05cdac9d3 (diff) | |
download | podman-10c6c806ea6d7830c248d9c89cd5ec3a7a515a63.tar.gz podman-10c6c806ea6d7830c248d9c89cd5ec3a7a515a63.tar.bz2 podman-10c6c806ea6d7830c248d9c89cd5ec3a7a515a63.zip |
Merge pull request #6553 from vrothberg/replace
--replace for containers and pods
Diffstat (limited to 'cmd/podman/pods/create.go')
-rw-r--r-- | cmd/podman/pods/create.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/cmd/podman/pods/create.go b/cmd/podman/pods/create.go index 51b7a7d52..835a62359 100644 --- a/cmd/podman/pods/create.go +++ b/cmd/podman/pods/create.go @@ -39,6 +39,7 @@ var ( createOptions entities.PodCreateOptions labels, labelFile []string podIDFile string + replace bool share string ) @@ -61,6 +62,7 @@ func init() { flags.StringVarP(&createOptions.Name, "name", "n", "", "Assign a name to the pod") flags.StringVarP(&createOptions.Hostname, "hostname", "", "", "Set a hostname to the pod") flags.StringVar(&podIDFile, "pod-id-file", "", "Write the pod ID to the file") + flags.BoolVar(&replace, "replace", false, "If a pod with the same exists, replace it") flags.StringVar(&share, "share", specgen.DefaultKernelNamespaces, "A comma delimited list of kernel namespaces the pod will share") flags.SetNormalizeFunc(aliasNetworkFlag) } @@ -147,6 +149,12 @@ func create(cmd *cobra.Command, args []string) error { } } + if replace { + if err := replacePod(createOptions.Name); err != nil { + return err + } + } + response, err := registry.ContainerEngine().PodCreate(context.Background(), createOptions) if err != nil { return err @@ -159,3 +167,14 @@ func create(cmd *cobra.Command, args []string) error { fmt.Println(response.Id) return nil } + +func replacePod(name string) error { + if len(name) == 0 { + return errors.New("cannot replace pod without --name being set") + } + rmOptions := entities.PodRmOptions{ + Force: true, // stop and remove pod + Ignore: true, // ignore if pod doesn't exist + } + return removePods([]string{name}, rmOptions, false) +} |