Merge pull request #7436 from rhatdan/variant

Add support for image pull overrides
This commit is contained in:
OpenShift Merge Robot
2020-08-28 16:02:56 -04:00
committed by GitHub
16 changed files with 67 additions and 24 deletions

View File

@ -323,13 +323,16 @@ func GetCreateFlags(cf *ContainerCLIOpts) *pflag.FlagSet {
"override-arch", "", "override-arch", "",
"use `ARCH` instead of the architecture of the machine for choosing images", "use `ARCH` instead of the architecture of the machine for choosing images",
) )
// markFlagHidden(createFlags, "override-arch")
createFlags.StringVar( createFlags.StringVar(
&cf.OverrideOS, &cf.OverrideOS,
"override-os", "", "override-os", "",
"use `OS` instead of the running OS for choosing images", "use `OS` instead of the running OS for choosing images",
) )
// markFlagHidden(createFlags, "override-os") createFlags.StringVar(
&cf.OverrideVariant,
"override-variant", "",
"Use _VARIANT_ instead of the running architecture variant for choosing images",
)
createFlags.String( createFlags.String(
"pid", "", "pid", "",
"PID namespace to use", "PID namespace to use",

View File

@ -65,6 +65,7 @@ type ContainerCLIOpts struct {
OOMScoreAdj int OOMScoreAdj int
OverrideArch string OverrideArch string
OverrideOS string OverrideOS string
OverrideVariant string
PID string PID string
PIDsLimit *int64 PIDsLimit *int64
Pod string Pod string

View File

@ -66,9 +66,6 @@ func createFlags(flags *pflag.FlagSet) {
_ = flags.MarkHidden("env-host") _ = flags.MarkHidden("env-host")
_ = flags.MarkHidden("http-proxy") _ = flags.MarkHidden("http-proxy")
} }
// Not sure we want these exposed yet. If we do, they need to be documented in man pages
_ = flags.MarkHidden("override-arch")
_ = flags.MarkHidden("override-os")
} }
func init() { func init() {
@ -254,10 +251,11 @@ func pullImage(imageName string) (string, error) {
return "", errors.Wrapf(define.ErrNoSuchImage, "unable to find a name and tag match for %s in repotags", imageName) return "", errors.Wrapf(define.ErrNoSuchImage, "unable to find a name and tag match for %s in repotags", imageName)
} }
pullReport, pullErr := registry.ImageEngine().Pull(registry.GetContext(), imageName, entities.ImagePullOptions{ pullReport, pullErr := registry.ImageEngine().Pull(registry.GetContext(), imageName, entities.ImagePullOptions{
Authfile: cliVals.Authfile, Authfile: cliVals.Authfile,
Quiet: cliVals.Quiet, Quiet: cliVals.Quiet,
OverrideArch: cliVals.OverrideArch, OverrideArch: cliVals.OverrideArch,
OverrideOS: cliVals.OverrideOS, OverrideOS: cliVals.OverrideOS,
OverrideVariant: cliVals.OverrideVariant,
}) })
if pullErr != nil { if pullErr != nil {
return "", pullErr return "", pullErr

View File

@ -70,9 +70,6 @@ func runFlags(flags *pflag.FlagSet) {
_ = flags.MarkHidden("http-proxy") _ = flags.MarkHidden("http-proxy")
_ = flags.MarkHidden("preserve-fds") _ = flags.MarkHidden("preserve-fds")
} }
// Not sure we want these exposed yet. If we do, they need to be documented in man pages
_ = flags.MarkHidden("override-arch")
_ = flags.MarkHidden("override-os")
} }
func init() { func init() {
registry.Commands = append(registry.Commands, registry.CliCommand{ registry.Commands = append(registry.Commands, registry.CliCommand{

View File

@ -82,6 +82,7 @@ func pullFlags(flags *pflag.FlagSet) {
flags.StringVar(&pullOptions.CredentialsCLI, "creds", "", "`Credentials` (USERNAME:PASSWORD) to use for authenticating to a registry") flags.StringVar(&pullOptions.CredentialsCLI, "creds", "", "`Credentials` (USERNAME:PASSWORD) to use for authenticating to a registry")
flags.StringVar(&pullOptions.OverrideArch, "override-arch", "", "Use `ARCH` instead of the architecture of the machine for choosing images") flags.StringVar(&pullOptions.OverrideArch, "override-arch", "", "Use `ARCH` instead of the architecture of the machine for choosing images")
flags.StringVar(&pullOptions.OverrideOS, "override-os", "", "Use `OS` instead of the running OS for choosing images") flags.StringVar(&pullOptions.OverrideOS, "override-os", "", "Use `OS` instead of the running OS for choosing images")
flags.StringVar(&pullOptions.OverrideVariant, "override-variant", "", " use VARIANT instead of the running architecture variant for choosing images")
flags.Bool("disable-content-trust", false, "This is a Docker specific option and is a NOOP") flags.Bool("disable-content-trust", false, "This is a Docker specific option and is a NOOP")
flags.BoolVarP(&pullOptions.Quiet, "quiet", "q", false, "Suppress output information when pulling images") flags.BoolVarP(&pullOptions.Quiet, "quiet", "q", false, "Suppress output information when pulling images")
flags.StringVar(&pullOptions.SignaturePolicy, "signature-policy", "", "`Pathname` of signature policy file (not usually used)") flags.StringVar(&pullOptions.SignaturePolicy, "signature-policy", "", "`Pathname` of signature policy file (not usually used)")

View File

@ -1980,12 +1980,16 @@ _podman_manifest_remove() {
_podman_pull() { _podman_pull() {
local options_with_args=" local options_with_args="
--authfile --authfile
--creds
--cert-dir --cert-dir
--creds
--override-arch
--override-os
--override-variant
" "
local boolean_options=" local boolean_options="
--all-tags --all-tags
-a -a
--disable-content-trust
--help --help
-h -h
--quiet --quiet
@ -2160,6 +2164,9 @@ _podman_container_run() {
--no-healthcheck --no-healthcheck
--no-hosts --no-hosts
--oom-score-adj --oom-score-adj
--override-arch
--override-os
--override-variant
--pid --pid
--pids-limit --pids-limit
--pod --pod

View File

@ -599,6 +599,15 @@ Whether to disable OOM Killer for the container or not.
Tune the host's OOM preferences for containers (accepts -1000 to 1000) 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*
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* **--pid**=*pid*
Set the PID mode for the container Set the PID mode for the container

View File

@ -79,12 +79,15 @@ 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 registry and is not supported by Podman. This flag is a NOOP and provided
solely for scripting compatibility. solely for scripting compatibility.
**--override-os**=*OS*
Use OS instead of the running OS for choosing images
**--override-arch**=*ARCH* **--override-arch**=*ARCH*
Override the architecture, defaults to hosts, of the image to be pulled. For example, `arm`.
Override the machine's default architecture 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`.
**--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.
**--quiet**, **-q** **--quiet**, **-q**

View File

@ -608,6 +608,15 @@ Whether to disable OOM Killer for the container or not.
Tune the host's OOM preferences for containers (accepts values from **-1000** to **1000**). 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*
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* **--pid**=*mode*
Set the PID namespace mode for the container. Set the PID namespace mode for the container.

View File

@ -30,6 +30,8 @@ type DockerRegistryOptions struct {
OSChoice string OSChoice string
// If not "", overrides the use of platform.GOARCH when choosing an image or verifying architecture match. // If not "", overrides the use of platform.GOARCH when choosing an image or verifying architecture match.
ArchitectureChoice string ArchitectureChoice string
// If not "", overrides_VARIANT_ instead of the running architecture variant for choosing images.
VariantChoice string
// RegistriesConfPath can be used to override the default path of registries.conf. // RegistriesConfPath can be used to override the default path of registries.conf.
RegistriesConfPath string RegistriesConfPath string
} }
@ -43,6 +45,7 @@ func (o DockerRegistryOptions) GetSystemContext(parent *types.SystemContext, add
DockerArchiveAdditionalTags: additionalDockerArchiveTags, DockerArchiveAdditionalTags: additionalDockerArchiveTags,
OSChoice: o.OSChoice, OSChoice: o.OSChoice,
ArchitectureChoice: o.ArchitectureChoice, ArchitectureChoice: o.ArchitectureChoice,
VariantChoice: o.VariantChoice,
BigFilesTemporaryDir: parse.GetTempDir(), BigFilesTemporaryDir: parse.GetTempDir(),
} }
if parent != nil { if parent != nil {

View File

@ -228,6 +228,7 @@ func (ir *Runtime) pullImageFromHeuristicSource(ctx context.Context, inputName s
if dockerOptions != nil { if dockerOptions != nil {
sc.OSChoice = dockerOptions.OSChoice sc.OSChoice = dockerOptions.OSChoice
sc.ArchitectureChoice = dockerOptions.ArchitectureChoice sc.ArchitectureChoice = dockerOptions.ArchitectureChoice
sc.VariantChoice = dockerOptions.VariantChoice
} }
sc.BlobInfoCacheDir = filepath.Join(ir.store.GraphRoot(), "cache") sc.BlobInfoCacheDir = filepath.Join(ir.store.GraphRoot(), "cache")
srcRef, err := alltransports.ParseImageName(inputName) srcRef, err := alltransports.ParseImageName(inputName)
@ -260,6 +261,7 @@ func (ir *Runtime) pullImageFromReference(ctx context.Context, srcRef types.Imag
if dockerOptions != nil { if dockerOptions != nil {
sc.OSChoice = dockerOptions.OSChoice sc.OSChoice = dockerOptions.OSChoice
sc.ArchitectureChoice = dockerOptions.ArchitectureChoice sc.ArchitectureChoice = dockerOptions.ArchitectureChoice
sc.VariantChoice = dockerOptions.VariantChoice
} }
goal, err := ir.pullGoalFromImageReference(ctx, srcRef, transports.ImageName(srcRef), sc) goal, err := ir.pullGoalFromImageReference(ctx, srcRef, transports.ImageName(srcRef), sc)
if err != nil { if err != nil {

View File

@ -338,11 +338,12 @@ func ImagesPull(w http.ResponseWriter, r *http.Request) {
runtime := r.Context().Value("runtime").(*libpod.Runtime) runtime := r.Context().Value("runtime").(*libpod.Runtime)
decoder := r.Context().Value("decoder").(*schema.Decoder) decoder := r.Context().Value("decoder").(*schema.Decoder)
query := struct { query := struct {
Reference string `schema:"reference"` Reference string `schema:"reference"`
OverrideOS string `schema:"overrideOS"` OverrideOS string `schema:"overrideOS"`
OverrideArch string `schema:"overrideArch"` OverrideArch string `schema:"overrideArch"`
TLSVerify bool `schema:"tlsVerify"` OverrideVariant string `schema:"overrideVariant"`
AllTags bool `schema:"allTags"` TLSVerify bool `schema:"tlsVerify"`
AllTags bool `schema:"allTags"`
}{ }{
TLSVerify: true, TLSVerify: true,
} }
@ -393,6 +394,7 @@ func ImagesPull(w http.ResponseWriter, r *http.Request) {
DockerRegistryCreds: authConf, DockerRegistryCreds: authConf,
OSChoice: query.OverrideOS, OSChoice: query.OverrideOS,
ArchitectureChoice: query.OverrideArch, ArchitectureChoice: query.OverrideArch,
VariantChoice: query.OverrideVariant,
} }
if _, found := r.URL.Query()["tlsVerify"]; found { if _, found := r.URL.Query()["tlsVerify"]; found {
dockerRegistryOptions.DockerInsecureSkipTLSVerify = types.NewOptionalBool(!query.TLSVerify) dockerRegistryOptions.DockerInsecureSkipTLSVerify = types.NewOptionalBool(!query.TLSVerify)

View File

@ -905,12 +905,16 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error {
// description: "username:password for the registry" // description: "username:password for the registry"
// type: string // type: string
// - in: query // - in: query
// name: overrideArch
// description: Pull image for the specified architecture.
// type: string
// - in: query
// name: overrideOS // name: overrideOS
// description: Pull image for the specified operating system. // description: Pull image for the specified operating system.
// type: string // type: string
// - in: query // - in: query
// name: overrideArch // name: overrideVariant
// description: Pull image for the specified architecture. // description: Pull image for the specified variant.
// type: string // type: string
// - in: query // - in: query
// name: tlsVerify // name: tlsVerify

View File

@ -365,6 +365,7 @@ func Pull(ctx context.Context, rawImage string, options entities.ImagePullOption
params.Set("reference", rawImage) params.Set("reference", rawImage)
params.Set("overrideArch", options.OverrideArch) params.Set("overrideArch", options.OverrideArch)
params.Set("overrideOS", options.OverrideOS) params.Set("overrideOS", options.OverrideOS)
params.Set("overrideVariant", options.OverrideVariant)
if options.SkipTLSVerify != types.OptionalBoolUndefined { if options.SkipTLSVerify != types.OptionalBoolUndefined {
// Note: we have to verify if skipped is false. // Note: we have to verify if skipped is false.
verifyTLS := bool(options.SkipTLSVerify == types.OptionalBoolFalse) verifyTLS := bool(options.SkipTLSVerify == types.OptionalBoolFalse)

View File

@ -137,6 +137,8 @@ type ImagePullOptions struct {
// OverrideOS will overwrite the local operating system (OS) for image // OverrideOS will overwrite the local operating system (OS) for image
// pulls. // pulls.
OverrideOS string OverrideOS string
// OverrideVariant will overwrite the local variant for image pulls.
OverrideVariant string
// Quiet can be specified to suppress pull progress when pulling. Ignored // Quiet can be specified to suppress pull progress when pulling. Ignored
// for remote calls. // for remote calls.
Quiet bool Quiet bool

View File

@ -251,6 +251,7 @@ func (ir *ImageEngine) Pull(ctx context.Context, rawImage string, options entiti
DockerCertPath: options.CertDir, DockerCertPath: options.CertDir,
OSChoice: options.OverrideOS, OSChoice: options.OverrideOS,
ArchitectureChoice: options.OverrideArch, ArchitectureChoice: options.OverrideArch,
VariantChoice: options.OverrideVariant,
DockerInsecureSkipTLSVerify: options.SkipTLSVerify, DockerInsecureSkipTLSVerify: options.SkipTLSVerify,
} }