Skip to content

Commit

Permalink
* [feat]: implement installation verification across services
Browse files Browse the repository at this point in the history
Signed-off-by: ysicing <[email protected]>
  • Loading branch information
ysicing committed Nov 7, 2024
1 parent bf97261 commit 27f1e8c
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 1 deletion.
7 changes: 6 additions & 1 deletion cmd/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions cmd/quickon/quickon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
}

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

Expand Down
4 changes: 4 additions & 0 deletions pkg/providers/devops/devops.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions pkg/providers/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type Provider interface {
GetProviderName() string
GetMeta() *quickon.Meta
GetKubeClient() error
CheckInstall() bool
Check() error
GetFlags() []types.Flag
Install() error
Expand Down
4 changes: 4 additions & 0 deletions pkg/providers/quickon/quickon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
13 changes: 13 additions & 0 deletions pkg/quickon/quickon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 27f1e8c

Please sign in to comment.