Skip to content

Commit

Permalink
Refactor manifest list operations
Browse files Browse the repository at this point in the history
* Update method/function signatures use the manifest list name and
  images associated with the operation explicitly, in general

  func f(ctx context.Context, manifestListName string,
         ImageNames []string, options *fOptions)

* Leverage gorilla/mux Subrouters to support API v3.x and v4.x for
  manifests
* Make manifest API endpoints more RESTful
* Add PUT /manifest/{id} to update existing manifests
* Add manifests.Annotate to go bindings, uncommented unit test
* Add DELETE /manifest/{Id} to remove existing manifest list, use
  PUT /manifest/{id} to remove images from a list
* Deprecated POST /manifest/{id}/add and /manifest/{id}/remove, use
  PUT /manifest/{id} instead
* Corrected swagger godoc and updated to cover API changes
* Update podman manifest commands to use registry.Context()
* Expose utils.GetVar() to obtain query parameters by name
* Unexpose server.registerSwaggerHandlers, not sure why this was ever
  exposed.
* Refactored code to use http.Header instead of map[string]string when
  operating on HTTP headers.
* Add API-Version header support in bindings to allow calling explicate
  versions of the API. Header is _NOT_ forwarded to the API service.

Signed-off-by: Jhon Honce <[email protected]>
  • Loading branch information
jwhonce committed Jan 14, 2022
1 parent ec2b213 commit 8a7e709
Show file tree
Hide file tree
Showing 32 changed files with 1,054 additions and 406 deletions.
12 changes: 4 additions & 8 deletions cmd/podman/manifest/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ type manifestAddOptsWrapper struct {
var (
manifestAddOpts = manifestAddOptsWrapper{}
addCmd = &cobra.Command{
Use: "add [options] LIST LIST",
Use: "add [options] LIST IMAGE [IMAGE...]",
Short: "Add images to a manifest list or image index",
Long: "Adds an image to a manifest list or image index.",
RunE: add,
Args: cobra.MinimumNArgs(2),
ValidArgsFunction: common.AutocompleteImages,
Example: `podman manifest add mylist:v1.11 image:v1.11-amd64
podman manifest add mylist:v1.11 transport:imageName`,
Args: cobra.ExactArgs(2),
}
)

Expand Down Expand Up @@ -93,10 +93,6 @@ func add(cmd *cobra.Command, args []string) error {
return err
}

// FIXME: (@vrothberg) this interface confuses me a lot. Why are they
// not two arguments?
manifestAddOpts.Images = []string{args[1], args[0]}

if manifestAddOpts.CredentialsCLI != "" {
creds, err := util.ParseRegistryCreds(manifestAddOpts.CredentialsCLI)
if err != nil {
Expand All @@ -114,10 +110,10 @@ func add(cmd *cobra.Command, args []string) error {
manifestAddOpts.SkipTLSVerify = types.NewOptionalBool(!manifestAddOpts.TLSVerifyCLI)
}

listID, err := registry.ImageEngine().ManifestAdd(context.Background(), manifestAddOpts.ManifestAddOptions)
listID, err := registry.ImageEngine().ManifestAdd(context.Background(), args[0], args[1:], manifestAddOpts.ManifestAddOptions)
if err != nil {
return err
}
fmt.Printf("%s\n", listID)
fmt.Println(listID)
return nil
}
16 changes: 3 additions & 13 deletions cmd/podman/manifest/annotate.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package manifest

import (
"context"
"fmt"

"github.com/containers/common/pkg/completion"
"github.com/containers/podman/v3/cmd/podman/common"
"github.com/containers/podman/v3/cmd/podman/registry"
"github.com/containers/podman/v3/pkg/domain/entities"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)

Expand All @@ -20,8 +18,8 @@ var (
Short: "Add or update information about an entry in a manifest list or image index",
Long: "Adds or updates information about an entry in a manifest list or image index.",
RunE: annotate,
Example: `podman manifest annotate --annotation left=right mylist:v1.11 image:v1.11-amd64`,
Args: cobra.ExactArgs(2),
Example: `podman manifest annotate --annotation left=right mylist:v1.11 image:v1.11-amd64`,
ValidArgsFunction: common.AutocompleteImages,
}
)
Expand Down Expand Up @@ -63,18 +61,10 @@ func init() {
}

func annotate(cmd *cobra.Command, args []string) error {
listImageSpec := args[0]
instanceSpec := args[1]
if listImageSpec == "" {
return errors.Errorf(`invalid image name "%s"`, listImageSpec)
}
if instanceSpec == "" {
return errors.Errorf(`invalid image digest "%s"`, instanceSpec)
}
updatedListID, err := registry.ImageEngine().ManifestAnnotate(context.Background(), args, manifestAnnotateOpts)
id, err := registry.ImageEngine().ManifestAnnotate(registry.Context(), args[0], args[1], manifestAnnotateOpts)
if err != nil {
return err
}
fmt.Printf("%s\n", updatedListID)
fmt.Println(id)
return nil
}
3 changes: 1 addition & 2 deletions cmd/podman/manifest/create.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package manifest

import (
"context"
"fmt"

"github.com/containers/podman/v3/cmd/podman/common"
Expand Down Expand Up @@ -36,7 +35,7 @@ func init() {
}

func create(cmd *cobra.Command, args []string) error {
imageID, err := registry.ImageEngine().ManifestCreate(context.Background(), args[:1], args[1:], manifestCreateOpts)
imageID, err := registry.ImageEngine().ManifestCreate(registry.Context(), args[0], args[1:], manifestCreateOpts)
if err != nil {
return err
}
Expand Down
5 changes: 2 additions & 3 deletions cmd/podman/manifest/inspect.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package manifest

import (
"context"
"fmt"

"github.com/containers/podman/v3/cmd/podman/common"
Expand Down Expand Up @@ -29,10 +28,10 @@ func init() {
}

func inspect(cmd *cobra.Command, args []string) error {
buf, err := registry.ImageEngine().ManifestInspect(context.Background(), args[0])
buf, err := registry.ImageEngine().ManifestInspect(registry.Context(), args[0])
if err != nil {
return err
}
fmt.Printf("%s\n", buf)
fmt.Println(string(buf))
return nil
}
17 changes: 4 additions & 13 deletions cmd/podman/manifest/remove.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package manifest

import (
"context"
"fmt"

"github.com/containers/podman/v3/cmd/podman/common"
Expand All @@ -16,9 +15,9 @@ var (
Short: "Remove an entry from a manifest list or image index",
Long: "Removes an image from a manifest list or image index.",
RunE: remove,
Args: cobra.ExactArgs(2),
ValidArgsFunction: common.AutocompleteImages,
Example: `podman manifest remove mylist:v1.11 sha256:15352d97781ffdf357bf3459c037be3efac4133dc9070c2dce7eca7c05c3e736`,
Args: cobra.ExactArgs(2),
}
)

Expand All @@ -30,18 +29,10 @@ func init() {
}

func remove(cmd *cobra.Command, args []string) error {
listImageSpec := args[0]
instanceSpec := args[1]
if listImageSpec == "" {
return errors.Errorf(`invalid image name "%s"`, listImageSpec)
}
if instanceSpec == "" {
return errors.Errorf(`invalid image digest "%s"`, instanceSpec)
}
updatedListID, err := registry.ImageEngine().ManifestRemove(context.Background(), args)
updatedListID, err := registry.ImageEngine().ManifestRemoveDigest(registry.Context(), args[0], args[1])
if err != nil {
return errors.Wrapf(err, "error removing from manifest list %s", listImageSpec)
return errors.Wrapf(err, "error removing from manifest list %s", args[0])
}
fmt.Printf("%s\n", updatedListID)
fmt.Println(updatedListID)
return nil
}
4 changes: 2 additions & 2 deletions cmd/podman/manifest/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import (

var (
rmCmd = &cobra.Command{
Use: "rm LIST",
Use: "rm LIST [LIST...]",
Short: "Remove manifest list or image index from local storage",
Long: "Remove manifest list or image index from local storage.",
RunE: rm,
Args: cobra.MinimumNArgs(1),
ValidArgsFunction: common.AutocompleteImages,
Example: `podman manifest rm mylist:v1.11`,
Args: cobra.ExactArgs(1),
}
)

Expand Down
Loading

0 comments on commit 8a7e709

Please sign in to comment.