Skip to content

Commit

Permalink
Fix --arch and --os flags to work correctly
Browse files Browse the repository at this point in the history
Currently podman implements --override-arch and --overide-os
But Podman has made these aliases for --arch and --os.  No
reason to have to specify --override, since it is clear what
the user intends.

Currently if the user specifies an --override-arch field but the
image was previously pulled for a different Arch, podman run uses
the different arch.  This PR also fixes this issue.

Fixes: containers#8001

Signed-off-by: Daniel J Walsh <[email protected]>
  • Loading branch information
rhatdan authored and mheon committed Feb 8, 2021
1 parent 7c05d52 commit 5da474d
Show file tree
Hide file tree
Showing 19 changed files with 152 additions and 143 deletions.
26 changes: 13 additions & 13 deletions cmd/podman/common/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,29 +474,29 @@ func DefineCreateFlags(cmd *cobra.Command, cf *ContainerCLIOpts) {
)
_ = cmd.RegisterFlagCompletionFunc(oomScoreAdjFlagName, completion.AutocompleteNone)

overrideArchFlagName := "override-arch"
archFlagName := "arch"
createFlags.StringVar(
&cf.OverrideArch,
overrideArchFlagName, "",
&cf.Arch,
archFlagName, "",
"use `ARCH` instead of the architecture of the machine for choosing images",
)
_ = cmd.RegisterFlagCompletionFunc(overrideArchFlagName, completion.AutocompleteNone)
_ = cmd.RegisterFlagCompletionFunc(archFlagName, completion.AutocompleteArch)

overrideOSFlagName := "override-os"
osFlagName := "os"
createFlags.StringVar(
&cf.OverrideOS,
overrideOSFlagName, "",
&cf.OS,
osFlagName, "",
"use `OS` instead of the running OS for choosing images",
)
_ = cmd.RegisterFlagCompletionFunc(overrideOSFlagName, completion.AutocompleteNone)
_ = cmd.RegisterFlagCompletionFunc(osFlagName, completion.AutocompleteOS)

overrideVariantFlagName := "override-variant"
variantFlagName := "variant"
createFlags.StringVar(
&cf.OverrideVariant,
overrideVariantFlagName, "",
&cf.Variant,
variantFlagName, "",
"Use _VARIANT_ instead of the running architecture variant for choosing images",
)
_ = cmd.RegisterFlagCompletionFunc(overrideVariantFlagName, completion.AutocompleteNone)
_ = cmd.RegisterFlagCompletionFunc(variantFlagName, completion.AutocompleteNone)

pidFlagName := "pid"
createFlags.String(
Expand All @@ -516,7 +516,7 @@ func DefineCreateFlags(cmd *cobra.Command, cf *ContainerCLIOpts) {
createFlags.StringVar(
&cf.Platform,
platformFlagName, "",
"Specify the platform for selecting the image. (Conflicts with override-arch and override-os)",
"Specify the platform for selecting the image. (Conflicts with --arch and --os)",
)
_ = cmd.RegisterFlagCompletionFunc(platformFlagName, completion.AutocompleteNone)

Expand Down
12 changes: 6 additions & 6 deletions cmd/podman/common/create_opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ type ContainerCLIOpts struct {
NoHealthCheck bool
OOMKillDisable bool
OOMScoreAdj int
OverrideArch string
OverrideOS string
OverrideVariant string
Arch string
OS string
Variant string
PID string
PIDsLimit *int64
Platform string
Expand Down Expand Up @@ -347,9 +347,9 @@ func ContainerCreateToContainerCLIOpts(cc handlers.CreateContainerConfig, cgroup
LogOptions: stringMaptoArray(cc.HostConfig.LogConfig.Config),
Name: cc.Name,
OOMScoreAdj: cc.HostConfig.OomScoreAdj,
OverrideArch: "",
OverrideOS: "",
OverrideVariant: "",
Arch: "",
OS: "",
Variant: "",
PID: string(cc.HostConfig.PidMode),
PIDsLimit: cc.HostConfig.PidsLimit,
Privileged: cc.HostConfig.Privileged,
Expand Down
27 changes: 15 additions & 12 deletions cmd/podman/containers/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,17 +237,20 @@ func pullImage(imageName string) (string, error) {
imageMissing = !br.Value
}

if cliVals.Platform != "" {
if cliVals.OverrideArch != "" || cliVals.OverrideOS != "" {
return "", errors.Errorf("--platform option can not be specified with --override-arch or --override-os")
}
split := strings.SplitN(cliVals.Platform, "/", 2)
cliVals.OverrideOS = split[0]
if len(split) > 1 {
cliVals.OverrideArch = split[1]
if cliVals.Platform != "" || cliVals.Arch != "" || cliVals.OS != "" {
if cliVals.Platform != "" {
if cliVals.Arch != "" || cliVals.OS != "" {
return "", errors.Errorf("--platform option can not be specified with --arch or --os")
}
split := strings.SplitN(cliVals.Platform, "/", 2)
cliVals.OS = split[0]
if len(split) > 1 {
cliVals.Arch = split[1]
}
}

if pullPolicy != config.PullImageAlways {
logrus.Info("--platform causes the pull policy to be \"always\"")
logrus.Info("--platform --arch and --os causes the pull policy to be \"always\"")
pullPolicy = config.PullImageAlways
}
}
Expand All @@ -259,9 +262,9 @@ func pullImage(imageName string) (string, error) {
pullReport, pullErr := registry.ImageEngine().Pull(registry.GetContext(), imageName, entities.ImagePullOptions{
Authfile: cliVals.Authfile,
Quiet: cliVals.Quiet,
OverrideArch: cliVals.OverrideArch,
OverrideOS: cliVals.OverrideOS,
OverrideVariant: cliVals.OverrideVariant,
Arch: cliVals.Arch,
OS: cliVals.OS,
Variant: cliVals.Variant,
SignaturePolicy: cliVals.SignaturePolicy,
PullPolicy: pullPolicy,
})
Expand Down
28 changes: 14 additions & 14 deletions cmd/podman/images/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,20 @@ func pullFlags(cmd *cobra.Command) {
flags.StringVar(&pullOptions.CredentialsCLI, credsFlagName, "", "`Credentials` (USERNAME:PASSWORD) to use for authenticating to a registry")
_ = cmd.RegisterFlagCompletionFunc(credsFlagName, completion.AutocompleteNone)

overrideArchFlagName := "override-arch"
flags.StringVar(&pullOptions.OverrideArch, overrideArchFlagName, "", "Use `ARCH` instead of the architecture of the machine for choosing images")
_ = cmd.RegisterFlagCompletionFunc(overrideArchFlagName, completion.AutocompleteNone)
archFlagName := "arch"
flags.StringVar(&pullOptions.Arch, archFlagName, "", "Use `ARCH` instead of the architecture of the machine for choosing images")
_ = cmd.RegisterFlagCompletionFunc(archFlagName, completion.AutocompleteArch)

overrideOsFlagName := "override-os"
flags.StringVar(&pullOptions.OverrideOS, overrideOsFlagName, "", "Use `OS` instead of the running OS for choosing images")
_ = cmd.RegisterFlagCompletionFunc(overrideOsFlagName, completion.AutocompleteNone)
osFlagName := "os"
flags.StringVar(&pullOptions.OS, osFlagName, "", "Use `OS` instead of the running OS for choosing images")
_ = cmd.RegisterFlagCompletionFunc(osFlagName, completion.AutocompleteOS)

overrideVariantFlagName := "override-variant"
flags.StringVar(&pullOptions.OverrideVariant, overrideVariantFlagName, "", " use VARIANT instead of the running architecture variant for choosing images")
_ = cmd.RegisterFlagCompletionFunc(overrideVariantFlagName, completion.AutocompleteNone)
variantFlagName := "variant"
flags.StringVar(&pullOptions.Variant, variantFlagName, "", " use VARIANT instead of the running architecture variant for choosing images")
_ = cmd.RegisterFlagCompletionFunc(variantFlagName, completion.AutocompleteNone)

platformFlagName := "platform"
flags.String(platformFlagName, "", "Specify the platform for selecting the image. (Conflicts with override-arch and override-os)")
flags.String(platformFlagName, "", "Specify the platform for selecting the image. (Conflicts with arch and os)")
_ = cmd.RegisterFlagCompletionFunc(platformFlagName, completion.AutocompleteNone)

flags.Bool("disable-content-trust", false, "This is a Docker specific option and is a NOOP")
Expand Down Expand Up @@ -138,13 +138,13 @@ func imagePull(cmd *cobra.Command, args []string) error {
return err
}
if platform != "" {
if pullOptions.OverrideArch != "" || pullOptions.OverrideOS != "" {
return errors.Errorf("--platform option can not be specified with --override-arch or --override-os")
if pullOptions.Arch != "" || pullOptions.OS != "" {
return errors.Errorf("--platform option can not be specified with --arch or --os")
}
split := strings.SplitN(platform, "/", 2)
pullOptions.OverrideOS = split[0]
pullOptions.OS = split[0]
if len(split) > 1 {
pullOptions.OverrideArch = split[1]
pullOptions.Arch = split[1]
}
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/podman/manifest/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func init() {

archFlagName := "arch"
flags.StringVar(&manifestAddOpts.Arch, archFlagName, "", "override the `architecture` of the specified image")
_ = addCmd.RegisterFlagCompletionFunc(archFlagName, completion.AutocompleteNone)
_ = addCmd.RegisterFlagCompletionFunc(archFlagName, completion.AutocompleteArch)

authfileFlagName := "authfile"
flags.StringVar(&manifestAddOpts.Authfile, authfileFlagName, auth.GetDefaultAuthFile(), "path of the authentication file. Use REGISTRY_AUTH_FILE environment variable to override")
Expand All @@ -72,7 +72,7 @@ func init() {

osFlagName := "os"
flags.StringVar(&manifestAddOpts.OS, osFlagName, "", "override the `OS` of the specified image")
_ = addCmd.RegisterFlagCompletionFunc(osFlagName, completion.AutocompleteNone)
_ = addCmd.RegisterFlagCompletionFunc(osFlagName, completion.AutocompleteOS)

osVersionFlagName := "os-version"
flags.StringVar(&manifestAddOpts.OSVersion, osVersionFlagName, "", "override the OS `version` of the specified image")
Expand Down
4 changes: 2 additions & 2 deletions cmd/podman/manifest/annotate.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ func init() {

archFlagName := "arch"
flags.StringVar(&manifestAnnotateOpts.Arch, archFlagName, "", "override the `architecture` of the specified image")
_ = annotateCmd.RegisterFlagCompletionFunc(archFlagName, completion.AutocompleteNone)
_ = annotateCmd.RegisterFlagCompletionFunc(archFlagName, completion.AutocompleteArch)

featuresFlagName := "features"
flags.StringSliceVar(&manifestAnnotateOpts.Features, featuresFlagName, nil, "override the `features` of the specified image")
_ = annotateCmd.RegisterFlagCompletionFunc(featuresFlagName, completion.AutocompleteNone)

osFlagName := "os"
flags.StringVar(&manifestAnnotateOpts.OS, osFlagName, "", "override the `OS` of the specified image")
_ = annotateCmd.RegisterFlagCompletionFunc(osFlagName, completion.AutocompleteNone)
_ = annotateCmd.RegisterFlagCompletionFunc(osFlagName, completion.AutocompleteOS)

osFeaturesFlagName := "os-features"
flags.StringSliceVar(&manifestAnnotateOpts.OSFeatures, osFeaturesFlagName, nil, "override the OS `features` of the specified image")
Expand Down
6 changes: 6 additions & 0 deletions cmd/podman/utils/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ func AliasFlags(f *pflag.FlagSet, name string) pflag.NormalizedName {
name = "external"
case "purge":
name = "rm"
case "override-arch":
name = "arch"
case "override-os":
name = "os"
case "override-variant":
name = "variant"
}
return pflag.NormalizedName(name)
}
16 changes: 8 additions & 8 deletions docs/source/markdown/podman-create.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ option can be set multiple times.
Add an annotation to the container. The format is key=value.
The **--annotation** option can be set multiple times.

#### **--arch**=*ARCH*
Override the architecture, defaults to hosts, of the image to be pulled. For example, `arm`.

#### **--attach**, **-a**=*location*

Attach to STDIN, STDOUT or STDERR.
Expand Down Expand Up @@ -668,15 +671,9 @@ Whether to disable OOM Killer for the container or not.

Tune the host's OOM preferences for containers (accepts -1000 to 1000)

#### **--override-arch**=*ARCH*
Override the architecture, defaults to hosts, of the image to be pulled. For example, `arm`.

#### **--override-os**=*OS*
#### **--os**=*OS*
Override the OS, defaults to hosts, of the image to be pulled. For example, `windows`.

#### **--override-variant**=*VARIANT*
Use _VARIANT_ instead of the default architecture variant of the container image. Some images can use multiple variants of the arm architectures, such as arm/v5 and arm/v7.

#### **--pid**=*pid*

Set the PID mode for the container
Expand All @@ -692,7 +689,7 @@ Tune the container's pids limit. Set `0` to have unlimited pids for the containe

#### **--platform**=*OS/ARCH*

Specify the platform for selecting the image. (Conflicts with override-arch and override-os)
Specify the platform for selecting the image. (Conflicts with --arch and --os)
The `--platform` option can be used to override the current architecture and operating system.

#### **--pod**=*name*
Expand Down Expand Up @@ -1008,6 +1005,9 @@ Set the UTS namespace mode for the container. The following values are supported
- **ns:[path]**: run the container in the given existing UTS namespace.
- **container:[container]**: join the UTS namespace of the specified container.

#### **--variant**=*VARIANT*
Use _VARIANT_ instead of the default architecture variant of the container image. Some images can use multiple variants of the arm architectures, such as arm/v5 and arm/v7.

#### **--volume**, **-v**[=*[[SOURCE-VOLUME|HOST-DIR:]CONTAINER-DIR[:OPTIONS]]*]

Create a bind mount. If you specify, ` -v /HOST-DIR:/CONTAINER-DIR`, Podman
Expand Down
22 changes: 11 additions & 11 deletions docs/source/markdown/podman-pull.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ All tagged images in the repository will be pulled.

Note: When using the all-tags flag, Podman will not iterate over the search registries in the containers-registries.conf(5) but will always use docker.io for unqualified image names.

#### **--arch**=*ARCH*
Override the architecture, defaults to hosts, of the image to be pulled. For example, `arm`.

#### **--authfile**=*path*

Path of the authentication file. Default is ${XDG\_RUNTIME\_DIR}/containers/auth.json, which is set using `podman login`.
Expand All @@ -96,19 +99,16 @@ This is a Docker specific option to disable image verification to a Docker
registry and is not supported by Podman. This flag is a NOOP and provided
solely for scripting compatibility.

#### **--override-arch**=*ARCH*
Override the architecture, defaults to hosts, of the image to be pulled. For example, `arm`.

#### **--override-os**=*OS*
Override the OS, defaults to hosts, of the image to be pulled. For example, `windows`.
#### **--help**, **-h**

#### **--override-variant**=*VARIANT*
Print usage statement

Use _VARIANT_ instead of the default architecture variant of the container image. Some images can use multiple variants of the arm architectures, such as arm/v5 and arm/v7.
#### **--os**=*OS*
Override the OS, defaults to hosts, of the image to be pulled. For example, `windows`.

#### **--platform**=*OS/ARCH*

Specify the platform for selecting the image. (Conflicts with override-arch and override-os)
Specify the platform for selecting the image. (Conflicts with --arch and --os)
The `--platform` option can be used to override the current architecture and operating system.

#### **--quiet**, **-q**
Expand All @@ -121,9 +121,9 @@ Require HTTPS and verify certificates when contacting registries (default: true)
then TLS verification will be used. If set to false, then TLS verification will not be used. If not specified,
TLS verification will be used unless the target registry is listed as an insecure registry in registries.conf.

#### **--help**, **-h**
#### **--variant**=*VARIANT*

Print usage statement
Use _VARIANT_ instead of the default architecture variant of the container image. Some images can use multiple variants of the arm architectures, such as arm/v5 and arm/v7.

## EXAMPLES

Expand Down Expand Up @@ -189,7 +189,7 @@ Storing signatures
```

```
$ podman pull --override-arch=arm arm32v7/debian:stretch
$ podman pull --arch=arm arm32v7/debian:stretch
Trying to pull docker.io/arm32v7/debian:stretch...
Getting image source signatures
Copying blob b531ae4a3925 done
Expand Down
16 changes: 8 additions & 8 deletions docs/source/markdown/podman-run.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ This option can be set multiple times.
Add an annotation to the container.
This option can be set multiple times.

#### **--arch**=*ARCH*
Override the architecture, defaults to hosts, of the image to be pulled. For example, `arm`.

#### **--attach**, **-a**=**stdin**|**stdout**|**stderr**

Attach to STDIN, STDOUT or STDERR.
Expand Down Expand Up @@ -705,15 +708,9 @@ Whether to disable OOM Killer for the container or not.

Tune the host's OOM preferences for containers (accepts values from **-1000** to **1000**).

#### **--override-arch**=*ARCH*
Override the architecture, defaults to hosts, of the image to be pulled. For example, `arm`.

#### **--override-os**=*OS*
#### **--os**=*OS*
Override the OS, defaults to hosts, of the image to be pulled. For example, `windows`.

#### **--override-variant**=*VARIANT*
Use _VARIANT_ instead of the default architecture variant of the container image. Some images can use multiple variants of the arm architectures, such as arm/v5 and arm/v7.

#### **--pid**=*mode*

Set the PID namespace mode for the container.
Expand All @@ -730,7 +727,7 @@ Tune the container's pids limit. Set to **0** to have unlimited pids for the con

#### **--platform**=*OS/ARCH*

Specify the platform for selecting the image. (Conflicts with override-arch and override-os)
Specify the platform for selecting the image. (Conflicts with --arch and --os)
The `--platform` option can be used to override the current architecture and operating system.

#### **--pod**=*name*
Expand Down Expand Up @@ -1083,6 +1080,9 @@ Set the UTS namespace mode for the container. The following values are supported
- **ns:[path]**: run the container in the given existing UTS namespace.
- **container:[container]**: join the UTS namespace of the specified container.

#### **--variant**=*VARIANT*
Use _VARIANT_ instead of the default architecture variant of the container image. Some images can use multiple variants of the arm architectures, such as arm/v5 and arm/v7.

#### **--volume**, **-v**[=*[[SOURCE-VOLUME|HOST-DIR:]CONTAINER-DIR[:OPTIONS]]*]

Create a bind mount. If you specify _/HOST-DIR_:_/CONTAINER-DIR_, Podman
Expand Down
18 changes: 9 additions & 9 deletions pkg/api/handlers/libpod/images_pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ func ImagesPull(w http.ResponseWriter, r *http.Request) {
runtime := r.Context().Value("runtime").(*libpod.Runtime)
decoder := r.Context().Value("decoder").(*schema.Decoder)
query := struct {
Reference string `schema:"reference"`
OverrideOS string `schema:"overrideOS"`
OverrideArch string `schema:"overrideArch"`
OverrideVariant string `schema:"overrideVariant"`
TLSVerify bool `schema:"tlsVerify"`
AllTags bool `schema:"allTags"`
Reference string `schema:"reference"`
OS string `schema:"OS"`
Arch string `schema:"Arch"`
Variant string `schema:"Variant"`
TLSVerify bool `schema:"tlsVerify"`
AllTags bool `schema:"allTags"`
}{
TLSVerify: true,
}
Expand Down Expand Up @@ -83,9 +83,9 @@ func ImagesPull(w http.ResponseWriter, r *http.Request) {
// Setup the registry options
dockerRegistryOptions := image.DockerRegistryOptions{
DockerRegistryCreds: authConf,
OSChoice: query.OverrideOS,
ArchitectureChoice: query.OverrideArch,
VariantChoice: query.OverrideVariant,
OSChoice: query.OS,
ArchitectureChoice: query.Arch,
VariantChoice: query.Variant,
}
if _, found := r.URL.Query()["tlsVerify"]; found {
dockerRegistryOptions.DockerInsecureSkipTLSVerify = types.NewOptionalBool(!query.TLSVerify)
Expand Down
Loading

0 comments on commit 5da474d

Please sign in to comment.