Skip to content

Commit

Permalink
fix(status): fix status show
Browse files Browse the repository at this point in the history
fix status show

Signed-off-by: ysicing <[email protected]>
  • Loading branch information
ysicing committed Aug 30, 2023
1 parent 55d87b8 commit 2b9e3b2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 19 deletions.
10 changes: 7 additions & 3 deletions hack/scripts/devops/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
# (2) Affero General Public License 3.0 (AGPL 3.0)
# license that can be found in the LICENSE file.

set -e
set -o noglob
# Source code is available at https://github.com/easysoft/quickon_cli

# SCRIPT_COMMIT_SHA="un"

# Usage:
# curl ... | ENV_VAR=... sh -
Expand All @@ -18,13 +19,16 @@ set -o noglob
# curl ... | DEVOPS_TYPE="" sh -
# - DEVOPS_TYPE
# Install Type when install Quickon.
# Defaults to 'zentao open'
# Defaults to '', support 'max', 'biz', 'ipd'
# - DEVOPS_VERSION
# Install Version when install Quickon.
# Defaults to ''
# - INSTALL_DOMAIN
# If not set default use gen default domain

set -e
set -o noglob

# --- helper functions for logs ---
info()
{
Expand Down
26 changes: 17 additions & 9 deletions internal/pkg/status/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"time"

"github.com/easysoft/qcadmin/common"
"github.com/easysoft/qcadmin/internal/app/config"
"github.com/easysoft/qcadmin/internal/pkg/k8s"
"github.com/easysoft/qcadmin/internal/pkg/plugin"
"github.com/easysoft/qcadmin/internal/pkg/util/log"
Expand All @@ -34,13 +35,16 @@ type K8sStatusOption struct {
type K8sStatusCollector struct {
client *k8s.Client
option K8sStatusOption
cfg *config.Config
}

func NewK8sStatusCollector(option K8sStatusOption) (*K8sStatusCollector, error) {
client, err := k8s.NewClient("", option.KubeConfig)
cfg, _ := config.LoadConfig()
return &K8sStatusCollector{
client: client,
option: option,
cfg: cfg,
}, err
}

Expand Down Expand Up @@ -85,8 +89,8 @@ func (k *K8sStatusCollector) status(ctx context.Context) *Status {
if err := k.nodesStatus(ctx, status); err != nil {
k.option.Log.Errorf("failed to get nodes status: %v", err)
}
if err := k.quchengStatus(ctx, status); err != nil {
k.option.Log.Errorf("failed to get qucheng status: %v", err)
if err := k.serviceStatus(ctx, status); err != nil {
k.option.Log.Errorf("failed to get service status: %v", err)
}
return status
}
Expand Down Expand Up @@ -145,26 +149,30 @@ func (k *K8sStatusCollector) deploymentStatus(ctx context.Context, ns, name, ali
return false, nil
}

func (k *K8sStatusCollector) quchengStatus(ctx context.Context, status *Status) error {
// serviceStatus 检查服务状态
func (k *K8sStatusCollector) serviceStatus(ctx context.Context, status *Status) error {
// 集群
k.deploymentStatus(ctx, "kube-system", "coredns", "coredns", "k8s", status)
k.deploymentStatus(ctx, "kube-system", "metrics-server", "metrics-server", "k8s", status)
k.deploymentStatus(ctx, "kube-system", "local-path-provisioner", "local-path-provisioner", "k8s", status)
if k.cfg.Storage.Type == "local" {
k.deploymentStatus(ctx, "kube-system", "local-path-provisioner", "local-path-provisioner", "k8s", status)
}
// 业务层
k.deploymentStatus(ctx, common.GetDefaultSystemNamespace(true), common.DefaultQuchengName, common.DefaultQuchengName, "", status)
k.deploymentStatus(ctx, common.GetDefaultSystemNamespace(true), common.GetReleaseName(k.cfg.Quickon.DevOps), common.GetReleaseName(k.cfg.Quickon.DevOps), "", status)
// 数据库
k.deploymentStatus(ctx, common.GetDefaultSystemNamespace(true), common.DefaultDBName, common.DefaultDBName, "", status)
db := fmt.Sprintf("%s-mysql", common.GetReleaseName(k.cfg.Quickon.DevOps))
k.deploymentStatus(ctx, common.GetDefaultSystemNamespace(true), db, db, "", status)

// 插件状态
plugins, _ := plugin.GetMaps()
for _, p := range plugins {
k.quchengPluginStatus(ctx, p, status)
k.platformPluginStatus(ctx, p, status)
}
return nil
}

func (k *K8sStatusCollector) quchengPluginStatus(ctx context.Context, p plugin.Meta, status *Status) error {
k.option.Log.Debugf("check plugin %s status", p.Type)
func (k *K8sStatusCollector) platformPluginStatus(ctx context.Context, p plugin.Meta, status *Status) error {
k.option.Log.Debugf("check platform plugin %s status", p.Type)
stateCount := PodStateCount{Type: "Plugin"}
_, err := k.client.GetSecret(ctx, common.GetDefaultSystemNamespace(true), "qc-plugin-"+p.Type, metav1.GetOptions{})
if err != nil {
Expand Down
18 changes: 11 additions & 7 deletions internal/pkg/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type PodStateMap map[string]PodStateCount
type Status struct {
output string `json:"-" yaml:"-"`
KubeStatus KubeStatus `json:"k8s" yaml:"k8s"`
QStatus QStatus `json:"qucheng" yaml:"qucheng"`
QStatus QStatus `json:"platform" yaml:"platform"`
}

type KubeStatus struct {
Expand Down Expand Up @@ -109,8 +109,8 @@ func (s *Status) Format() error {
}
}
fmt.Fprintf(w, "\n")
fmt.Fprintf(w, "Qucheng Status: \n")
if s.QStatus.PodState["qucheng"].Disabled {
fmt.Fprintf(w, "Platform Status: \n")
if s.QStatus.PodState["platform"].Disabled {
fmt.Fprintf(w, " %s\t%s\n", "status", color.SBlue("disabled"))
w.Flush()
return output.EncodeText(os.Stdout, buf.Bytes())
Expand All @@ -131,8 +131,12 @@ func (s *Status) Format() error {
consoleURL = fmt.Sprintf("http://%s:32379", loginIP)
}
fmt.Fprintf(w, " namespace:\t%s\n", color.SBlue(common.GetDefaultSystemNamespace(true)))
fmt.Fprintf(w, " console: %s(%s/%s)\n", color.SGreen(consoleURL), color.SGreen(common.QuchengDefaultUser), color.SGreen(cfg.ConsolePassword))
quchengOK := true
if cfg.Quickon.DevOps {
fmt.Fprintf(w, " console: %s\n", color.SGreen(consoleURL))
} else {
fmt.Fprintf(w, " console: %s(%s/%s)\n", color.SGreen(consoleURL), color.SGreen(common.QuchengDefaultUser), color.SGreen(cfg.ConsolePassword))
}
ptOK := true
fmt.Fprintf(w, " component status: \n")
for name, state := range s.QStatus.PodState {
if state.Disabled {
Expand All @@ -142,7 +146,7 @@ func (s *Status) Format() error {
fmt.Fprintf(w, " %s\t%s\n", name, color.SGreen("ok"))
} else {
fmt.Fprintf(w, " %s\t%s\n", name, color.SRed("warn"))
quchengOK = false
ptOK = false
}
}
}
Expand All @@ -154,7 +158,7 @@ func (s *Status) Format() error {
fmt.Fprintf(w, " %s\t%s\n", name, color.SGreen("enabled"))
}
}
if quchengOK {
if ptOK {
fmt.Fprintf(w, " %s\t%s\n", "status", color.SGreen("health"))
} else {
fmt.Fprintf(w, " %s\t%s\n", "status", color.SRed("unhealth"))
Expand Down

0 comments on commit 2b9e3b2

Please sign in to comment.