diff --git a/.github/workflows/contributors.yml b/.github/workflows/contributors.yml new file mode 100644 index 00000000..8d775252 --- /dev/null +++ b/.github/workflows/contributors.yml @@ -0,0 +1,16 @@ +# on: +# push: +# branches: +# - master + +# name: Generate a list of contributors + +# jobs: +# contrib-readme-en-job: +# runs-on: ubuntu-latest +# name: A job to automate contrib in readme +# steps: +# - name: Contribute List +# uses: akhilmhdh/contributors-readme-action@v2.3.4 +# env: +# GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index fec35f66..ec004b8f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -5,6 +5,9 @@ on: tags: - 'v*' +permissions: + contents: write + jobs: release: name: Release diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 9043a3f5..1e12833a 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -180,6 +180,8 @@ nfpms: group: notRoot changelog: sort: asc + skip: false + use: github filters: exclude: - '^docs:' @@ -200,3 +202,14 @@ changelog: order: 10 - title: Other work order: 999 + +release: + # If set to true, will not auto-publish the release. + # Default is false. + draft: false + + # If set to auto, will mark the release as not ready for production + # in case there is an indicator for this in the tag e.g. v1.0.0-rc1 + # If set to true, will mark the release as not ready for production. + # Default is false. + prerelease: auto diff --git a/README.md b/README.md index 13b7dc2d..34ba2766 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,6 @@ [![TODOs](https://img.shields.io/endpoint?url=https://api.tickgit.com/badge?repo=github.com/easysoft/qucheng_cli)](https://www.tickgit.com/browse?repo=github.com/easysoft/qucheng_cli) [![docs](https://img.shields.io/badge/docs-done-green)](https://www.qucheng.com/) - > 中文 | [English](README-EN.md) 使用 `qcadmin`(`q`),您可以轻松、高效、灵活地单独或整体安装渠成平台。 @@ -113,3 +112,11 @@ q init --podsubnet 10.42.0.0/16 --svcsubnet 10.43.0.0/16 ## 相关文档 [版本升级](https://github.com/easysoft/qucheng_cli/wiki/%E7%89%88%E6%9C%AC%E5%8D%87%E7%BA%A7) + +## Contributors + + + + + + diff --git a/cmd/bug-report.go b/cmd/bug-report.go index 3ba6c56a..c63a0db3 100644 --- a/cmd/bug-report.go +++ b/cmd/bug-report.go @@ -12,25 +12,33 @@ import ( "runtime/debug" "github.com/easysoft/qcadmin/common" + "github.com/easysoft/qcadmin/internal/pkg/util/factory" "github.com/easysoft/qcadmin/internal/pkg/util/log" "github.com/spf13/cobra" ) -func newCmdBugReport() *cobra.Command { +type bugReportCmd struct { + log log.Logger +} + +func newCmdBugReport(f factory.Factory) *cobra.Command { + br := bugReportCmd{ + log: f.GetLog(), + } cmd := &cobra.Command{ Use: "bug-report", Short: "Display system information for bug report", Long: "this command shares no personally-identifiable information, and is unused unless you share the bug identifier with our team.", RunE: func(cmd *cobra.Command, args []string) error { - return bugReport() + return br.BugReport() }, } return cmd } -func bugReport() error { - log := log.GetInstance() - log.Info("Issue: 🐛Bug Report: https://github.com/easysoft/qucheng_cli/issues/new?assignees=&labels=&template=bug-report.md") +func (br bugReportCmd) BugReport() error { + bugmsg := "found bug: submit the error message to Github or Gitee\n\t Github: https://github.com/easysoft/qucheng_cli/issues/new?assignees=&labels=&template=bug-report.md\n\t Gitee: https://gitee.com/wwccss/qucheng_cli/issues\n" + br.log.Info(bugmsg) // TODO 详细信息 sprintf := func(key, val string) string { return fmt.Sprintf("%-24s%s\n", key, val) diff --git a/cmd/experimental/helm.go b/cmd/experimental/helm.go index 3712399e..654be27a 100644 --- a/cmd/experimental/helm.go +++ b/cmd/experimental/helm.go @@ -14,5 +14,5 @@ import ( // HelmCommand helm command. func HelmCommand(f factory.Factory) *cobra.Command { - return helm.EmbedCommand() + return helm.EmbedCommand(f) } diff --git a/cmd/init.go b/cmd/init.go index 7a02b5ae..b58c7bba 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -65,6 +65,7 @@ func newCmdInit(f factory.Factory) *cobra.Command { log.Fatalf("failed to stage files: %s", err) return } + cp.SetLog(log) if name != "incluster" { if err := cp.PreSystemInit(); err != nil { log.Fatalf("presystem init err, reason: %s", err) diff --git a/cmd/join.go b/cmd/join.go index 5e3eb5e5..dbc179d1 100644 --- a/cmd/join.go +++ b/cmd/join.go @@ -13,7 +13,6 @@ import ( "github.com/easysoft/qcadmin/internal/app/config" "github.com/easysoft/qcadmin/internal/pkg/providers" "github.com/easysoft/qcadmin/internal/pkg/util/factory" - "github.com/easysoft/qcadmin/internal/pkg/util/log" "github.com/easysoft/qcadmin/internal/static" "github.com/spf13/cobra" ) @@ -56,12 +55,12 @@ func newCmdJoin(f factory.Factory) *cobra.Command { log.Fatal(err) } } - joinCmd.AddCommand(newCmdGenJoin()) + joinCmd.AddCommand(newCmdGenJoin(f)) return joinCmd } -func newCmdGenJoin() *cobra.Command { - log := log.GetInstance() +func newCmdGenJoin(f factory.Factory) *cobra.Command { + log := f.GetLog() genjoin := &cobra.Command{ Use: "gen", Short: "Generate a join command", diff --git a/cmd/manage.go b/cmd/manage.go index b7c504f2..03e5256a 100644 --- a/cmd/manage.go +++ b/cmd/manage.go @@ -8,27 +8,28 @@ package cmd import ( "github.com/easysoft/qcadmin/cmd/manage" + "github.com/easysoft/qcadmin/internal/pkg/util/factory" "github.com/spf13/cobra" ) -func newCmdManage() *cobra.Command { +func newCmdManage(f factory.Factory) *cobra.Command { m := &cobra.Command{ Use: "manage", Short: "Manage qucheng tools", Aliases: []string{"m", "op"}, } - m.AddCommand(manage.NewCmdPlugin()) - m.AddCommand(manage.NewResetPassword()) - m.AddCommand(manage.NewUpgradeQucheg()) + m.AddCommand(manage.NewCmdPlugin(f)) + m.AddCommand(manage.NewResetPassword(f)) + m.AddCommand(manage.NewUpgradeQucheg(f)) return m } -func newCmdManageGet() *cobra.Command { +func newCmdManageGet(f factory.Factory) *cobra.Command { m := &cobra.Command{ Use: "get", Short: "Display one or many resources.", } - m.AddCommand(manage.NewCmdGetNode()) - m.AddCommand(manage.NewCmdGetApp()) + m.AddCommand(manage.NewCmdGetNode(f)) + m.AddCommand(manage.NewCmdGetApp(f)) return m } diff --git a/cmd/manage/get.go b/cmd/manage/get.go index c3607f85..a8b1686f 100644 --- a/cmd/manage/get.go +++ b/cmd/manage/get.go @@ -10,11 +10,11 @@ import ( "os" qcexec "github.com/easysoft/qcadmin/internal/pkg/util/exec" - "github.com/easysoft/qcadmin/internal/pkg/util/log" + "github.com/easysoft/qcadmin/internal/pkg/util/factory" "github.com/spf13/cobra" ) -func NewCmdGetNode() *cobra.Command { +func NewCmdGetNode(f factory.Factory) *cobra.Command { node := &cobra.Command{ Use: "node", Aliases: []string{"no", "nodes"}, @@ -32,8 +32,8 @@ func NewCmdGetNode() *cobra.Command { return node } -func NewCmdGetApp() *cobra.Command { - log := log.GetInstance() +func NewCmdGetApp(f factory.Factory) *cobra.Command { + log := f.GetLog() app := &cobra.Command{ Use: "app", Aliases: []string{"apps"}, diff --git a/cmd/manage/plugin.go b/cmd/manage/plugin.go index 07fe7931..bcd359a2 100644 --- a/cmd/manage/plugin.go +++ b/cmd/manage/plugin.go @@ -13,6 +13,7 @@ import ( "github.com/easysoft/qcadmin/common" "github.com/easysoft/qcadmin/internal/pkg/k8s" pluginapi "github.com/easysoft/qcadmin/internal/pkg/plugin" + "github.com/easysoft/qcadmin/internal/pkg/util/factory" "github.com/easysoft/qcadmin/internal/pkg/util/output" "github.com/easysoft/qcadmin/internal/static/deploy" "github.com/gosuri/uitable" @@ -21,20 +22,20 @@ import ( var show string -func NewCmdPlugin() *cobra.Command { +func NewCmdPlugin(f factory.Factory) *cobra.Command { cmd := &cobra.Command{ Use: "plugins", Short: "manage plugin", Aliases: []string{"plugin"}, } - cmd.AddCommand(listPluginCmd()) - cmd.AddCommand(installPluginCmd()) - cmd.AddCommand(unInstallPluginCmd()) - cmd.AddCommand(syncPluginFileCmd()) + cmd.AddCommand(listPluginCmd(f)) + cmd.AddCommand(installPluginCmd(f)) + cmd.AddCommand(unInstallPluginCmd(f)) + cmd.AddCommand(syncPluginFileCmd(f)) return cmd } -func syncPluginFileCmd() *cobra.Command { +func syncPluginFileCmd(f factory.Factory) *cobra.Command { sync := &cobra.Command{ Use: "sync", Short: "sync plugin file", @@ -52,7 +53,7 @@ func syncPluginFileCmd() *cobra.Command { return sync } -func listPluginCmd() *cobra.Command { +func listPluginCmd(f factory.Factory) *cobra.Command { listcmd := &cobra.Command{ Use: "list", Short: "list plugin", @@ -93,7 +94,7 @@ func listPluginCmd() *cobra.Command { return listcmd } -func installPluginCmd() *cobra.Command { +func installPluginCmd(f factory.Factory) *cobra.Command { cmd := &cobra.Command{ Use: "enable", Short: "install plugin", @@ -115,7 +116,7 @@ func installPluginCmd() *cobra.Command { return cmd } -func unInstallPluginCmd() *cobra.Command { +func unInstallPluginCmd(f factory.Factory) *cobra.Command { cmd := &cobra.Command{ Use: "disable", Short: "uninstall plugin", diff --git a/cmd/manage/resetpassword.go b/cmd/manage/resetpassword.go index 133229a2..e0c8bdd2 100644 --- a/cmd/manage/resetpassword.go +++ b/cmd/manage/resetpassword.go @@ -13,7 +13,7 @@ import ( "github.com/easysoft/qcadmin/common" "github.com/easysoft/qcadmin/internal/pkg/k8s" - "github.com/easysoft/qcadmin/internal/pkg/util/log" + "github.com/easysoft/qcadmin/internal/pkg/util/factory" "github.com/ergoapi/util/color" "github.com/ergoapi/util/exnet" "github.com/ergoapi/util/expass" @@ -35,8 +35,8 @@ type Body struct { Password string `json:"password"` } -func NewResetPassword() *cobra.Command { - log := log.GetInstance() +func NewResetPassword(f factory.Factory) *cobra.Command { + log := f.GetLog() var password string rp := &cobra.Command{ Use: "reset-password", diff --git a/cmd/manage/upgrade.go b/cmd/manage/upgrade.go index ced3eb9a..d3a65d41 100644 --- a/cmd/manage/upgrade.go +++ b/cmd/manage/upgrade.go @@ -9,6 +9,7 @@ package manage import ( "fmt" + "github.com/easysoft/qcadmin/internal/pkg/util/factory" "github.com/easysoft/qcadmin/internal/pkg/util/log" "github.com/easysoft/qcadmin/pkg/qucheng/upgrade" "github.com/spf13/cobra" @@ -20,8 +21,10 @@ type UpgradeCmd struct { log log.Logger } -func NewUpgradeQucheg() *cobra.Command { - upcmd := &UpgradeCmd{} +func NewUpgradeQucheg(f factory.Factory) *cobra.Command { + upcmd := &UpgradeCmd{ + log: f.GetLog(), + } up := &cobra.Command{ Use: "upgrade", Short: "Upgrades the QuCheng to the newest version", diff --git a/cmd/precheck.go b/cmd/precheck.go index 5c988ac3..03d78372 100644 --- a/cmd/precheck.go +++ b/cmd/precheck.go @@ -8,10 +8,11 @@ package cmd import ( "github.com/easysoft/qcadmin/cmd/precheck" + "github.com/easysoft/qcadmin/internal/pkg/util/factory" "github.com/spf13/cobra" ) -func newCmdPreCheck() *cobra.Command { +func newCmdPreCheck(f factory.Factory) *cobra.Command { var pc precheck.PreCheck cmd := &cobra.Command{ Use: "precheck", diff --git a/cmd/root.go b/cmd/root.go index 0894917a..7ed095a7 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -17,6 +17,7 @@ import ( "github.com/easysoft/qcadmin/cmd/flags" "github.com/easysoft/qcadmin/common" "github.com/easysoft/qcadmin/internal/pkg/util/factory" + "github.com/easysoft/qcadmin/internal/pkg/util/log" mcobra "github.com/muesli/mango-cobra" "github.com/muesli/roff" "github.com/sirupsen/logrus" @@ -46,6 +47,11 @@ func Execute() { } else { f.GetLog().Fatal(err) } + if !strings.Contains(err.Error(), "unknown command") { + f.GetLog().Info("----------------------------") + bugmsg := "found bug: submit the error message to Github or Gitee\n\t Github: https://github.com/easysoft/qucheng_cli/issues/new?assignees=&labels=&template=bug-report.md\n\t Gitee: https://gitee.com/wwccss/qucheng_cli/issues" + f.GetLog().Info(bugmsg) + } } } @@ -56,20 +62,20 @@ func BuildRoot(f factory.Factory) *cobra.Command { persistentFlags := rootCmd.PersistentFlags() globalFlags = flags.SetGlobalFlags(persistentFlags) // Add main commands - rootCmd.AddCommand(newCmdVersion()) - rootCmd.AddCommand(newCmdPreCheck()) + rootCmd.AddCommand(newCmdVersion(f)) + rootCmd.AddCommand(newCmdPreCheck(f)) rootCmd.AddCommand(newCmdInit(f)) rootCmd.AddCommand(newCmdJoin(f)) - rootCmd.AddCommand(newCmdUninstall()) - rootCmd.AddCommand(newCmdStatus()) - rootCmd.AddCommand(newCmdUpgrade()) - rootCmd.AddCommand(newCmdManage()) - rootCmd.AddCommand(newCmdManageGet()) + rootCmd.AddCommand(newCmdUninstall(f)) + rootCmd.AddCommand(newCmdStatus(f)) + rootCmd.AddCommand(newCmdUpgrade(f)) + rootCmd.AddCommand(newCmdManage(f)) + rootCmd.AddCommand(newCmdManageGet(f)) // Add plugin commands rootCmd.AddCommand(NewCmdExperimental(f)) rootCmd.AddCommand(newManCmd()) - rootCmd.AddCommand(newCmdBugReport()) + rootCmd.AddCommand(newCmdBugReport(f)) args := os.Args if len(args) > 1 { @@ -110,13 +116,14 @@ func NewRootCmd(f factory.Factory) *cobra.Command { if cobraCmd.Annotations != nil { return nil } - log := f.GetLog() + qlog := f.GetLog() if globalFlags.Silent { - log.SetLevel(logrus.FatalLevel) + qlog.SetLevel(logrus.FatalLevel) } else if globalFlags.Debug { - log.SetLevel(logrus.DebugLevel) + qlog.SetLevel(logrus.DebugLevel) } + log.StartFileLogging() // TODO apply extra flags return nil }, diff --git a/cmd/status.go b/cmd/status.go index f062cc7f..3e417489 100644 --- a/cmd/status.go +++ b/cmd/status.go @@ -13,14 +13,14 @@ import ( statussubcmd "github.com/easysoft/qcadmin/cmd/status" "github.com/easysoft/qcadmin/common" "github.com/easysoft/qcadmin/internal/pkg/status" - "github.com/easysoft/qcadmin/internal/pkg/util/log" + "github.com/easysoft/qcadmin/internal/pkg/util/factory" "github.com/ergoapi/util/color" "github.com/ergoapi/util/file" "github.com/spf13/cobra" ) -func newCmdStatus() *cobra.Command { - log := log.GetInstance() +func newCmdStatus(f factory.Factory) *cobra.Command { + log := f.GetLog() var params = status.K8sStatusOption{ Log: log, } diff --git a/cmd/uninstall.go b/cmd/uninstall.go index bec7eccd..f83d2a9d 100644 --- a/cmd/uninstall.go +++ b/cmd/uninstall.go @@ -8,18 +8,19 @@ package cmd import ( "github.com/easysoft/qcadmin/internal/pkg/cluster" - "github.com/easysoft/qcadmin/internal/pkg/util/log" + "github.com/easysoft/qcadmin/internal/pkg/util/factory" "github.com/spf13/cobra" ) -func newCmdUninstall() *cobra.Command { - log := log.GetInstance() +func newCmdUninstall(f factory.Factory) *cobra.Command { + log := f.GetLog() return &cobra.Command{ Use: "uninstall", Short: "Uninstall", Run: func(cmd *cobra.Command, args []string) { log.Info("start uninstall cluster") c := cluster.NewCluster() + c.Log = log err := c.Uninstall() if err != nil { log.Fatalf("uninstall cluster failed, reason: %v", err) diff --git a/cmd/upgrade.go b/cmd/upgrade.go index c00b9206..915509e7 100644 --- a/cmd/upgrade.go +++ b/cmd/upgrade.go @@ -8,15 +8,16 @@ package cmd import ( "github.com/easysoft/qcadmin/cmd/upgrade" + "github.com/easysoft/qcadmin/internal/pkg/util/factory" "github.com/spf13/cobra" ) -func newCmdUpgrade() *cobra.Command { +func newCmdUpgrade(f factory.Factory) *cobra.Command { up := &cobra.Command{ Use: "upgrade", Short: "Upgrades the Q CLI to the newest version", Aliases: []string{"ug", "ugc"}, } - up.AddCommand(upgrade.NewUpgradeQ()) + up.AddCommand(upgrade.NewUpgradeQ(f)) return up } diff --git a/cmd/upgrade/q.go b/cmd/upgrade/q.go index 5cd9c74f..6d75f299 100644 --- a/cmd/upgrade/q.go +++ b/cmd/upgrade/q.go @@ -14,50 +14,57 @@ import ( "github.com/easysoft/qcadmin/cmd/version" "github.com/easysoft/qcadmin/common" + "github.com/easysoft/qcadmin/internal/pkg/util/factory" "github.com/easysoft/qcadmin/internal/pkg/util/log" "github.com/easysoft/qcadmin/pkg/selfupdate" "github.com/spf13/cobra" ) -func NewUpgradeQ() *cobra.Command { +type option struct { + log log.Logger +} + +func NewUpgradeQ(f factory.Factory) *cobra.Command { + up := option{ + log: f.GetLog(), + } upq := &cobra.Command{ Use: "q", Aliases: []string{"qcadmin"}, Short: "upgrade qcadmin(q) to the newest version", Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { - DoQcadmin() + up.DoQcadmin() }, } return upq } -func DoQcadmin() { - logutil := log.GetInstance() - logutil.StartWait("fetch latest version from remote...") +func (up option) DoQcadmin() { + up.log.StartWait("fetch latest version from remote...") lastversion, err := version.PreCheckLatestVersion() - logutil.StopWait() + up.log.StopWait() if err != nil { - logutil.Errorf("fetch latest version err, reason: %v", err) + up.log.Errorf("fetch latest version err, reason: %v", err) return } if lastversion == "" || lastversion == common.Version || strings.Contains(common.Version, lastversion) { - logutil.Infof("The current version %s is the latest version", common.Version) + up.log.Infof("The current version %s is the latest version", common.Version) return } cmdPath, err := os.Executable() if err != nil { - logutil.Errorf("q executable err:%v", err) + up.log.Errorf("q executable err:%v", err) return } - logutil.StartWait(fmt.Sprintf("downloading version %s...", lastversion)) + up.log.StartWait(fmt.Sprintf("downloading version %s...", lastversion)) assetURL := fmt.Sprintf("https://pkg.qucheng.com/qucheng/cli/stable/qcadmin_%s_%s", runtime.GOOS, runtime.GOARCH) - err = selfupdate.UpdateTo(logutil, assetURL, cmdPath) - logutil.StopWait() + err = selfupdate.UpdateTo(up.log, assetURL, cmdPath) + up.log.StopWait() if err != nil { - logutil.Errorf("upgrade failed, reason: %v", err) + up.log.Errorf("upgrade failed, reason: %v", err) return } - logutil.Donef("Successfully updated ergo to version %s", lastversion) - logutil.Infof("Release note: \n\trelease %s ", lastversion) + up.log.Donef("Successfully updated ergo to version %s", lastversion) + up.log.Infof("Release note: \n\trelease %s ", lastversion) } diff --git a/cmd/version.go b/cmd/version.go index 7b9bb04e..9e23fbd3 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -8,17 +8,18 @@ package cmd import ( "github.com/easysoft/qcadmin/cmd/version" + "github.com/easysoft/qcadmin/internal/pkg/util/factory" "github.com/spf13/cobra" ) // newCmdVersion show version -func newCmdVersion() *cobra.Command { +func newCmdVersion(f factory.Factory) *cobra.Command { return &cobra.Command{ Use: "version", Short: "Show version", Args: cobra.NoArgs, Run: func(cobraCmd *cobra.Command, args []string) { - version.ShowVersion() + version.ShowVersion(f.GetLog()) }, } } diff --git a/cmd/version/version.go b/cmd/version/version.go index 6367185e..c460c619 100644 --- a/cmd/version/version.go +++ b/cmd/version/version.go @@ -17,7 +17,7 @@ import ( gv "github.com/Masterminds/semver/v3" "github.com/easysoft/qcadmin/common" - "github.com/easysoft/qcadmin/internal/pkg/util/log" + logpkg "github.com/easysoft/qcadmin/internal/pkg/util/log" "github.com/easysoft/qcadmin/pkg/qucheng/upgrade" "github.com/ergoapi/util/color" "github.com/ergoapi/util/file" @@ -117,8 +117,7 @@ func PreCheckLatestVersion() (string, error) { return lastVersion.Data.Version, nil } -func ShowVersion() { - log := log.GetInstance() +func ShowVersion(log logpkg.Logger) { // logo.PrintLogo() if common.Version == "" { common.Version = defaultVersion diff --git a/internal/pkg/cli/helm/helm.go b/internal/pkg/cli/helm/helm.go index 384c6a79..d07d647a 100644 --- a/internal/pkg/cli/helm/helm.go +++ b/internal/pkg/cli/helm/helm.go @@ -9,24 +9,25 @@ package helm import ( "fmt" + "github.com/easysoft/qcadmin/internal/pkg/util/factory" "github.com/easysoft/qcadmin/internal/pkg/util/helm" "github.com/spf13/cobra" ) -func EmbedCommand() *cobra.Command { +func EmbedCommand(f factory.Factory) *cobra.Command { helm := &cobra.Command{ Use: "helm", Short: "The Kubernetes package manager", } - helm.AddCommand(repoUpdate()) - helm.AddCommand(repoAdd()) - helm.AddCommand(repoDel()) - helm.AddCommand(chartUpgrade()) - helm.AddCommand(chartUninstall()) + helm.AddCommand(repoUpdate(f)) + helm.AddCommand(repoAdd(f)) + helm.AddCommand(repoDel(f)) + helm.AddCommand(chartUpgrade(f)) + helm.AddCommand(chartUninstall(f)) return helm } -func repoUpdate() *cobra.Command { +func repoUpdate(f factory.Factory) *cobra.Command { helm := &cobra.Command{ Use: "repo-update", Short: "update information of available charts locally from chart repositories", @@ -42,7 +43,7 @@ func repoUpdate() *cobra.Command { return helm } -func repoAdd() *cobra.Command { +func repoAdd(f factory.Factory) *cobra.Command { var name, url, username, password string helm := &cobra.Command{ Use: "repo-add", @@ -65,7 +66,7 @@ func repoAdd() *cobra.Command { return helm } -func repoDel() *cobra.Command { +func repoDel(f factory.Factory) *cobra.Command { var name string helm := &cobra.Command{ Use: "repo-del", @@ -86,7 +87,7 @@ func repoDel() *cobra.Command { return helm } -func chartUpgrade() *cobra.Command { +func chartUpgrade(f factory.Factory) *cobra.Command { var ns, name, repoName, chartName, chartVersion string var p []string helm := &cobra.Command{ @@ -120,7 +121,7 @@ func chartUpgrade() *cobra.Command { return helm } -func chartUninstall() *cobra.Command { +func chartUninstall(f factory.Factory) *cobra.Command { var ns, name string helm := &cobra.Command{ Use: "uninstall", @@ -140,8 +141,12 @@ func chartUninstall() *cobra.Command { if err != nil { return fmt.Errorf("helm create go client err: %v", err) } - _, err = hc.Uninstall(name) - return err + release, _ := hc.GetDetail(name) + if release != nil { + _, err = hc.Uninstall(name) + return err + } + return nil }, } helm.Flags().StringVarP(&ns, "namespace", "n", "", "namespace") diff --git a/internal/pkg/cluster/cluster.go b/internal/pkg/cluster/cluster.go index e52b22b5..9a9c178d 100644 --- a/internal/pkg/cluster/cluster.go +++ b/internal/pkg/cluster/cluster.go @@ -43,7 +43,6 @@ type Cluster struct { } func NewCluster() *Cluster { - log := log.GetFileLogger(fmt.Sprintf("cluster.init.%s.log", ztime.GetTodayHour())) return &Cluster{ Metadata: types.Metadata{ ClusterCidr: "10.42.0.0/16", @@ -52,8 +51,7 @@ func NewCluster() *Cluster { QuchengVersion: "stable", DisableIngress: false, }, - M: new(syncmap.Map), - Log: log, + M: new(syncmap.Map), } } diff --git a/internal/pkg/providers/incluster/incluster.go b/internal/pkg/providers/incluster/incluster.go index 4d77f84b..2792df46 100644 --- a/internal/pkg/providers/incluster/incluster.go +++ b/internal/pkg/providers/incluster/incluster.go @@ -16,6 +16,7 @@ import ( "github.com/easysoft/qcadmin/internal/pkg/providers" "github.com/easysoft/qcadmin/internal/pkg/types" "github.com/easysoft/qcadmin/internal/pkg/util/kutil" + "github.com/easysoft/qcadmin/internal/pkg/util/log" "github.com/ergoapi/util/exnet" "github.com/ergoapi/util/file" "github.com/ergoapi/util/zos" @@ -143,3 +144,7 @@ func (p *InCluster) Show() { p.Log.Donef("docs: %s", common.QuchengDocs) } + +func (p *InCluster) SetLog(log log.Logger) { + p.Log = log +} diff --git a/internal/pkg/providers/native/native.go b/internal/pkg/providers/native/native.go index 155421cd..8053a039 100644 --- a/internal/pkg/providers/native/native.go +++ b/internal/pkg/providers/native/native.go @@ -15,9 +15,11 @@ import ( "github.com/easysoft/qcadmin/internal/pkg/providers" "github.com/easysoft/qcadmin/internal/pkg/types" "github.com/easysoft/qcadmin/internal/pkg/util/kutil" + "github.com/easysoft/qcadmin/internal/pkg/util/log" "github.com/easysoft/qcadmin/internal/pkg/util/preflight" "github.com/ergoapi/util/exnet" "github.com/ergoapi/util/zos" + utilsexec "k8s.io/utils/exec" ) @@ -163,3 +165,7 @@ func (p *Native) Show() { } p.Log.Donef("docs: %s", common.QuchengDocs) } + +func (p *Native) SetLog(log log.Logger) { + p.Log = log +} diff --git a/internal/pkg/providers/providers.go b/internal/pkg/providers/providers.go index d8639525..305f8e38 100644 --- a/internal/pkg/providers/providers.go +++ b/internal/pkg/providers/providers.go @@ -10,6 +10,8 @@ import ( "fmt" "sync" + "github.com/easysoft/qcadmin/internal/pkg/util/log" + "github.com/easysoft/qcadmin/internal/pkg/types" ) @@ -33,6 +35,7 @@ type Provider interface { CreateCheck(skip bool) error PreSystemInit() error Show() + SetLog(log log.Logger) } // RegisterProvider registers a provider.Factory by name. diff --git a/internal/pkg/util/log/log.go b/internal/pkg/util/log/log.go index b492f749..d4929d53 100644 --- a/internal/pkg/util/log/log.go +++ b/internal/pkg/util/log/log.go @@ -7,8 +7,10 @@ package log import ( + "fmt" "strings" + "github.com/easysoft/qcadmin/common" "github.com/mgutz/ansi" "github.com/sirupsen/logrus" ) @@ -21,9 +23,10 @@ var defaultLog Logger = &stdoutLogger{ var Discard = &DiscardLogger{} // StartFileLogging logs the output of the global logger to the file default.log -func StartFileLogging(filename string) { +func StartFileLogging() { defaultLogStdout, ok := defaultLog.(*stdoutLogger) if ok { + filename := fmt.Sprintf("%s.default.log", common.Version) defaultLogStdout.fileLogger = GetFileLogger(filename) }