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

Commit e68fb04

Browse files
authored
Fix RBAC and local image resolution for acorn copy (#1950)
Signed-off-by: Grant Linville <[email protected]>
1 parent 2008864 commit e68fb04

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

pkg/cli/copy.go

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,25 @@ func (a *ImageCopy) Run(cmd *cobra.Command, args []string) error {
5656
return err
5757
}
5858

59+
if !a.AllTags {
60+
// Check if the source argument matches the name of a local image, and use it if it does.
61+
// If there is an error, ignore it and move on, treating the argument as a remote image name.
62+
if _, err := c.ImageGet(cmd.Context(), args[0]); err == nil {
63+
return a.copyLocalToRemote(cmd, c, args, creds)
64+
}
65+
}
66+
5967
source, err := name.ParseReference(args[0])
6068
if err != nil {
6169
return err
6270
}
6371

64-
dest, err := name.ParseReference(args[1])
72+
sourceAuth, _, err := creds.Get(cmd.Context(), source.Context().RegistryStr())
6573
if err != nil {
6674
return err
6775
}
6876

69-
sourceAuth, _, err := creds.Get(cmd.Context(), source.Context().RegistryStr())
77+
dest, err := name.ParseReference(args[1])
7078
if err != nil {
7179
return err
7280
}
@@ -88,3 +96,25 @@ func (a *ImageCopy) Run(cmd *cobra.Command, args []string) error {
8896

8997
return progressbar.Print(progress)
9098
}
99+
100+
func (a *ImageCopy) copyLocalToRemote(cmd *cobra.Command, c client.Client, args []string, creds *credentials.Store) error {
101+
dest, err := name.ParseReference(args[1])
102+
if err != nil {
103+
return err
104+
}
105+
106+
destAuth, _, err := creds.Get(cmd.Context(), dest.Context().RegistryStr())
107+
if err != nil {
108+
return err
109+
}
110+
111+
progress, err := c.ImageCopy(cmd.Context(), args[0], args[1], &client.ImageCopyOptions{
112+
Force: a.Force,
113+
DestAuth: destAuth,
114+
})
115+
if err != nil {
116+
return err
117+
}
118+
119+
return progressbar.Print(progress)
120+
}

pkg/roles/roles.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ var (
123123
Resources: []string{
124124
"images/push",
125125
"images/pull",
126+
"images/copy",
126127
"containerreplicas/exec",
127128
"secrets/reveal",
128129
},

0 commit comments

Comments
 (0)