Skip to content

Commit

Permalink
Fix panic in manifest annotate --index
Browse files Browse the repository at this point in the history
When the --index flag is used, `manifest annotate` shouldn't be
expecting a second non-flag argument.

Signed-off-by: Nalin Dahyabhai <[email protected]>
  • Loading branch information
nalind committed Dec 5, 2024
1 parent 8ff491b commit a28d167
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmd/podman/manifest/annotate.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func annotate(cmd *cobra.Command, args []string) error {
} else {
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 {
return err
}
Expand Down
47 changes: 44 additions & 3 deletions test/e2e/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ import (
"strings"

"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"
. "github.com/containers/podman/v5/test/utils"
"github.com/containers/storage/pkg/archive"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
imgspec "github.com/opencontainers/image-spec/specs-go"
imgspecv1 "github.com/opencontainers/image-spec/specs-go/v1"
)

Expand Down Expand Up @@ -377,12 +381,49 @@ add_compression = ["zstd"]`), 0o644)
session = podmanTest.Podman([]string{"manifest", "annotate", "--annotation", "hello=world,withcomma", "--arch", "bar", "foo", imageListARM64InstanceDigest})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
session = podmanTest.Podman([]string{"manifest", "annotate", "--index", "--annotation", "left=right", "foo"})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
session = podmanTest.Podman([]string{"manifest", "inspect", "foo"})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expect(session.OutputToString()).To(ContainSubstring(`"architecture": "bar"`))
// Check added annotation
Expect(session.OutputToString()).To(ContainSubstring(`"hello": "world,withcomma"`))
// Extract the digest from the name of the image that we just added to the list
ref, err := alltransports.ParseImageName(imageListInstance)
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{
"left": "right",
},
})
Expect(err).ToNot(HaveOccurred())
Expect(session.OutputToString()).To(MatchJSON(encoded))
})

It("remove digest", func() {
Expand Down

0 comments on commit a28d167

Please sign in to comment.