Skip to content

Commit b1abafd

Browse files
authoredFeb 13, 2025··
Merge pull request #435 from kubenetworks/feat/add-cmd-image-copy
feat: add cmd image copy
2 parents 12f29f2 + 7f3f030 commit b1abafd

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed
 

‎cmd/kubevpn/cmds/imagecopy.go

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package cmds
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
cmdutil "k8s.io/kubectl/pkg/cmd/util"
6+
7+
"github.com/wencaiwulue/kubevpn/v2/pkg/util"
8+
"github.com/wencaiwulue/kubevpn/v2/pkg/util/regctl"
9+
)
10+
11+
func CmdImageCopy(_ cmdutil.Factory) *cobra.Command {
12+
var imageCmd = &cobra.Command{
13+
Use: "image <cmd>",
14+
Short: "copy images",
15+
}
16+
17+
copyCmd := &cobra.Command{
18+
Use: "copy <src_image_ref> <dst_image_ref>",
19+
Aliases: []string{"cp"},
20+
Short: "copy or re-tag image",
21+
Long: `Copy or re-tag an image. This works between registries and only pulls layers
22+
that do not exist at the target. In the same registry it attempts to mount
23+
the layers between repositories. And within the same repository it only
24+
sends the manifest with the new tag.`,
25+
Example: `
26+
# copy an image
27+
regctl image copy ghcr.io/kubenetworks/kubevpn:latest docker.io/naison/kubevpn:latest
28+
29+
# re-tag an image
30+
regctl image copy registry.example.org/repo:v1.2.3 registry.example.org/repo:v1`,
31+
Args: cobra.MatchAll(cobra.ExactArgs(2), cobra.OnlyValidArgs),
32+
PreRunE: func(cmd *cobra.Command, args []string) error {
33+
util.InitLoggerForClient(false)
34+
return nil
35+
},
36+
RunE: func(cmd *cobra.Command, args []string) error {
37+
err := regctl.TransferImageWithRegctl(cmd.Context(), args[0], args[1])
38+
return err
39+
},
40+
}
41+
imageCmd.AddCommand(copyCmd)
42+
return imageCmd
43+
}

‎cmd/kubevpn/cmds/root.go

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ func NewKubeVPNCommand() *cobra.Command {
7777
CmdConfig(factory),
7878
CmdSSH(factory),
7979
CmdSSHDaemon(factory),
80+
CmdImageCopy(factory),
8081
CmdLogs(factory),
8182
CmdCp(factory),
8283
CmdReset(factory),

0 commit comments

Comments
 (0)
Please sign in to comment.