mirror of https://github.com/containers/podman.git
				
				
				
			Add --replace flag to "podman container runlabel"
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1677908 Signed-off-by: Jhon Honce <jhonce@redhat.com>
This commit is contained in:
		
							parent
							
								
									8b3f759800
								
							
						
					
					
						commit
						504a0ff72f
					
				|  | @ -416,14 +416,15 @@ type RmiValues struct { | ||||||
| type RunlabelValues struct { | type RunlabelValues struct { | ||||||
| 	PodmanCommand | 	PodmanCommand | ||||||
| 	Authfile        string | 	Authfile        string | ||||||
| 	Display         bool |  | ||||||
| 	CertDir         string | 	CertDir         string | ||||||
| 	Creds           string | 	Creds           string | ||||||
|  | 	Display         bool | ||||||
| 	Name            string | 	Name            string | ||||||
| 	Opt1            string | 	Opt1            string | ||||||
| 	Opt2            string | 	Opt2            string | ||||||
| 	Opt3            string | 	Opt3            string | ||||||
| 	Quiet           bool | 	Quiet           bool | ||||||
|  | 	Replace         bool | ||||||
| 	SignaturePolicy string | 	SignaturePolicy string | ||||||
| 	TlsVerify       bool | 	TlsVerify       bool | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -10,9 +10,11 @@ import ( | ||||||
| 	"github.com/containers/libpod/cmd/podman/cliconfig" | 	"github.com/containers/libpod/cmd/podman/cliconfig" | ||||||
| 	"github.com/containers/libpod/cmd/podman/libpodruntime" | 	"github.com/containers/libpod/cmd/podman/libpodruntime" | ||||||
| 	"github.com/containers/libpod/cmd/podman/shared" | 	"github.com/containers/libpod/cmd/podman/shared" | ||||||
|  | 	"github.com/containers/libpod/libpod" | ||||||
| 	"github.com/containers/libpod/libpod/image" | 	"github.com/containers/libpod/libpod/image" | ||||||
| 	"github.com/containers/libpod/utils" | 	"github.com/containers/libpod/utils" | ||||||
| 	"github.com/pkg/errors" | 	"github.com/pkg/errors" | ||||||
|  | 	"github.com/sirupsen/logrus" | ||||||
| 	"github.com/spf13/cobra" | 	"github.com/spf13/cobra" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
|  | @ -45,6 +47,7 @@ func init() { | ||||||
| 	flags.StringVar(&runlabelCommand.CertDir, "cert-dir", "", "`Pathname` of a directory containing TLS certificates and keys") | 	flags.StringVar(&runlabelCommand.CertDir, "cert-dir", "", "`Pathname` of a directory containing TLS certificates and keys") | ||||||
| 	flags.StringVar(&runlabelCommand.Creds, "creds", "", "`Credentials` (USERNAME:PASSWORD) to use for authenticating to a registry") | 	flags.StringVar(&runlabelCommand.Creds, "creds", "", "`Credentials` (USERNAME:PASSWORD) to use for authenticating to a registry") | ||||||
| 	flags.BoolVar(&runlabelCommand.Display, "display", false, "Preview the command that the label would run") | 	flags.BoolVar(&runlabelCommand.Display, "display", false, "Preview the command that the label would run") | ||||||
|  | 	flags.BoolVar(&runlabelCommand.Replace, "replace", false, "Replace existing container with a new one from the image") | ||||||
| 	flags.StringVar(&runlabelCommand.Name, "name", "", "Assign a name to the container") | 	flags.StringVar(&runlabelCommand.Name, "name", "", "Assign a name to the container") | ||||||
| 
 | 
 | ||||||
| 	flags.StringVar(&runlabelCommand.Opt1, "opt1", "", "Optional parameter to pass for install") | 	flags.StringVar(&runlabelCommand.Opt1, "opt1", "", "Optional parameter to pass for install") | ||||||
|  | @ -146,10 +149,33 @@ func runlabelCmd(c *cliconfig.RunlabelValues) error { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| 	if !c.Quiet { | 	if !c.Quiet { | ||||||
| 		fmt.Printf("Command: %s\n", strings.Join(cmd, " ")) | 		fmt.Printf("command: %s\n", strings.Join(cmd, " ")) | ||||||
| 		if c.Display { | 		if c.Display { | ||||||
| 			return nil | 			return nil | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  | 
 | ||||||
|  | 	// If container already exists && --replace given -- Nuke it
 | ||||||
|  | 	if c.Replace { | ||||||
|  | 		for i, entry := range cmd { | ||||||
|  | 			if entry == "--name" { | ||||||
|  | 				name := cmd[i+1] | ||||||
|  | 				ctr, err := runtime.LookupContainer(name) | ||||||
|  | 				if err != nil { | ||||||
|  | 					if errors.Cause(err) != libpod.ErrNoSuchCtr { | ||||||
|  | 						logrus.Debugf("Error occurred searching for container %s: %s", name, err.Error()) | ||||||
|  | 						return err | ||||||
|  | 					} | ||||||
|  | 				} else { | ||||||
|  | 					logrus.Debugf("Runlabel --replace option given. Container %s will be deleted. The new container will be named %s", ctr.ID(), name) | ||||||
|  | 					if err := runtime.RemoveContainer(ctx, ctr, true, false); err != nil { | ||||||
|  | 						return err | ||||||
|  | 					} | ||||||
|  | 				} | ||||||
|  | 				break | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	return utils.ExecCmdWithStdStreams(stdIn, stdOut, stdErr, env, cmd[0], cmd[1:]...) | 	return utils.ExecCmdWithStdStreams(stdIn, stdOut, stdErr, env, cmd[0], cmd[1:]...) | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -2469,6 +2469,7 @@ _podman_container_runlabel() { | ||||||
| 	 -h | 	 -h | ||||||
| 	 -q | 	 -q | ||||||
| 	 --quiet | 	 --quiet | ||||||
|  | 	 --replace | ||||||
| 	 --tls-verify | 	 --tls-verify | ||||||
|   " |   " | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -12,6 +12,7 @@ podman-container-runlabel - Execute Image Label Method | ||||||
| [**--rootfs**=*ROOTFS*] | [**--rootfs**=*ROOTFS*] | ||||||
| [**--set**=*NAME*=*VALUE*] | [**--set**=*NAME*=*VALUE*] | ||||||
| [**--storage**] | [**--storage**] | ||||||
|  | [**--replace**] | ||||||
| LABEL IMAGE [ARG...] | LABEL IMAGE [ARG...] | ||||||
| 
 | 
 | ||||||
| # DESCRIPTION | # DESCRIPTION | ||||||
|  | @ -85,6 +86,11 @@ Print usage statement | ||||||
| 
 | 
 | ||||||
| Suppress output information when pulling images | Suppress output information when pulling images | ||||||
| 
 | 
 | ||||||
|  | **--replace** | ||||||
|  | 
 | ||||||
|  | If a container exists of the default or given name, as needed it will be stopped, deleted and a new container will be | ||||||
|  | created from this image. | ||||||
|  | 
 | ||||||
| **--signature-policy="PATHNAME"** | **--signature-policy="PATHNAME"** | ||||||
| 
 | 
 | ||||||
| Pathname of a signature policy file to use.  It is not recommended that this | Pathname of a signature policy file to use.  It is not recommended that this | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue