Skip to content

Commit

Permalink
Merge pull request #2266 from will4j/feature/image-start-index
Browse files Browse the repository at this point in the history
Feature/support image start index when export images
  • Loading branch information
ks-ci-bot committed Jun 3, 2024
2 parents af024f2 + b2558eb commit 6beb293
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
3 changes: 3 additions & 0 deletions cmd/kk/cmd/artifact/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type ArtifactExportOptions struct {
Output string
CriSocket string
DownloadCmd string
ImageStartIndex int
ImageTransport string
SkipRemoveArtifact bool
}
Expand Down Expand Up @@ -81,6 +82,7 @@ func (o *ArtifactExportOptions) Run() error {
ManifestFile: o.ManifestFile,
Output: o.Output,
CriSocket: o.CriSocket,
ImageStartIndex: o.ImageStartIndex,
ImageTransport: o.ImageTransport,
Debug: o.CommonOptions.Verbose,
IgnoreErr: o.CommonOptions.IgnoreErr,
Expand All @@ -95,6 +97,7 @@ func (o *ArtifactExportOptions) AddFlags(cmd *cobra.Command) {
cmd.Flags().StringVarP(&o.Output, "output", "o", "", "Path to a output path")
cmd.Flags().StringVarP(&o.DownloadCmd, "download-cmd", "", "curl -L -o %s %s",
`The user defined command to download the necessary binary files. The first param '%s' is output path, the second param '%s', is the URL`)
cmd.Flags().IntVarP(&o.ImageStartIndex, "image-start-index", "", 0, "Save images from specific index, default to 0")
cmd.Flags().StringVarP(&o.ImageTransport, "image-transport", "", "", "Image transport to pull from, take values from [docker, docker-daemon]")
cmd.Flags().BoolVarP(&o.SkipRemoveArtifact, "skip-remove-artifact", "", false, "Skip remove artifact")

Expand Down
1 change: 1 addition & 0 deletions cmd/kk/pkg/common/artifact_runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type ArtifactArgument struct {
Debug bool
IgnoreErr bool
DownloadCommand func(path, url string) string
ImageStartIndex int
ImageTransport string
SkipRemoveArtifact bool
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/kk/pkg/images/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func (p *PullModule) Init() {

type CopyImagesToLocalModule struct {
common.ArtifactModule
ImageStartIndex int
ImageTransport string
}

Expand All @@ -59,7 +60,7 @@ func (c *CopyImagesToLocalModule) Init() {
copyImage := &task.LocalTask{
Name: "SaveImages",
Desc: "Copy images to a local OCI path from registries",
Action: &SaveImages{ImageTransport: c.ImageTransport},
Action: &SaveImages{ImageStartIndex: c.ImageStartIndex, ImageTransport: c.ImageTransport},
}

c.Tasks = []task.Interface{
Expand Down
10 changes: 7 additions & 3 deletions cmd/kk/pkg/images/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ func GetImage(runtime connector.ModuleRuntime, kubeConf *common.KubeConf, name s

type SaveImages struct {
common.ArtifactAction
ImageStartIndex int
ImageTransport string
}

Expand All @@ -165,7 +166,10 @@ func (s *SaveImages) Execute(runtime connector.Runtime) error {
if err := coreutil.Mkdir(dirName); err != nil {
return errors.Wrapf(errors.WithStack(err), "mkdir %s failed", dirName)
}
for _, image := range s.Manifest.Spec.Images {
for index, image := range s.Manifest.Spec.Images {
if s.ImageStartIndex > index {
continue
}
if err := validateImageName(image); err != nil {
return err
}
Expand All @@ -187,8 +191,8 @@ func (s *SaveImages) Execute(runtime connector.Runtime) error {
// oci:./kubekey/artifact/images:docker.io/kubesphere/kube-apiserver:v1.21.5-amd64
// oci:./kubekey/artifact/images:docker.io/kubesphere/kube-apiserver:v1.21.5-arm-v7
destName := fmt.Sprintf("oci:%s:%s-%s%s", dirName, image, arch, variant)
logger.Log.Infof("Source: %s", srcName)
logger.Log.Infof("Destination: %s", destName)
logger.Log.Infof("[%d]Source: %s", index, srcName)
logger.Log.Infof("[%d]Destination: %s", index, destName)

o := &CopyImageOptions{
srcImage: &srcImageOptions{
Expand Down
6 changes: 3 additions & 3 deletions cmd/kk/pkg/pipelines/artifact_export.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
func NewArtifactExportPipeline(runtime *common.ArtifactRuntime) error {
m := []module.Module{
&confirm.CheckFileExistModule{FileName: runtime.Arg.Output},
&images.CopyImagesToLocalModule{ImageTransport: runtime.Arg.ImageTransport},
&images.CopyImagesToLocalModule{ImageStartIndex: runtime.Arg.ImageStartIndex, ImageTransport: runtime.Arg.ImageTransport},
&binaries.ArtifactBinariesModule{},
&artifact.RepositoryModule{},
&artifact.ArchiveModule{},
Expand All @@ -58,7 +58,7 @@ func NewArtifactExportPipeline(runtime *common.ArtifactRuntime) error {
func NewK3sArtifactExportPipeline(runtime *common.ArtifactRuntime) error {
m := []module.Module{
&confirm.CheckFileExistModule{FileName: runtime.Arg.Output},
&images.CopyImagesToLocalModule{},
&images.CopyImagesToLocalModule{ImageStartIndex: runtime.Arg.ImageStartIndex},
&binaries.K3sArtifactBinariesModule{},
&artifact.RepositoryModule{},
&artifact.ArchiveModule{},
Expand All @@ -82,7 +82,7 @@ func NewK3sArtifactExportPipeline(runtime *common.ArtifactRuntime) error {
func NewK8eArtifactExportPipeline(runtime *common.ArtifactRuntime) error {
m := []module.Module{
&confirm.CheckFileExistModule{FileName: runtime.Arg.Output},
&images.CopyImagesToLocalModule{},
&images.CopyImagesToLocalModule{ImageStartIndex: runtime.Arg.ImageStartIndex},
&binaries.K8eArtifactBinariesModule{},
&artifact.RepositoryModule{},
&artifact.ArchiveModule{},
Expand Down

0 comments on commit 6beb293

Please sign in to comment.