Skip to content

Commit

Permalink
* refactor: refactor helm client initialization and logging functiona…
Browse files Browse the repository at this point in the history
…lity
  • Loading branch information
ysicing committed Aug 9, 2024
1 parent 0765174 commit e89956c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
1 change: 0 additions & 1 deletion cmd/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ func newCmdUninstall(f factory.Factory) *cobra.Command {
return
}
}
log.Donef("uninstall success")
}
uninstallCmd.PersistentFlags().BoolVar(&cleanCluster, "all", true, "clean all")
return uninstallCmd
Expand Down
3 changes: 3 additions & 0 deletions common/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ ExecStart=/usr/local/bin/k3s \
{{if .DataStore -}}
--datastore-endpoint {{ .DataStore }} \
{{else -}}
{{if not .Master0 -}}
--server https://{{ .KubeAPI }}:6443 \
{{end -}}
--cluster-init \
--etcd-expose-metrics \
--etcd-snapshot-name auto-snapshot \
Expand Down
24 changes: 13 additions & 11 deletions internal/pkg/cli/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
"github.com/easysoft/qcadmin/internal/pkg/k8s"
"github.com/easysoft/qcadmin/internal/pkg/util/factory"
"github.com/easysoft/qcadmin/internal/pkg/util/helm"

exhelm "github.com/easysoft/qcadmin/internal/pkg/util/helm"
)

func EmbedCommand(f factory.Factory) *cobra.Command {
Expand Down Expand Up @@ -43,14 +45,14 @@ func repoInit(f factory.Factory) *cobra.Command {
Short: "init helm repo",
PostRunE: func(cmd *cobra.Command, args []string) error {
logpkg.Debug("update helm repo")
hc, err := helm.NewClient(&helm.Config{Namespace: ""})
hc, err := exhelm.NewClient(&exhelm.Config{Namespace: ""})
if err != nil {
return errors.Errorf("helm create go client err: %v", err)
}
return hc.UpdateRepo()
},
RunE: func(cmd *cobra.Command, args []string) error {
hc, err := helm.NewClient(&helm.Config{Namespace: ""})
hc, err := exhelm.NewClient(&exhelm.Config{Namespace: ""})
if err != nil {
return errors.Errorf("helm create go client err: %v", err)
}
Expand Down Expand Up @@ -85,7 +87,7 @@ func repoList(f factory.Factory) *cobra.Command {
Short: "list helm repo",
RunE: func(cmd *cobra.Command, args []string) error {
logpkg := f.GetLog()
hc, err := helm.NewClient(&helm.Config{Namespace: ""})
hc, err := exhelm.NewClient(&helm.Config{Namespace: ""})
if err != nil {
return errors.Errorf("helm create go client err: %v", err)
}
Expand All @@ -107,7 +109,7 @@ func repoUpdate(f factory.Factory) *cobra.Command {
Use: "repo-update",
Short: "update information of available charts locally from chart repositories",
RunE: func(cmd *cobra.Command, args []string) error {
hc, err := helm.NewClient(&helm.Config{Namespace: ""})
hc, err := exhelm.NewClient(&helm.Config{Namespace: ""})
if err != nil {
return errors.Errorf("helm create go client err: %v", err)
}
Expand All @@ -127,7 +129,7 @@ func repoAdd(f factory.Factory) *cobra.Command {
if len(name) == 0 || len(url) == 0 {
return errors.Errorf("name or url is empty")
}
hc, err := helm.NewClient(&helm.Config{Namespace: ""})
hc, err := exhelm.NewClient(&helm.Config{Namespace: ""})
if err != nil {
return errors.Errorf("helm create go client err: %v", err)
}
Expand All @@ -148,7 +150,7 @@ func repoDel(f factory.Factory) *cobra.Command {
Aliases: []string{"repo-remove"},
Short: "del a chart repository",
RunE: func(cmd *cobra.Command, args []string) error {
hc, err := helm.NewClient(&helm.Config{Namespace: ""})
hc, err := exhelm.NewClient(&helm.Config{Namespace: ""})
if err != nil {
return errors.Errorf("helm create go client err: %v", err)
}
Expand Down Expand Up @@ -187,11 +189,11 @@ func chartUpgrade(f factory.Factory) *cobra.Command {
if ns == "" {
ns = "default"
}
hc, err := helm.NewClient(&helm.Config{Namespace: ns})
hc, err := exhelm.NewClient(&exhelm.Config{Namespace: ns})
if err != nil {
return errors.Errorf("helm create go client err: %v", err)
}
values, _ := helm.MergeValues(p)
values, _ := exhelm.MergeValues(p)
_, err = hc.Upgrade(name, repoName, chartName, chartVersion, values)
return err
},
Expand Down Expand Up @@ -221,7 +223,7 @@ func chartUninstall(f factory.Factory) *cobra.Command {
if ns == "" {
ns = "default"
}
hc, err := helm.NewClient(&helm.Config{Namespace: ns})
hc, err := exhelm.NewClient(&exhelm.Config{Namespace: ns})
if err != nil {
return errors.Errorf("helm create go client err: %v", err)
}
Expand All @@ -248,7 +250,7 @@ func chartClean(f factory.Factory) *cobra.Command {
if ns == "" {
ns = "default"
}
hc, err := helm.NewClient(&helm.Config{Namespace: ns})
hc, err := exhelm.NewClient(&exhelm.Config{Namespace: ns})
if err != nil {
return errors.Errorf("helm create go client err: %v", err)
}
Expand All @@ -274,7 +276,7 @@ func chartList(f factory.Factory) *cobra.Command {
Use: "list",
Short: "list all chart installed by quickon",
RunE: func(cmd *cobra.Command, args []string) error {
hc, err := helm.NewClient(&helm.Config{Namespace: ns})
hc, err := exhelm.NewClient(&exhelm.Config{Namespace: ns})
if err != nil {
return errors.Errorf("helm create go client err: %v", err)
}
Expand Down
8 changes: 6 additions & 2 deletions internal/pkg/util/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,16 @@ func (c Client) Upgrade(name, repoName, chartName, chartVersion string, values m
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("locate chart %s failed: %v", chartName, err))
}
c.log.Infof("chart name %s path: %s", chartName, p)
c.log.Debugf("chart name %s path: %s", chartName, p)
ct, err := loader.Load(p)
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("load chart %s failed: %v", chartName, err))
}
// TODO 获取之前参数,并且更新参数
releaseValue, err := c.GetDetail(name)
if err != nil {
return nil, errors.Errorf("fetch %s chart release value failed, %v", name, err)
}
values = MergeMaps(releaseValue.Config, values)
release, err := client.Run(name, ct, values)
if err != nil {
return release, errors.Wrap(err, fmt.Sprintf("upgrade tool %s with chart %s failed: %v", name, chartName, err))
Expand Down

0 comments on commit e89956c

Please sign in to comment.