Skip to content

Commit

Permalink
add app mode to node view (#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiejingru authored Mar 30, 2021
1 parent b956d61 commit b32706e
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions spec/v1/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
coreV1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"

"github.com/baetyl/baetyl-go/v2/context"
"github.com/baetyl/baetyl-go/v2/errors"
"github.com/baetyl/baetyl-go/v2/log"
)
Expand Down Expand Up @@ -82,6 +83,7 @@ type NodeView struct {
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`
Annotations map[string]string `json:"annotations,omitempty" yaml:"annotations,omitempty"`
Report *ReportView `json:"report,omitempty" yaml:"report,omitempty"`
AppMode string `json:"appMode,omitempty" yaml:"appMode,omitempty"`
Desire Desire `json:"desire,omitempty" yaml:"desire,omitempty"`
SysApps []string `json:"sysApps,omitempty" yaml:"sysApps,omitempty"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
Expand Down Expand Up @@ -299,6 +301,7 @@ func (n *Node) View(timeout time.Duration) (*NodeView, error) {
}
}
report.countInstanceNum()
view.AppMode = report.calculateAppMode()
}
return view, nil
}
Expand Down Expand Up @@ -454,6 +457,15 @@ func (s *NodeStats) processResourcePercent(status *NodeStats, resourceType strin
return "0", nil
}

func (view *ReportView) calculateAppMode() string {
for _, node := range view.Node {
if node.ContainerRuntime == "" && node.MachineID == "" {
return context.RunModeNative
}
}
return context.RunModeKube
}

func (view *ReportView) countInstanceNum() {
nums := map[string]int{}
if view.AppStats != nil {
Expand Down

0 comments on commit b32706e

Please sign in to comment.