Skip to content

Commit 27f1e8c

Browse files
committed
* [feat]: implement installation verification across services
Signed-off-by: ysicing <i@ysicing.me>
1 parent bf97261 commit 27f1e8c

File tree

7 files changed

+39
-1
lines changed

7 files changed

+39
-1
lines changed

cmd/cluster/cluster.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ import (
1010
"github.com/cockroachdb/errors"
1111
"github.com/ergoapi/util/confirm"
1212
"github.com/ergoapi/util/exnet"
13+
"github.com/ergoapi/util/file"
1314
"github.com/spf13/cobra"
1415
"k8s.io/kubectl/pkg/util/templates"
1516

1617
"github.com/easysoft/qcadmin/cmd/flags"
1718
"github.com/easysoft/qcadmin/cmd/precheck"
19+
"github.com/easysoft/qcadmin/common"
1820
"github.com/easysoft/qcadmin/internal/api/statistics"
1921
"github.com/easysoft/qcadmin/internal/pkg/util/factory"
2022
"github.com/easysoft/qcadmin/pkg/cluster"
@@ -46,10 +48,13 @@ func InitCommand(f factory.Factory) *cobra.Command {
4648
Short: "init cluster",
4749
Example: initExample,
4850
PreRunE: func(cmd *cobra.Command, args []string) error {
51+
// 禁止重复初始化
52+
if file.CheckFileExists(common.GetCustomConfig(common.InitFileName)) {
53+
return errors.New("cluster is already initialized")
54+
}
4955
if len(myCluster.MasterIPs) == 0 {
5056
myCluster.MasterIPs = append(myCluster.MasterIPs, exnet.LocalIPs()[0])
5157
}
52-
// 禁止重复初始化
5358
preCheck.IgnorePreflightErrors = myCluster.IgnorePreflightErrors
5459
preCheck.OffLine = myCluster.OffLine
5560
if err := preCheck.Run(); err != nil {

cmd/quickon/quickon.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ import (
1111

1212
"github.com/ergoapi/util/confirm"
1313
"github.com/ergoapi/util/exnet"
14+
"github.com/ergoapi/util/file"
1415
"github.com/spf13/cobra"
1516

1617
"github.com/easysoft/qcadmin/cmd/flags"
18+
"github.com/easysoft/qcadmin/common"
1719
"github.com/easysoft/qcadmin/internal/api/statistics"
1820
"github.com/easysoft/qcadmin/internal/app/config"
1921
"github.com/easysoft/qcadmin/internal/pkg/types"
@@ -56,6 +58,9 @@ func InitCommand(f factory.Factory) *cobra.Command {
5658
if err := cp.GetKubeClient(); err != nil {
5759
return err
5860
}
61+
if file.CheckFileExists(common.GetCustomConfig(common.InitFileName)) && cp.CheckInstall() {
62+
return fmt.Errorf("quickon is already initialized")
63+
}
5964
return cp.Check()
6065
}
6166

hack/manifests/scripts/node.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ check_docker() {
4545
if [ -z "${which_cmd}" ]; then
4646
sed -i "s#--docker \\\##g" /root/.k3s.service
4747
sed -i "s#--docker##g" /root/.k3s.service
48+
else
49+
docker_status=$(systemctl is-active docker)
50+
if [ "${docker_status}" != "active" ]; then
51+
sed -i "s#--docker \\\##g" /root/.k3s.service
52+
sed -i "s#--docker##g" /root/.k3s.service
53+
fi
4854
fi
4955
}
5056

pkg/providers/devops/devops.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ func (q *Devops) Check() error {
112112
return q.MetaData.Check()
113113
}
114114

115+
func (q *Devops) CheckInstall() bool {
116+
return q.MetaData.CheckInstall()
117+
}
118+
115119
func (q *Devops) GetMeta() *quickon.Meta {
116120
return q.MetaData
117121
}

pkg/providers/providers.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type Provider interface {
2828
GetProviderName() string
2929
GetMeta() *quickon.Meta
3030
GetKubeClient() error
31+
CheckInstall() bool
3132
Check() error
3233
GetFlags() []types.Flag
3334
Install() error

pkg/providers/quickon/quickon.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ func (q *Quickon) Check() error {
130130
return q.MetaData.Check()
131131
}
132132

133+
func (q *Quickon) CheckInstall() bool {
134+
return q.MetaData.CheckInstall()
135+
}
136+
133137
func (q *Quickon) GetMeta() *quickon.Meta {
134138
return q.MetaData
135139
}

pkg/quickon/quickon.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,19 @@ func (m *Meta) checkStorage() {
150150
m.Log.Done("check default storage done")
151151
}
152152

153+
func (m *Meta) CheckInstall() bool {
154+
_, err := config.LoadConfig()
155+
if err != nil {
156+
return false
157+
}
158+
_, err = m.kubeClient.GetDeployment(context.Background(), common.GetDefaultSystemNamespace(true), common.GetReleaseName(m.DevopsMode), metav1.GetOptions{})
159+
if err == nil {
160+
m.Log.Debug("found exist quickon deployment")
161+
return true
162+
}
163+
return false
164+
}
165+
153166
func (m *Meta) Check() error {
154167
if err := m.addHelmRepo(); err != nil {
155168
return err

0 commit comments

Comments
 (0)