mirror of
https://github.com/containers/podman.git
synced 2025-06-28 06:18:57 +08:00
Merge pull request #15988 from sstosh/manifest-annotate-remote
remote: fix manifest add --annotation
This commit is contained in:
@ -11,8 +11,8 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/containers/common/libimage"
|
||||||
"github.com/containers/image/v5/docker/reference"
|
"github.com/containers/image/v5/docker/reference"
|
||||||
"github.com/containers/image/v5/manifest"
|
|
||||||
"github.com/containers/image/v5/types"
|
"github.com/containers/image/v5/types"
|
||||||
"github.com/containers/podman/v4/libpod"
|
"github.com/containers/podman/v4/libpod"
|
||||||
"github.com/containers/podman/v4/pkg/api/handlers"
|
"github.com/containers/podman/v4/pkg/api/handlers"
|
||||||
@ -148,7 +148,7 @@ func ManifestInspect(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var schema2List manifest.Schema2List
|
var schema2List libimage.ManifestListData
|
||||||
if err := json.Unmarshal(rawManifest, &schema2List); err != nil {
|
if err := json.Unmarshal(rawManifest, &schema2List); err != nil {
|
||||||
utils.Error(w, http.StatusInternalServerError, err)
|
utils.Error(w, http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/containers/image/v5/manifest"
|
"github.com/containers/common/libimage"
|
||||||
imageTypes "github.com/containers/image/v5/types"
|
imageTypes "github.com/containers/image/v5/types"
|
||||||
"github.com/containers/podman/v4/pkg/auth"
|
"github.com/containers/podman/v4/pkg/auth"
|
||||||
"github.com/containers/podman/v4/pkg/bindings"
|
"github.com/containers/podman/v4/pkg/bindings"
|
||||||
@ -71,7 +71,7 @@ func Exists(ctx context.Context, name string, options *ExistsOptions) (bool, err
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Inspect returns a manifest list for a given name.
|
// Inspect returns a manifest list for a given name.
|
||||||
func Inspect(ctx context.Context, name string, _ *InspectOptions) (*manifest.Schema2List, error) {
|
func Inspect(ctx context.Context, name string, _ *InspectOptions) (*libimage.ManifestListData, error) {
|
||||||
conn, err := bindings.GetClient(ctx)
|
conn, err := bindings.GetClient(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -83,7 +83,7 @@ func Inspect(ctx context.Context, name string, _ *InspectOptions) (*manifest.Sch
|
|||||||
}
|
}
|
||||||
defer response.Body.Close()
|
defer response.Body.Close()
|
||||||
|
|
||||||
var list manifest.Schema2List
|
var list libimage.ManifestListData
|
||||||
return &list, response.Process(&list)
|
return &list, response.Process(&list)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ type ExistsOptions struct {
|
|||||||
// AddOptions are optional options for adding manifest lists
|
// AddOptions are optional options for adding manifest lists
|
||||||
type AddOptions struct {
|
type AddOptions struct {
|
||||||
All *bool
|
All *bool
|
||||||
Annotation map[string]string
|
Annotation []string
|
||||||
Arch *string
|
Arch *string
|
||||||
Features []string
|
Features []string
|
||||||
Images []string
|
Images []string
|
||||||
@ -46,12 +46,12 @@ type ModifyOptions struct {
|
|||||||
// Operation values are "update", "remove" and "annotate". This allows the service to
|
// Operation values are "update", "remove" and "annotate". This allows the service to
|
||||||
// efficiently perform each update on a manifest list.
|
// efficiently perform each update on a manifest list.
|
||||||
Operation *string
|
Operation *string
|
||||||
All *bool // All when true, operate on all images in a manifest list that may be included in Images
|
All *bool // All when true, operate on all images in a manifest list that may be included in Images
|
||||||
Annotations map[string]string // Annotations to add to manifest list
|
Annotations []string // Annotations to add to manifest list
|
||||||
Arch *string // Arch overrides the architecture for the image
|
Arch *string // Arch overrides the architecture for the image
|
||||||
Features []string // Feature list for the image
|
Features []string // Feature list for the image
|
||||||
Images []string // Images is an optional list of images to add/remove to/from manifest list depending on operation
|
Images []string // Images is an optional list of images to add/remove to/from manifest list depending on operation
|
||||||
OS *string // OS overrides the operating system for the image
|
OS *string // OS overrides the operating system for the image
|
||||||
// OS features for the image
|
// OS features for the image
|
||||||
OSFeatures []string `json:"os_features" schema:"os_features"`
|
OSFeatures []string `json:"os_features" schema:"os_features"`
|
||||||
// OSVersion overrides the operating system for the image
|
// OSVersion overrides the operating system for the image
|
||||||
|
@ -33,15 +33,15 @@ func (o *AddOptions) GetAll() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WithAnnotation set field Annotation to given value
|
// WithAnnotation set field Annotation to given value
|
||||||
func (o *AddOptions) WithAnnotation(value map[string]string) *AddOptions {
|
func (o *AddOptions) WithAnnotation(value []string) *AddOptions {
|
||||||
o.Annotation = value
|
o.Annotation = value
|
||||||
return o
|
return o
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAnnotation returns value of field Annotation
|
// GetAnnotation returns value of field Annotation
|
||||||
func (o *AddOptions) GetAnnotation() map[string]string {
|
func (o *AddOptions) GetAnnotation() []string {
|
||||||
if o.Annotation == nil {
|
if o.Annotation == nil {
|
||||||
var z map[string]string
|
var z []string
|
||||||
return z
|
return z
|
||||||
}
|
}
|
||||||
return o.Annotation
|
return o.Annotation
|
||||||
|
@ -48,15 +48,15 @@ func (o *ModifyOptions) GetAll() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WithAnnotations set annotations to add to manifest list
|
// WithAnnotations set annotations to add to manifest list
|
||||||
func (o *ModifyOptions) WithAnnotations(value map[string]string) *ModifyOptions {
|
func (o *ModifyOptions) WithAnnotations(value []string) *ModifyOptions {
|
||||||
o.Annotations = value
|
o.Annotations = value
|
||||||
return o
|
return o
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAnnotations returns value of annotations to add to manifest list
|
// GetAnnotations returns value of annotations to add to manifest list
|
||||||
func (o *ModifyOptions) GetAnnotations() map[string]string {
|
func (o *ModifyOptions) GetAnnotations() []string {
|
||||||
if o.Annotations == nil {
|
if o.Annotations == nil {
|
||||||
var z map[string]string
|
var z []string
|
||||||
return z
|
return z
|
||||||
}
|
}
|
||||||
return o.Annotations
|
return o.Annotations
|
||||||
|
@ -36,7 +36,7 @@ type ManifestAddOptions struct {
|
|||||||
// ManifestAnnotateOptions provides model for annotating manifest list
|
// ManifestAnnotateOptions provides model for annotating manifest list
|
||||||
type ManifestAnnotateOptions struct {
|
type ManifestAnnotateOptions struct {
|
||||||
// Annotation to add to manifest list
|
// Annotation to add to manifest list
|
||||||
Annotation []string `json:"annotation" schema:"annotation"`
|
Annotation []string `json:"annotations" schema:"annotations"`
|
||||||
// Arch overrides the architecture for the image
|
// Arch overrides the architecture for the image
|
||||||
Arch string `json:"arch" schema:"arch"`
|
Arch string `json:"arch" schema:"arch"`
|
||||||
// Feature list for the image
|
// Feature list for the image
|
||||||
|
@ -5,7 +5,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/containers/image/v5/types"
|
"github.com/containers/image/v5/types"
|
||||||
"github.com/containers/podman/v4/pkg/bindings/images"
|
"github.com/containers/podman/v4/pkg/bindings/images"
|
||||||
@ -48,20 +47,9 @@ func (ir *ImageEngine) ManifestInspect(_ context.Context, name string) ([]byte,
|
|||||||
|
|
||||||
// ManifestAdd adds images to the manifest list
|
// ManifestAdd adds images to the manifest list
|
||||||
func (ir *ImageEngine) ManifestAdd(_ context.Context, name string, imageNames []string, opts entities.ManifestAddOptions) (string, error) {
|
func (ir *ImageEngine) ManifestAdd(_ context.Context, name string, imageNames []string, opts entities.ManifestAddOptions) (string, error) {
|
||||||
options := new(manifests.AddOptions).WithAll(opts.All).WithArch(opts.Arch).WithVariant(opts.Variant)
|
options := new(manifests.AddOptions).WithAll(opts.All).WithAnnotation(opts.Annotation).WithArch(opts.Arch)
|
||||||
options.WithFeatures(opts.Features).WithImages(imageNames).WithOS(opts.OS).WithOSVersion(opts.OSVersion)
|
options.WithVariant(opts.Variant).WithFeatures(opts.Features).WithImages(imageNames).WithOS(opts.OS)
|
||||||
options.WithUsername(opts.Username).WithPassword(opts.Password).WithAuthfile(opts.Authfile)
|
options.WithOSVersion(opts.OSVersion).WithUsername(opts.Username).WithPassword(opts.Password).WithAuthfile(opts.Authfile)
|
||||||
if len(opts.Annotation) != 0 {
|
|
||||||
annotations := make(map[string]string)
|
|
||||||
for _, annotationSpec := range opts.Annotation {
|
|
||||||
spec := strings.SplitN(annotationSpec, "=", 2)
|
|
||||||
if len(spec) != 2 {
|
|
||||||
return "", fmt.Errorf("no value given for annotation %q", spec[0])
|
|
||||||
}
|
|
||||||
annotations[spec[0]] = spec[1]
|
|
||||||
}
|
|
||||||
options.WithAnnotation(annotations)
|
|
||||||
}
|
|
||||||
if s := opts.SkipTLSVerify; s != types.OptionalBoolUndefined {
|
if s := opts.SkipTLSVerify; s != types.OptionalBoolUndefined {
|
||||||
if s == types.OptionalBoolTrue {
|
if s == types.OptionalBoolTrue {
|
||||||
options.WithSkipTLSVerify(true)
|
options.WithSkipTLSVerify(true)
|
||||||
|
@ -165,6 +165,20 @@ var _ = Describe("Podman manifest", func() {
|
|||||||
))
|
))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("add --annotation", func() {
|
||||||
|
session := podmanTest.Podman([]string{"manifest", "create", "foo"})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session).Should(Exit(0))
|
||||||
|
session = podmanTest.Podman([]string{"manifest", "add", "--annotation", "hoge=fuga", "foo", imageList})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session).Should(Exit(0))
|
||||||
|
session = podmanTest.Podman([]string{"manifest", "inspect", "foo"})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session).Should(Exit(0))
|
||||||
|
Expect(session.OutputToString()).To(ContainSubstring(`"annotations"`))
|
||||||
|
Expect(session.OutputToString()).To(ContainSubstring(`"hoge": "fuga"`))
|
||||||
|
})
|
||||||
|
|
||||||
It("add --os", func() {
|
It("add --os", func() {
|
||||||
session := podmanTest.Podman([]string{"manifest", "create", "foo"})
|
session := podmanTest.Podman([]string{"manifest", "create", "foo"})
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
|
Reference in New Issue
Block a user