From f3283c1fcade01adec012b9a6c4e309f4d0d9abd Mon Sep 17 00:00:00 2001 From: ysicing Date: Wed, 26 Jul 2023 14:22:18 +0800 Subject: [PATCH] feat(storage): add longhorn & nfs beta support add longhorn & nfs beta support Signed-off-by: ysicing --- cmd/app/list.go | 2 +- cmd/storage/storage.go | 7 +++---- hack/manifests/scripts/node.sh | 6 +++--- hack/manifests/storage/longhorn_environment_check.sh | 4 ++-- pkg/cluster/cluster.go | 6 ++++++ pkg/quickon/quickon.go | 10 +++++++--- 6 files changed, 22 insertions(+), 13 deletions(-) diff --git a/cmd/app/list.go b/cmd/app/list.go index 50e0a912..3619bcb5 100644 --- a/cmd/app/list.go +++ b/cmd/app/list.go @@ -78,7 +78,7 @@ func NewCmdAppList(f factory.Factory) *cobra.Command { log.Debugf("authUsername: %s, authPassword: %s", authUsername, authPassword) log.Infof("app meta:\n\t username: %s\n\t password: %s\n\t url: %s", color.SBlue(authUsername), color.SBlue(authPassword), color.SBlue(host)) } else { - log.Infof("app meta:\n\turl: %s", color.SBlue(host)) + log.Infof("app meta:\n\t url: %s", color.SBlue(host)) } return nil } diff --git a/cmd/storage/storage.go b/cmd/storage/storage.go index 2d98d8f8..e3f5c4c7 100644 --- a/cmd/storage/storage.go +++ b/cmd/storage/storage.go @@ -46,7 +46,6 @@ func NewCmdStorage(f factory.Factory) *cobra.Command { } func longhorn(f factory.Factory) *cobra.Command { - var ip, path, name string logpkg := f.GetLog() cmd := &cobra.Command{ Use: "longhorn", @@ -65,9 +64,6 @@ func longhorn(f factory.Factory) *cobra.Command { return nil }, } - cmd.Flags().StringVar(&ip, "ip", "", "cloud cfs/nas ip") - cmd.Flags().StringVar(&path, "path", "", "cloud cfs/nas path") - cmd.Flags().StringVar(&name, "name", "q-nfs", "storage class name") return cmd } @@ -158,6 +154,9 @@ func defaultStorage(f factory.Factory) *cobra.Command { } } } + if len(scItems) == 1 { + return kubeClient.PatchDefaultSC(ctx, scs.Items[0].DeepCopy(), true) + } newDefaultSCName, err := logpkg.Question(&survey.QuestionOptions{ Question: "select default storage class", DefaultValue: scItems[0], diff --git a/hack/manifests/scripts/node.sh b/hack/manifests/scripts/node.sh index 63280a4d..17dcb897 100755 --- a/hack/manifests/scripts/node.sh +++ b/hack/manifests/scripts/node.sh @@ -12,15 +12,15 @@ set -o noglob # --- helper functions for logs --- info() { - echo '[INFO] ' "$@" + echo '[INFO] ' "$@" } warn() { - echo '[WARN] ' "$@" >&2 + echo '[WARN] ' "$@" >&2 } fatal() { - echo '[ERROR] ' "$@" >&2 + echo '[ERROR] ' "$@" >&2 exit 1 } diff --git a/hack/manifests/storage/longhorn_environment_check.sh b/hack/manifests/storage/longhorn_environment_check.sh index 5eb925c3..61f9df57 100755 --- a/hack/manifests/storage/longhorn_environment_check.sh +++ b/hack/manifests/storage/longhorn_environment_check.sh @@ -39,7 +39,7 @@ info() { else log_title='' fi - echo -e "${CYAN}[INFO] ${log_title} ${NO_COLOR}$1" + echo -e "${CYAN}[INFO] ${log_title} ${NO_COLOR}$1" fi } @@ -53,7 +53,7 @@ warn() { else log_title='' fi - echo -e "${YELLOW}[WARN] ${log_title} ${NO_COLOR}$1" + echo -e "${YELLOW}[WARN] ${log_title} ${NO_COLOR}$1" fi } diff --git a/pkg/cluster/cluster.go b/pkg/cluster/cluster.go index e5e188ee..564d6173 100644 --- a/pkg/cluster/cluster.go +++ b/pkg/cluster/cluster.go @@ -26,6 +26,7 @@ import ( "github.com/easysoft/qcadmin/internal/pkg/cli/k3stpl" "github.com/easysoft/qcadmin/internal/pkg/k8s" "github.com/easysoft/qcadmin/internal/pkg/types" + qcexec "github.com/easysoft/qcadmin/internal/pkg/util/exec" "github.com/easysoft/qcadmin/internal/pkg/util/log" "github.com/easysoft/qcadmin/internal/pkg/util/ssh" "github.com/ergoapi/util/expass" @@ -406,6 +407,11 @@ func (c *Cluster) InitNode() error { c.log.Warnf("skip join worker: %s, reason: %v", host, err) } } + if c.Storage == "longhorn" || c.Storage == "nfs" { + c.log.Infof("install %s as storageclass", c.Storage) + scArgs := []string{"cluster", "storage", c.Storage} + return qcexec.CommandRun(os.Args[0], scArgs...) + } return nil } diff --git a/pkg/quickon/quickon.go b/pkg/quickon/quickon.go index e8bb36a1..4eb6e277 100644 --- a/pkg/quickon/quickon.go +++ b/pkg/quickon/quickon.go @@ -131,12 +131,16 @@ func (m *Meta) checkStorage() { defaultClass, _ := m.kubeClient.GetDefaultSC(context.Background()) m.log.StopWait() if defaultClass == nil { + // TODO default storage m.log.Infof("not found default storage class, will install default storage") - m.log.Debug("start install default storage: local-storage") - if err := qcexec.CommandRun(os.Args[0], "quickon", "plugins", "enable", "storage"); err != nil { + m.log.Debug("start install default storage: longhorn") + if err := qcexec.CommandRun(os.Args[0], "cluster", "storage", "longhorn"); err != nil { m.log.Errorf("install storage failed, reason: %v", err) } else { - m.log.Done("install storage: local-storage success") + m.log.Done("install storage: longhorn success") + } + if err := qcexec.CommandRun(os.Args[0], "cluster", "storage", "set-default"); err != nil { + m.log.Errorf("set default storageclass failed, reason: %v", err) } } else { m.log.Infof("found exist default storage class: %s", defaultClass.Name)