mirror of
https://github.com/containers/podman.git
synced 2025-05-20 00:27:03 +08:00
Fix panic in manifest annotate --index
When the --index flag is used, `manifest annotate` shouldn't be expecting a second non-flag argument. Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
This commit is contained in:
@ -119,7 +119,7 @@ func annotate(cmd *cobra.Command, args []string) error {
|
|||||||
} else {
|
} else {
|
||||||
opts.Annotations = annotations
|
opts.Annotations = annotations
|
||||||
}
|
}
|
||||||
id, err := registry.ImageEngine().ManifestAnnotate(registry.Context(), args[0], args[1], opts)
|
id, err := registry.ImageEngine().ManifestAnnotate(registry.Context(), listImageSpec, instanceSpec, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -10,12 +10,16 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/containers/common/libimage/define"
|
"github.com/containers/common/libimage/define"
|
||||||
|
"github.com/containers/image/v5/docker/reference"
|
||||||
|
manifest "github.com/containers/image/v5/manifest"
|
||||||
|
"github.com/containers/image/v5/transports/alltransports"
|
||||||
podmanRegistry "github.com/containers/podman/v5/hack/podman-registry-go"
|
podmanRegistry "github.com/containers/podman/v5/hack/podman-registry-go"
|
||||||
. "github.com/containers/podman/v5/test/utils"
|
. "github.com/containers/podman/v5/test/utils"
|
||||||
"github.com/containers/storage/pkg/archive"
|
"github.com/containers/storage/pkg/archive"
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
. "github.com/onsi/gomega/gexec"
|
. "github.com/onsi/gomega/gexec"
|
||||||
|
imgspec "github.com/opencontainers/image-spec/specs-go"
|
||||||
imgspecv1 "github.com/opencontainers/image-spec/specs-go/v1"
|
imgspecv1 "github.com/opencontainers/image-spec/specs-go/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -368,7 +372,7 @@ add_compression = ["zstd"]`), 0o644)
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("annotate", func() {
|
It("annotate", func() {
|
||||||
session := podmanTest.Podman([]string{"manifest", "create", "foo"})
|
session := podmanTest.Podman([]string{"manifest", "create", "--annotation", "up=down", "foo"})
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
Expect(session).Should(ExitCleanly())
|
Expect(session).Should(ExitCleanly())
|
||||||
session = podmanTest.Podman([]string{"manifest", "add", "foo", imageListInstance})
|
session = podmanTest.Podman([]string{"manifest", "add", "foo", imageListInstance})
|
||||||
@ -377,12 +381,50 @@ add_compression = ["zstd"]`), 0o644)
|
|||||||
session = podmanTest.Podman([]string{"manifest", "annotate", "--annotation", "hello=world,withcomma", "--arch", "bar", "foo", imageListARM64InstanceDigest})
|
session = podmanTest.Podman([]string{"manifest", "annotate", "--annotation", "hello=world,withcomma", "--arch", "bar", "foo", imageListARM64InstanceDigest})
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
Expect(session).Should(ExitCleanly())
|
Expect(session).Should(ExitCleanly())
|
||||||
|
session = podmanTest.Podman([]string{"manifest", "annotate", "--index", "--annotation", "top=bottom", "foo"})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session).Should(ExitCleanly())
|
||||||
session = podmanTest.Podman([]string{"manifest", "inspect", "foo"})
|
session = podmanTest.Podman([]string{"manifest", "inspect", "foo"})
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
Expect(session).Should(ExitCleanly())
|
Expect(session).Should(ExitCleanly())
|
||||||
Expect(session.OutputToString()).To(ContainSubstring(`"architecture": "bar"`))
|
// Extract the digest from the name of the image that we just added to the list
|
||||||
// Check added annotation
|
ref, err := alltransports.ParseImageName(imageListInstance)
|
||||||
Expect(session.OutputToString()).To(ContainSubstring(`"hello": "world,withcomma"`))
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
dockerReference := ref.DockerReference()
|
||||||
|
referenceWithDigest, ok := dockerReference.(reference.Canonical)
|
||||||
|
Expect(ok).To(BeTrueBecause("we started with a canonical reference"))
|
||||||
|
// Check that the index has all of the information we've just added to it
|
||||||
|
encoded, err := json.Marshal(&imgspecv1.Index{
|
||||||
|
Versioned: imgspec.Versioned{
|
||||||
|
SchemaVersion: 2,
|
||||||
|
},
|
||||||
|
// media type forced because we need to be able to represent annotations
|
||||||
|
MediaType: imgspecv1.MediaTypeImageIndex,
|
||||||
|
Manifests: []imgspecv1.Descriptor{
|
||||||
|
{
|
||||||
|
// from imageListInstance
|
||||||
|
MediaType: manifest.DockerV2Schema2MediaType,
|
||||||
|
Digest: referenceWithDigest.Digest(),
|
||||||
|
Size: 527,
|
||||||
|
// OS from imageListInstance(?), Architecture/Variant as above
|
||||||
|
Platform: &imgspecv1.Platform{
|
||||||
|
Architecture: "bar",
|
||||||
|
OS: "linux",
|
||||||
|
},
|
||||||
|
// added above
|
||||||
|
Annotations: map[string]string{
|
||||||
|
"hello": "world,withcomma",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// added above
|
||||||
|
Annotations: map[string]string{
|
||||||
|
"top": "bottom",
|
||||||
|
"up": "down",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
Expect(session.OutputToString()).To(MatchJSON(encoded))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("remove digest", func() {
|
It("remove digest", func() {
|
||||||
|
Reference in New Issue
Block a user