From 27f1e8cfa235789e3bfc97777a562feebc4a4d27 Mon Sep 17 00:00:00 2001 From: ysicing Date: Thu, 7 Nov 2024 13:46:32 +0800 Subject: [PATCH] * [feat]: implement installation verification across services Signed-off-by: ysicing --- cmd/cluster/cluster.go | 7 ++++++- cmd/quickon/quickon.go | 5 +++++ hack/manifests/scripts/node.sh | 6 ++++++ pkg/providers/devops/devops.go | 4 ++++ pkg/providers/providers.go | 1 + pkg/providers/quickon/quickon.go | 4 ++++ pkg/quickon/quickon.go | 13 +++++++++++++ 7 files changed, 39 insertions(+), 1 deletion(-) diff --git a/cmd/cluster/cluster.go b/cmd/cluster/cluster.go index 436af689..532beedf 100644 --- a/cmd/cluster/cluster.go +++ b/cmd/cluster/cluster.go @@ -10,11 +10,13 @@ import ( "github.com/cockroachdb/errors" "github.com/ergoapi/util/confirm" "github.com/ergoapi/util/exnet" + "github.com/ergoapi/util/file" "github.com/spf13/cobra" "k8s.io/kubectl/pkg/util/templates" "github.com/easysoft/qcadmin/cmd/flags" "github.com/easysoft/qcadmin/cmd/precheck" + "github.com/easysoft/qcadmin/common" "github.com/easysoft/qcadmin/internal/api/statistics" "github.com/easysoft/qcadmin/internal/pkg/util/factory" "github.com/easysoft/qcadmin/pkg/cluster" @@ -46,10 +48,13 @@ func InitCommand(f factory.Factory) *cobra.Command { Short: "init cluster", Example: initExample, PreRunE: func(cmd *cobra.Command, args []string) error { + // 禁止重复初始化 + if file.CheckFileExists(common.GetCustomConfig(common.InitFileName)) { + return errors.New("cluster is already initialized") + } if len(myCluster.MasterIPs) == 0 { myCluster.MasterIPs = append(myCluster.MasterIPs, exnet.LocalIPs()[0]) } - // 禁止重复初始化 preCheck.IgnorePreflightErrors = myCluster.IgnorePreflightErrors preCheck.OffLine = myCluster.OffLine if err := preCheck.Run(); err != nil { diff --git a/cmd/quickon/quickon.go b/cmd/quickon/quickon.go index dfa88f35..9157adf9 100644 --- a/cmd/quickon/quickon.go +++ b/cmd/quickon/quickon.go @@ -11,9 +11,11 @@ import ( "github.com/ergoapi/util/confirm" "github.com/ergoapi/util/exnet" + "github.com/ergoapi/util/file" "github.com/spf13/cobra" "github.com/easysoft/qcadmin/cmd/flags" + "github.com/easysoft/qcadmin/common" "github.com/easysoft/qcadmin/internal/api/statistics" "github.com/easysoft/qcadmin/internal/app/config" "github.com/easysoft/qcadmin/internal/pkg/types" @@ -56,6 +58,9 @@ func InitCommand(f factory.Factory) *cobra.Command { if err := cp.GetKubeClient(); err != nil { return err } + if file.CheckFileExists(common.GetCustomConfig(common.InitFileName)) && cp.CheckInstall() { + return fmt.Errorf("quickon is already initialized") + } return cp.Check() } diff --git a/hack/manifests/scripts/node.sh b/hack/manifests/scripts/node.sh index 8c88a734..f6dcdb57 100755 --- a/hack/manifests/scripts/node.sh +++ b/hack/manifests/scripts/node.sh @@ -45,6 +45,12 @@ check_docker() { if [ -z "${which_cmd}" ]; then sed -i "s#--docker \\\##g" /root/.k3s.service sed -i "s#--docker##g" /root/.k3s.service + else + docker_status=$(systemctl is-active docker) + if [ "${docker_status}" != "active" ]; then + sed -i "s#--docker \\\##g" /root/.k3s.service + sed -i "s#--docker##g" /root/.k3s.service + fi fi } diff --git a/pkg/providers/devops/devops.go b/pkg/providers/devops/devops.go index 6f618c8a..ab00b8f9 100644 --- a/pkg/providers/devops/devops.go +++ b/pkg/providers/devops/devops.go @@ -112,6 +112,10 @@ func (q *Devops) Check() error { return q.MetaData.Check() } +func (q *Devops) CheckInstall() bool { + return q.MetaData.CheckInstall() +} + func (q *Devops) GetMeta() *quickon.Meta { return q.MetaData } diff --git a/pkg/providers/providers.go b/pkg/providers/providers.go index ce2f0d43..4a8e342d 100644 --- a/pkg/providers/providers.go +++ b/pkg/providers/providers.go @@ -28,6 +28,7 @@ type Provider interface { GetProviderName() string GetMeta() *quickon.Meta GetKubeClient() error + CheckInstall() bool Check() error GetFlags() []types.Flag Install() error diff --git a/pkg/providers/quickon/quickon.go b/pkg/providers/quickon/quickon.go index dffd9c3d..99e0eaf2 100644 --- a/pkg/providers/quickon/quickon.go +++ b/pkg/providers/quickon/quickon.go @@ -130,6 +130,10 @@ func (q *Quickon) Check() error { return q.MetaData.Check() } +func (q *Quickon) CheckInstall() bool { + return q.MetaData.CheckInstall() +} + func (q *Quickon) GetMeta() *quickon.Meta { return q.MetaData } diff --git a/pkg/quickon/quickon.go b/pkg/quickon/quickon.go index cda97575..8ec3f36f 100644 --- a/pkg/quickon/quickon.go +++ b/pkg/quickon/quickon.go @@ -150,6 +150,19 @@ func (m *Meta) checkStorage() { m.Log.Done("check default storage done") } +func (m *Meta) CheckInstall() bool { + _, err := config.LoadConfig() + if err != nil { + return false + } + _, err = m.kubeClient.GetDeployment(context.Background(), common.GetDefaultSystemNamespace(true), common.GetReleaseName(m.DevopsMode), metav1.GetOptions{}) + if err == nil { + m.Log.Debug("found exist quickon deployment") + return true + } + return false +} + func (m *Meta) Check() error { if err := m.addHelmRepo(); err != nil { return err