Skip to content

Commit

Permalink
feat(storage): add longhorn & nfs beta support
Browse files Browse the repository at this point in the history
add longhorn & nfs beta support

Signed-off-by: ysicing <[email protected]>
  • Loading branch information
ysicing committed Jul 26, 2023
1 parent 1969a4b commit f3283c1
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion cmd/app/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
7 changes: 3 additions & 4 deletions cmd/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
}

Expand Down Expand Up @@ -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],
Expand Down
6 changes: 3 additions & 3 deletions hack/manifests/scripts/node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions hack/manifests/storage/longhorn_environment_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down
10 changes: 7 additions & 3 deletions pkg/quickon/quickon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f3283c1

Please sign in to comment.