Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Commit

Permalink
Add imageName to ImageDetail command to support wildcards
Browse files Browse the repository at this point in the history
acorn image detail now support passing patterns supported by autoupgrade.

Signed-off-by: Darren Shepherd <darren@acorn.io>
  • Loading branch information
ibuildthecloud committed Aug 10, 2023
1 parent 0a235a1 commit e018b24
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 9 deletions.
1 change: 1 addition & 0 deletions pkg/apis/api.acorn.io/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ type ImageDetails struct {
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`

// Input Params
ImageName string `json:"imageName,omitempty"`
NestedDigest string `json:"nestedDigest,omitempty"`
DeployArgs v1.GenericMap `json:"deployArgs,omitempty"`
Profiles []string `json:"profiles,omitempty"`
Expand Down
1 change: 1 addition & 0 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ type ImageDetails struct {
AppImage v1.AppImage `json:"appImage,omitempty"`
AppSpec *v1.AppSpec `json:"appSpec,omitempty"`
Params *v1.ParamSpec `json:"params,omitempty"`
ImageName string `json:"imageName,omitempty"`
SignatureDigest string `json:"signatureDigest,omitempty"`
Readme string `json:"readme,omitempty"`
ParseError string `json:"parseError,omitempty"`
Expand Down
9 changes: 5 additions & 4 deletions pkg/client/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ func (c *DefaultClient) ImageTag(ctx context.Context, imageName, tag string) err
}

func (c *DefaultClient) ImageDetails(ctx context.Context, imageName string, opts *ImageDetailsOptions) (*ImageDetails, error) {
imageName = strings.ReplaceAll(imageName, "/", "+")

detailsResult := &apiv1.ImageDetails{}
detailsResult := &apiv1.ImageDetails{
ImageName: imageName,
}

if opts != nil {
detailsResult.DeployArgs = opts.DeployArgs
Expand All @@ -50,7 +50,7 @@ func (c *DefaultClient) ImageDetails(ctx context.Context, imageName string, opts
err := c.RESTClient.Post().
Namespace(c.Namespace).
Resource("images").
Name(imageName).
Name("_").
SubResource("details").
Body(detailsResult).
Do(ctx).Into(detailsResult)
Expand All @@ -59,6 +59,7 @@ func (c *DefaultClient) ImageDetails(ctx context.Context, imageName string, opts
}

return &ImageDetails{
ImageName: detailsResult.ImageName,
AppImage: detailsResult.AppImage,
AppSpec: detailsResult.AppSpec,
Readme: detailsResult.Readme,
Expand Down
1 change: 1 addition & 0 deletions pkg/imagedetails/imagedetails.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ func GetImageDetails(ctx context.Context, c kclient.Client, namespace, imageName
Name: imageName,
Namespace: namespace,
},
ImageName: imageName,
DeployArgs: details.DeployArgs,
Profiles: profiles,
Params: details.Params,
Expand Down
8 changes: 7 additions & 1 deletion pkg/openapi/generated/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions pkg/server/registry/apigroups/acorn/images/detail.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,25 @@ func (s *ImageDetailStrategy) Get(ctx context.Context, namespace, name string) (

func (s *ImageDetailStrategy) Create(ctx context.Context, obj types.Object) (types.Object, error) {
details := obj.(*apiv1.ImageDetails)
if details.Name == "" {
if details.ImageName == "" {
details.ImageName = details.Name
}
if details.ImageName == "" {
ri, ok := request.RequestInfoFrom(ctx)
if ok {
details.Name = ri.Name
details.ImageName = ri.Name
}
}
ns, _ := request.NamespaceFrom(ctx)
opts := []remote.Option{s.remoteOpt}
if details.Auth != nil {
imageName := strings.ReplaceAll(details.Name, "+", "/")
imageName := strings.ReplaceAll(details.ImageName, "+", "/")
ref, err := name.ParseReference(imageName)
if err == nil {
opts = append(opts, remote.WithAuthFromKeychain(images.NewSimpleKeychain(ref.Context(), *details.Auth, nil)))
}
}
return imagedetails.GetImageDetails(ctx, s.client, ns, details.Name, details.Profiles, details.DeployArgs, details.NestedDigest, details.NoDefaultRegistry, opts...)
return imagedetails.GetImageDetails(ctx, s.client, ns, details.ImageName, details.Profiles, details.DeployArgs, details.NestedDigest, details.NoDefaultRegistry, opts...)
}

func (s *ImageDetailStrategy) New() types.Object {
Expand Down

0 comments on commit e018b24

Please sign in to comment.