diff --git a/cmd/app/get.go b/cmd/app/get.go index 736f5e1d..bb456a06 100644 --- a/cmd/app/get.go +++ b/cmd/app/get.go @@ -34,9 +34,8 @@ func NewCmdAppGet(f factory.Factory) *cobra.Command { if err != nil { return err } - extargs := []string{"exp", "kubectl", "get", "-o", "wide", "pods,deploy,pvc,svc,ing", "-l", "release=" + appdata.K8Name, "--kubeconfig", common.GetDefaultNewKubeConfig()} - // extargs = append(extargs, args...) - return qcexec.CommandRun(os.Args[0], extargs...) + extArgs := []string{"exp", "kubectl", "get", "-o", "wide", "pods,deploy,pvc,svc,ing", "-l", "release=" + appdata.K8Name, "--kubeconfig", common.GetKubeConfig()} + return qcexec.CommandRun(os.Args[0], extArgs...) }, } app.Flags().BoolVar(&useip, "api-useip", false, "api use ip") diff --git a/cmd/root.go b/cmd/root.go index 59523190..c25e2495 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -242,12 +242,3 @@ func HandlePluginCommand(pluginHandler PluginHandler, cmdArgs []string) error { return nil } - -// func initConfig() { -// if globalFlags.ConfigPath == "" { -// globalFlags.ConfigPath = common.GetDefaultConfig() -// } -// viper.SetConfigFile(globalFlags.ConfigPath) -// viper.AutomaticEnv() -// viper.ReadInConfig() -// } diff --git a/common/const.go b/common/const.go index ffdc9a04..c41055a7 100644 --- a/common/const.go +++ b/common/const.go @@ -172,7 +172,7 @@ ExecStart=/usr/local/bin/k3s \ {{if not .Master0 -}} --server https://{{ .KubeAPI }}:6443 \ {{end -}} - --data-dir {{.DataDir}} \ + --data-dir {{.DataDir}} \ --docker \ --pause-image hub.qucheng.com/library/rancher/mirrored-pause:3.6 \ --kube-proxy-arg "proxy-mode=ipvs" "masquerade-all=true" \ diff --git a/common/func.go b/common/func.go index 7dd524cb..d3fdc675 100644 --- a/common/func.go +++ b/common/func.go @@ -8,7 +8,6 @@ package common import ( "fmt" - "os" "runtime" "strings" @@ -99,25 +98,26 @@ func GetDefaultConfig() string { return home + "/" + DefaultCfgDir + "/cluster.yaml" } -func GetDefaultKubeConfig() string { +func DefaultKubeConfig() string { d := fmt.Sprintf("%v/.kube", zos.GetHomeDir()) - os.MkdirAll(d, FileMode0644) + // os.MkdirAll(d, FileMode0644) return fmt.Sprintf("%v/config", d) } -func GetDefaultNewKubeConfig() string { +func DefaultQuickONKubeConfig() string { home := zos.GetHomeDir() d := home + "/" + DefaultCfgDir + "/.kube" - os.MkdirAll(d, FileMode0644) + // os.MkdirAll(d, FileMode0644) return fmt.Sprintf("%v/config", d) } +// GetKubeConfig get kubeconfig func GetKubeConfig() string { - kubecfg := GetDefaultNewKubeConfig() - if file.CheckFileExists(kubecfg) { - return kubecfg + kubeCfg := DefaultQuickONKubeConfig() + if file.CheckFileExists(kubeCfg) { + return kubeCfg } - return GetDefaultKubeConfig() + return DefaultKubeConfig() } func GetCustomConfig(name string) string { diff --git a/hack/packaging/postinstall.sh b/hack/packaging/postinstall.sh index 8a10db0e..782493a2 100755 --- a/hack/packaging/postinstall.sh +++ b/hack/packaging/postinstall.sh @@ -1,11 +1,14 @@ #!/bin/sh # Determine OS platform # shellcheck source=/dev/null -. /etc/os-release create_link() { # shellcheck disable=SC2015 [ -f "/usr/bin/q" ] && rm -rf /usr/bin/q || true + # shellcheck disable=SC2015 + [ -f "/usr/local/bin/q" ] && rm -rf /usr/local/bin/q || true + # shellcheck disable=SC2015 + [ -f "/usr/local/bin/qcadmin" ] && rm -rf /usr/local/bin/qcadmin || true # shellcheck disable=SC2015 [ -f "/usr/bin/qcadmin" ] && ln -s /usr/bin/qcadmin /usr/bin/q || true } diff --git a/hack/packaging/postremove.sh b/hack/packaging/postremove.sh index 839b9deb..d528a8af 100755 --- a/hack/packaging/postremove.sh +++ b/hack/packaging/postremove.sh @@ -1,7 +1,6 @@ #!/bin/sh # Determine OS platform # shellcheck source=/dev/null -. /etc/os-release echo "Removing quickon package." diff --git a/hack/packaging/preinstall.sh b/hack/packaging/preinstall.sh index f6f4a172..184c5842 100755 --- a/hack/packaging/preinstall.sh +++ b/hack/packaging/preinstall.sh @@ -1,7 +1,6 @@ #!/bin/sh # Determine OS platform # shellcheck source=/dev/null -. /etc/os-release ensure_sudo() { if [ "$(id -u)" = "0" ]; then diff --git a/hack/packaging/preremove.sh b/hack/packaging/preremove.sh index 2c77fd6d..2dee0576 100755 --- a/hack/packaging/preremove.sh +++ b/hack/packaging/preremove.sh @@ -1,6 +1,7 @@ #!/bin/sh # Determine OS platform # shellcheck source=/dev/null -. /etc/os-release +# shellcheck disable=SC2015 [ -f "/usr/bin/q" ] && rm -rf /usr/bin/q || true +[ -f "/usr/local/bin/q" ] && rm -rf /usr/local/bin/q || true diff --git a/internal/pkg/cli/tool/domain.go b/internal/pkg/cli/tool/domain.go index 70f01583..b59ac8b5 100644 --- a/internal/pkg/cli/tool/domain.go +++ b/internal/pkg/cli/tool/domain.go @@ -134,12 +134,12 @@ func domainAdd(f factory.Factory) *cobra.Command { if err := helmClient.UpdateRepo(); err != nil { log.Warnf("update repo failed, reason: %v", err) } - if err := qcexec.Command(os.Args[0], "experimental", "kubectl", "apply", "-f", fmt.Sprintf("%s/hack/haogstls/haogs.yaml", common.GetDefaultDataDir()), "-n", common.GetDefaultSystemNamespace(true), "--kubeconfig", common.GetDefaultNewKubeConfig()).Run(); err != nil { + if err := qcexec.Command(os.Args[0], "experimental", "kubectl", "apply", "-f", fmt.Sprintf("%s/hack/haogstls/haogs.yaml", common.GetDefaultDataDir()), "-n", common.GetDefaultSystemNamespace(true), "--kubeconfig", common.GetKubeConfig()).Run(); err != nil { log.Warnf("load tls cert for %s failed, reason: %v", common.GetDefaultSystemNamespace(true), err) } else { log.Donef("load tls cert for %s success", common.GetDefaultSystemNamespace(true)) } - if err := qcexec.Command(os.Args[0], "experimental", "kubectl", "apply", "-f", fmt.Sprintf("%s/hack/haogstls/haogs.yaml", common.GetDefaultDataDir()), "-n", "default", "--kubeconfig", common.GetDefaultNewKubeConfig()).Run(); err != nil { + if err := qcexec.Command(os.Args[0], "experimental", "kubectl", "apply", "-f", fmt.Sprintf("%s/hack/haogstls/haogs.yaml", common.GetDefaultDataDir()), "-n", "default", "--kubeconfig", common.GetKubeConfig()).Run(); err != nil { log.Warnf("load tls cert for default failed, reason: %v", err) } else { log.Done("load tls cert for default success") diff --git a/internal/pkg/plugin/plugin.go b/internal/pkg/plugin/plugin.go index 57fa4592..3381c882 100644 --- a/internal/pkg/plugin/plugin.go +++ b/internal/pkg/plugin/plugin.go @@ -117,7 +117,7 @@ func (p *Item) UnInstall() error { } } else { // #nosec - applycmd := qcexec.Command(os.Args[0], "experimental", "kubectl", "delete", "-f", fmt.Sprintf("%s/%s", common.GetDefaultDataDir(), p.Path), "-n", common.GetDefaultSystemNamespace(true), "--kubeconfig", common.GetDefaultNewKubeConfig()) + applycmd := qcexec.Command(os.Args[0], "experimental", "kubectl", "delete", "-f", fmt.Sprintf("%s/%s", common.GetDefaultDataDir(), p.Path), "-n", common.GetDefaultSystemNamespace(true), "--kubeconfig", common.GetKubeConfig()) if output, err := applycmd.CombinedOutput(); err != nil { p.log.Errorf("kubectl uninstall %s plugin %s failed: %s", p.Type, p.Name, string(output)) return err @@ -160,7 +160,7 @@ func (p *Item) Install() error { } } else { // #nosec - applycmd := qcexec.Command(os.Args[0], "experimental", "kubectl", "apply", "-f", fmt.Sprintf("%s/%s", common.GetDefaultDataDir(), p.Path), "-n", common.GetDefaultSystemNamespace(true), "--kubeconfig", common.GetDefaultNewKubeConfig()) + applycmd := qcexec.Command(os.Args[0], "experimental", "kubectl", "apply", "-f", fmt.Sprintf("%s/%s", common.GetDefaultDataDir(), p.Path), "-n", common.GetDefaultSystemNamespace(true), "--kubeconfig", common.GetKubeConfig()) if output, err := applycmd.CombinedOutput(); err != nil { p.log.Errorf("kubectl install %s plugin %s failed: %s", p.Type, p.Name, string(output)) return err @@ -209,7 +209,7 @@ func (p *Item) Upgrade() (err error) { } } else { // #nosec - applycmd := qcexec.Command(os.Args[0], "experimental", "kubectl", "apply", "-f", fmt.Sprintf("%s/%s", common.GetDefaultDataDir(), p.Path), "-n", common.GetDefaultSystemNamespace(true), "--kubeconfig", common.GetDefaultNewKubeConfig()) + applycmd := qcexec.Command(os.Args[0], "experimental", "kubectl", "apply", "-f", fmt.Sprintf("%s/%s", common.GetDefaultDataDir(), p.Path), "-n", common.GetDefaultSystemNamespace(true), "--kubeconfig", common.GetKubeConfig()) if output, err := applycmd.CombinedOutput(); err != nil { p.log.Errorf("kubectl upgrade %s plugin %s failed: %s", p.Type, p.Name, string(output)) return err diff --git a/internal/pkg/util/helm/helm.go b/internal/pkg/util/helm/helm.go index 5fbbff4f..742c6885 100644 --- a/internal/pkg/util/helm/helm.go +++ b/internal/pkg/util/helm/helm.go @@ -22,7 +22,6 @@ import ( "github.com/easysoft/qcadmin/common" "github.com/easysoft/qcadmin/internal/pkg/util/kutil" "github.com/easysoft/qcadmin/internal/pkg/util/log" - "github.com/ergoapi/util/file" "github.com/gofrs/flock" "helm.sh/helm/v3/cmd/helm/search" "helm.sh/helm/v3/pkg/action" @@ -57,9 +56,7 @@ func NewClient(config *Config) (*Client, error) { settings := cli.New() client := &Client{} settings.SetNamespace(config.Namespace) - if !file.CheckFileExists(common.GetDefaultKubeConfig()) { - settings.KubeConfig = common.GetDefaultNewKubeConfig() - } + settings.KubeConfig = common.GetKubeConfig() settings.RepositoryCache = common.GetDefaultCacheDir() client.settings = settings actionConfig := &action.Configuration{} diff --git a/internal/pkg/util/httptls/httptls.go b/internal/pkg/util/httptls/httptls.go index f669ae9f..b01db356 100644 --- a/internal/pkg/util/httptls/httptls.go +++ b/internal/pkg/util/httptls/httptls.go @@ -81,11 +81,11 @@ func renewCertificate(domain string) error { coreDomain := fmt.Sprintf("%s.%s.%s", ds[len(ds)-3], ds[len(ds)-2], ds[len(ds)-1]) tlsfile := fmt.Sprintf("https://pkg.qucheng.com/ssl/%s/%s/tls.yaml", mainDomain, coreDomain) log.Debugf("renew default tls certificate use %s", tlsfile) - if err := qcexec.Command(os.Args[0], "experimental", "kubectl", "apply", "-f", tlsfile, "-n", common.GetDefaultSystemNamespace(true), "--kubeconfig", common.GetDefaultNewKubeConfig()).Run(); err != nil { + if err := qcexec.Command(os.Args[0], "experimental", "kubectl", "apply", "-f", tlsfile, "-n", common.GetDefaultSystemNamespace(true), "--kubeconfig", common.GetKubeConfig()).Run(); err != nil { log.Warnf("load renew tls cert for %s failed, reason: %v", common.GetDefaultSystemNamespace(true), err) } log.Debugf("renew ingress tls certificate") - if err := qcexec.Command(os.Args[0], "experimental", "kubectl", "apply", "-f", tlsfile, "--kubeconfig", common.GetDefaultNewKubeConfig()).Run(); err != nil { + if err := qcexec.Command(os.Args[0], "experimental", "kubectl", "apply", "-f", tlsfile, "--kubeconfig", common.GetKubeConfig()).Run(); err != nil { log.Warnf("load renew tls cert for default failed, reason: %v", err) } return nil diff --git a/pkg/cluster/cluster.go b/pkg/cluster/cluster.go index 34c3dc0d..664445a2 100644 --- a/pkg/cluster/cluster.go +++ b/pkg/cluster/cluster.go @@ -234,13 +234,13 @@ func (c *Cluster) waitk3sReady(host string, sshClient ssh.Interface) error { try++ c.log.Debugf("the %d/%d time tring to check k8s status", try, defaultBackoff.Steps) // TODO 地址错误问题 - err := sshClient.Copy(host, "/etc/rancher/k3s/k3s.yaml", common.GetDefaultNewKubeConfig()) + err := sshClient.Copy(host, "/etc/rancher/k3s/k3s.yaml", common.DefaultQuickONKubeConfig()) if err != nil { return false, nil } // 本地不存在config文件, 同步最新的kubeconfig文件 - if !file.CheckFileExists(common.GetDefaultKubeConfig()) { - if err := sshClient.Copy(host, common.GetDefaultNewKubeConfig(), common.GetDefaultKubeConfig()); err != nil { + if !file.CheckFileExists(common.DefaultKubeConfig()) { + if err := sshClient.Copy(host, common.DefaultQuickONKubeConfig(), common.DefaultKubeConfig()); err != nil { return false, nil } } @@ -395,7 +395,7 @@ func (c *Cluster) DeleteNode() error { cfg, _ := config.LoadConfig() var wg sync.WaitGroup sshClient := ssh.NewSSHClient(&cfg.Global.SSH, true) - kubeClient, err := k8s.NewSimpleClient(common.GetDefaultNewKubeConfig()) + kubeClient, err := k8s.NewSimpleClient(common.GetKubeConfig()) if err != nil { return errors.Errorf("load k8s client failed, reason: %v", err) } diff --git a/pkg/qucheng/upgrade/upgrade.go b/pkg/qucheng/upgrade/upgrade.go index 2c8aa6f6..a440d8f1 100644 --- a/pkg/qucheng/upgrade/upgrade.go +++ b/pkg/qucheng/upgrade/upgrade.go @@ -121,12 +121,12 @@ func Upgrade(flagVersion string, log log.Logger) error { if _, err := os.Stat(defaultTLS); err == nil { log.StopWait() log.Done("download tls cert success") - if err := qcexec.Command(os.Args[0], "experimental", "kubectl", "apply", "-f", defaultTLS, "-n", common.GetDefaultSystemNamespace(true), "--kubeconfig", common.GetDefaultNewKubeConfig()).Run(); err != nil { + if err := qcexec.Command(os.Args[0], "experimental", "kubectl", "apply", "-f", defaultTLS, "-n", common.GetDefaultSystemNamespace(true), "--kubeconfig", common.GetKubeConfig()).Run(); err != nil { log.Warnf("load default tls cert failed, reason: %v", err) } else { log.Done("load default tls cert success") } - qcexec.Command(os.Args[0], "experimental", "kubectl", "apply", "-f", defaultTLS, "-n", "default", "--kubeconfig", common.GetDefaultNewKubeConfig()).Run() + qcexec.Command(os.Args[0], "experimental", "kubectl", "apply", "-f", defaultTLS, "-n", "default", "--kubeconfig", common.GetKubeConfig()).Run() args := []string{"ingress.tls.enabled=true", "ingress.tls.secretName=tls-haogs-cn"} values, _ := helm.MergeValues(args) defaultValue = helm.MergeMaps(defaultValue, values) diff --git a/pkg/quickon/quickon.go b/pkg/quickon/quickon.go index 1c98ffa7..66c7863e 100644 --- a/pkg/quickon/quickon.go +++ b/pkg/quickon/quickon.go @@ -92,7 +92,7 @@ func (m *Meta) GetFlags() []types.Flag { } func (m *Meta) GetKubeClient() error { - kubeClient, err := k8s.NewSimpleClient(common.GetDefaultNewKubeConfig()) + kubeClient, err := k8s.NewSimpleClient(common.GetKubeConfig()) if err != nil { return errors.Errorf("load k8s client failed, reason: %v", err) } @@ -236,12 +236,12 @@ func (m *Meta) Init() error { if file.CheckFileExists(defaultTLS) { m.log.StopWait() m.log.Done("download tls cert success") - if err := qcexec.Command(os.Args[0], "experimental", "kubectl", "apply", "-f", defaultTLS, "-n", common.GetDefaultSystemNamespace(true), "--kubeconfig", common.GetDefaultNewKubeConfig()).Run(); err != nil { + if err := qcexec.Command(os.Args[0], "experimental", "kubectl", "apply", "-f", defaultTLS, "-n", common.GetDefaultSystemNamespace(true), "--kubeconfig", common.GetKubeConfig()).Run(); err != nil { m.log.Warnf("load default tls cert failed, reason: %v", err) } else { m.log.Done("load default tls cert success") } - qcexec.Command(os.Args[0], "experimental", "kubectl", "apply", "-f", defaultTLS, "-n", "default", "--kubeconfig", common.GetDefaultNewKubeConfig()).Run() + qcexec.Command(os.Args[0], "experimental", "kubectl", "apply", "-f", defaultTLS, "-n", "default", "--kubeconfig", common.GetKubeConfig()).Run() break } _, mainDomain := kutil.SplitDomain(m.Domain)