Skip to content

Commit

Permalink
Merge pull request #2205 from hellocn9/feature/skip-remove-artifact
Browse files Browse the repository at this point in the history
Add Flag --skip-remove-artifact to remain kubekey/artifact dir after exporting an artifact
  • Loading branch information
ks-ci-bot committed Apr 12, 2024
2 parents 0b5f9e1 + 82f2a75 commit b872915
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
22 changes: 13 additions & 9 deletions cmd/kk/cmd/artifact/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ import (
type ArtifactExportOptions struct {
CommonOptions *options.CommonOptions

ManifestFile string
Output string
CriSocket string
DownloadCmd string
ManifestFile string
Output string
CriSocket string
DownloadCmd string
SkipRemoveArtifact bool
}

func NewArtifactExportOptions() *ArtifactExportOptions {
Expand Down Expand Up @@ -76,11 +77,12 @@ func (o *ArtifactExportOptions) Validate(_ []string) error {

func (o *ArtifactExportOptions) Run() error {
arg := common.ArtifactArgument{
ManifestFile: o.ManifestFile,
Output: o.Output,
CriSocket: o.CriSocket,
Debug: o.CommonOptions.Verbose,
IgnoreErr: o.CommonOptions.IgnoreErr,
ManifestFile: o.ManifestFile,
Output: o.Output,
CriSocket: o.CriSocket,
Debug: o.CommonOptions.Verbose,
IgnoreErr: o.CommonOptions.IgnoreErr,
SkipRemoveArtifact: o.SkipRemoveArtifact,
}

return pipelines.ArtifactExport(arg, o.DownloadCmd)
Expand All @@ -91,4 +93,6 @@ 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().BoolVarP(&o.SkipRemoveArtifact, "skip-remove-artifact", "", false, "Skip remove artifact")

}
5 changes: 5 additions & 0 deletions cmd/kk/pkg/artifact/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ func (a *ArchiveDependencies) Execute(runtime connector.Runtime) error {
return errors.Wrapf(errors.WithStack(err), "archive %s failed", src)
}

// skip remove artifact if --skip-remove-artifact
if a.Manifest.Arg.SkipRemoveArtifact {
return nil
}

// remove the src directory
if err := os.RemoveAll(src); err != nil {
return errors.Wrapf(errors.WithStack(err), "remove %s failed", src)
Expand Down
13 changes: 7 additions & 6 deletions cmd/kk/pkg/common/artifact_runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ import (
)

type ArtifactArgument struct {
ManifestFile string
Output string
CriSocket string
Debug bool
IgnoreErr bool
DownloadCommand func(path, url string) string
ManifestFile string
Output string
CriSocket string
Debug bool
IgnoreErr bool
DownloadCommand func(path, url string) string
SkipRemoveArtifact bool
}

type ArtifactRuntime struct {
Expand Down

0 comments on commit b872915

Please sign in to comment.