summaryrefslogtreecommitdiff
path: root/pkg/domain/infra/abi/containers_runlabel.go
diff options
context:
space:
mode:
authorValentin Rothberg <rothberg@redhat.com>2021-04-22 08:01:12 +0200
committerValentin Rothberg <rothberg@redhat.com>2021-05-05 11:30:12 +0200
commit0f7d54b0260c1be992ee3b9cee359ef3a9e8bd21 (patch)
tree192e52054de2abf0c92d83ecdbc71d498c2ec947 /pkg/domain/infra/abi/containers_runlabel.go
parent8eefca5a257121b177562742c972e39e1686140d (diff)
downloadpodman-0f7d54b0260c1be992ee3b9cee359ef3a9e8bd21.tar.gz
podman-0f7d54b0260c1be992ee3b9cee359ef3a9e8bd21.tar.bz2
podman-0f7d54b0260c1be992ee3b9cee359ef3a9e8bd21.zip
migrate Podman to containers/common/libimage
Migrate the Podman code base over to `common/libimage` which replaces `libpod/image` and a lot of glue code entirely. Note that I tried to leave bread crumbs for changed tests. Miscellaneous changes: * Some errors yield different messages which required to alter some tests. * I fixed some pre-existing issues in the code. Others were marked as `//TODO`s to prevent the PR from exploding. * The `NamesHistory` of an image is returned as is from the storage. Previously, we did some filtering which I think is undesirable. Instead we should return the data as stored in the storage. * Touched handlers use the ABI interfaces where possible. * Local image resolution: previously Podman would match "foo" on "myfoo". This behaviour has been changed and Podman will now only match on repository boundaries such that "foo" would match "my/foo" but not "myfoo". I consider the old behaviour to be a bug, at the very least an exotic corner case. * Futhermore, "foo:none" does *not* resolve to a local image "foo" without tag anymore. It's a hill I am (almost) willing to die on. * `image prune` prints the IDs of pruned images. Previously, in some cases, the names were printed instead. The API clearly states ID, so we should stick to it. * Compat endpoint image removal with _force_ deletes the entire not only the specified tag. Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
Diffstat (limited to 'pkg/domain/infra/abi/containers_runlabel.go')
-rw-r--r--pkg/domain/infra/abi/containers_runlabel.go86
1 files changed, 44 insertions, 42 deletions
diff --git a/pkg/domain/infra/abi/containers_runlabel.go b/pkg/domain/infra/abi/containers_runlabel.go
index 2cabab988..199ae43ad 100644
--- a/pkg/domain/infra/abi/containers_runlabel.go
+++ b/pkg/domain/infra/abi/containers_runlabel.go
@@ -7,8 +7,9 @@ import (
"path/filepath"
"strings"
+ "github.com/containers/common/libimage"
+ "github.com/containers/common/pkg/config"
"github.com/containers/podman/v3/libpod/define"
- "github.com/containers/podman/v3/libpod/image"
"github.com/containers/podman/v3/pkg/domain/entities"
envLib "github.com/containers/podman/v3/pkg/env"
"github.com/containers/podman/v3/utils"
@@ -18,21 +19,48 @@ import (
)
func (ic *ContainerEngine) ContainerRunlabel(ctx context.Context, label string, imageRef string, args []string, options entities.ContainerRunlabelOptions) error {
- // First, get the image and pull it if needed.
- img, err := ic.runlabelImage(ctx, label, imageRef, options)
+ pullOptions := &libimage.PullOptions{}
+ pullOptions.AuthFilePath = options.Authfile
+ pullOptions.CertDirPath = options.CertDir
+ pullOptions.Credentials = options.Credentials
+ pullOptions.SignaturePolicyPath = options.SignaturePolicy
+ pullOptions.InsecureSkipTLSVerify = options.SkipTLSVerify
+
+ pullPolicy := config.PullPolicyNever
+ if options.Pull {
+ pullPolicy = config.PullPolicyMissing
+ }
+ if !options.Quiet {
+ pullOptions.Writer = os.Stderr
+ }
+
+ pulledImages, err := ic.Libpod.LibimageRuntime().Pull(ctx, imageRef, pullPolicy, pullOptions)
if err != nil {
return err
}
+
+ if len(pulledImages) != 1 {
+ return errors.Errorf("internal error: expected an image to be pulled (or an error)")
+ }
+
// Extract the runlabel from the image.
- runlabel, err := img.GetLabel(ctx, label)
+ labels, err := pulledImages[0].Labels(ctx)
if err != nil {
return err
}
+
+ var runlabel string
+ for k, v := range labels {
+ if strings.EqualFold(k, label) {
+ runlabel = v
+ break
+ }
+ }
if runlabel == "" {
return errors.Errorf("cannot find the value of label: %s in image: %s", label, imageRef)
}
- cmd, env, err := generateRunlabelCommand(runlabel, img, args, options)
+ cmd, env, err := generateRunlabelCommand(runlabel, pulledImages[0], imageRef, args, options)
if err != nil {
return err
}
@@ -76,36 +104,9 @@ func (ic *ContainerEngine) ContainerRunlabel(ctx context.Context, label string,
return utils.ExecCmdWithStdStreams(stdIn, stdOut, stdErr, env, cmd[0], cmd[1:]...)
}
-// runlabelImage returns an image based on the specified image AND options.
-func (ic *ContainerEngine) runlabelImage(ctx context.Context, label string, imageRef string, options entities.ContainerRunlabelOptions) (*image.Image, error) {
- // First, look up the image locally. If we get an error and requested
- // to pull, fallthrough and pull it.
- img, err := ic.Libpod.ImageRuntime().NewFromLocal(imageRef)
- switch {
- case err == nil:
- return img, nil
- case !options.Pull:
- return nil, err
- default:
- // Fallthrough and pull!
- }
-
- pullOptions := entities.ImagePullOptions{
- Quiet: options.Quiet,
- CertDir: options.CertDir,
- SkipTLSVerify: options.SkipTLSVerify,
- SignaturePolicy: options.SignaturePolicy,
- Authfile: options.Authfile,
- }
- if _, err := pull(ctx, ic.Libpod.ImageRuntime(), imageRef, pullOptions, &label); err != nil {
- return nil, err
- }
- return ic.Libpod.ImageRuntime().NewFromLocal(imageRef)
-}
-
// generateRunlabelCommand generates the to-be-executed command as a string
// slice along with a base environment.
-func generateRunlabelCommand(runlabel string, img *image.Image, args []string, options entities.ContainerRunlabelOptions) ([]string, []string, error) {
+func generateRunlabelCommand(runlabel string, img *libimage.Image, inputName string, args []string, options entities.ContainerRunlabelOptions) ([]string, []string, error) {
var (
err error
name, imageName string
@@ -113,24 +114,25 @@ func generateRunlabelCommand(runlabel string, img *image.Image, args []string, o
cmd []string
)
- // TODO: How do we get global opts as done in v1?
-
// Extract the imageName (or ID).
- imgNames := img.Names()
+ imgNames := img.NamesHistory()
if len(imgNames) == 0 {
imageName = img.ID()
} else {
+ // The newest name is the first entry in the `NamesHistory`
+ // slice.
imageName = imgNames[0]
}
// Use the user-specified name or extract one from the image.
- if options.Name != "" {
- name = options.Name
- } else {
- name, err = image.GetImageBaseName(imageName)
- if err != nil {
- return nil, nil, err
+ name = options.Name
+ if name == "" {
+ normalize := imageName
+ if !strings.HasPrefix(img.ID(), inputName) {
+ normalize = inputName
}
+ splitImageName := strings.Split(normalize, "/")
+ name = splitImageName[len(splitImageName)-1]
}
// Append the user-specified arguments to the runlabel (command).