mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
feat(climc): upload helm chart to a repository
This commit is contained in:
@@ -15,6 +15,14 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/cheggaaa/pb/v3"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modules/k8s"
|
||||
o "yunion.io/x/onecloud/pkg/mcclient/options/k8s"
|
||||
)
|
||||
@@ -29,4 +37,31 @@ func initRepo() {
|
||||
cmd.Perform("sync", new(o.RepoGetOptions))
|
||||
cmd.Perform("public", new(o.RepoPublicOptions))
|
||||
cmd.Perform("private", new(o.RepoGetOptions))
|
||||
|
||||
type UploadOptions struct {
|
||||
REPO string `help:"The name or id of helm repository`
|
||||
FILE string `help:"Helm packaged file"`
|
||||
}
|
||||
R(new(UploadOptions), "k8s-repo-upload-chart", "Upload chart to the repository", func(s *mcclient.ClientSession, args *UploadOptions) error {
|
||||
f, err := os.Open(args.FILE)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
finfo, err := f.Stat()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
size := finfo.Size()
|
||||
bar := pb.Full.Start64(size)
|
||||
barReader := bar.NewProxyReader(f)
|
||||
param := jsonutils.Marshal(args)
|
||||
param.(*jsonutils.JSONDict).Add(jsonutils.NewString(filepath.Base(args.FILE)), "chart_name")
|
||||
ret, err := k8s.Repos.UploadChart(s, args.REPO, param, barReader, size)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(ret)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user