Merge pull request #289 from GLYASAI/RAINBOND-931

[ADD] node role: lb
This commit is contained in:
barnettZQG 2019-05-15 07:49:53 -05:00 committed by GitHub
commit 5dee4c9fe1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 15 additions and 12 deletions

View File

@ -21,8 +21,8 @@ package cmd
import ( import (
"fmt" "fmt"
"os" "os"
"strconv" "strconv"
"strings"
"github.com/apcera/termtables" "github.com/apcera/termtables"
"github.com/goodrain/rainbond/grctl/clients" "github.com/goodrain/rainbond/grctl/clients"
@ -186,7 +186,7 @@ func handleRoleAndStatus(list []map[string]string) bool {
if v["role"] == "manage" && v["status"] == "running" { if v["role"] == "manage" && v["status"] == "running" {
manageFlag = true manageFlag = true
} }
if (v["role"] == "compute,manage" || v["role"] == "manage,compute") && v["status"] == "running" { if (strings.HasPrefix(v["role"], "compute,manage") || strings.HasPrefix(v["role"], "manage,compute")) && v["status"] == "running" {
computeFlag = true computeFlag = true
manageFlag = true manageFlag = true
} }

View File

@ -43,7 +43,7 @@ func NewCmdInit() cli.Command {
cli.StringFlag{ cli.StringFlag{
Name: "role", Name: "role",
Usage: "Node identity property", Usage: "Node identity property",
Value: "manage,compute", Value: "manage,compute,gateway",
}, },
cli.StringFlag{ cli.StringFlag{
Name: "work_dir", Name: "work_dir",

View File

@ -587,7 +587,7 @@ func NewCmdNode() cli.Command {
}, },
cli.StringFlag{ cli.StringFlag{
Name: "role,r", Name: "role,r",
Usage: "The option is required, the allowed values are: [manage|compute]", Usage: "The option is required, the allowed values are: [manage|compute|gateway]",
}, },
cli.StringFlag{ cli.StringFlag{
Name: "podCIDR,cidr", Name: "podCIDR,cidr",
@ -610,8 +610,8 @@ func NewCmdNode() cli.Command {
if c.String("root-pass") != "" && c.String("private-key") != "" { if c.String("root-pass") != "" && c.String("private-key") != "" {
showError("Options private-key and root-pass are conflicting") showError("Options private-key and root-pass are conflicting")
} }
if c.String("role") != "compute" && c.String("role") != "manage" { if c.String("role") != "compute" && c.String("role") != "manage" && c.String("role") != "gateway" {
showError("node role only support `compute` and `manage`") showError("node role only support `compute`, `manage` and `gateway`")
} }
var node client.APIHostNode var node client.APIHostNode
node.Role = c.String("role") node.Role = c.String("role")

View File

@ -131,7 +131,13 @@ func getKubeletMessage(v *client.HostNode) string {
//GetRuleNodes 获取分角色节点 //GetRuleNodes 获取分角色节点
func GetRuleNodes(w http.ResponseWriter, r *http.Request) { func GetRuleNodes(w http.ResponseWriter, r *http.Request) {
rule := chi.URLParam(r, "rule") rule := chi.URLParam(r, "rule")
if rule != "compute" && rule != "manage" && rule != "storage" { allowRule := map[string]struct{}{
"compute": struct{}{},
"manage": struct{}{},
"storage": struct{}{},
"gateway": struct{}{},
}
if _, ok := allowRule[rule]; !ok {
httputil.ReturnError(r, w, 400, rule+" rule is not define") httputil.ReturnError(r, w, 400, rule+" rule is not define")
return return
} }

View File

@ -63,9 +63,6 @@ func (n *NodeService) AddNode(node *client.APIHostNode) (*client.HostNode, *util
if node.Role == "" { if node.Role == "" {
return nil, utils.CreateAPIHandleError(400, fmt.Errorf("node role must not null")) return nil, utils.CreateAPIHandleError(400, fmt.Errorf("node role must not null"))
} }
if node.Role != "manage" && node.Role != "compute" {
return nil, utils.CreateAPIHandleError(400, fmt.Errorf("node role %s not support", node.Role))
}
if node.ID == "" { if node.ID == "" {
node.ID = uuid.NewV4().String() node.ID = uuid.NewV4().String()
} }

View File

@ -206,7 +206,7 @@ func (n *Cluster) handleNodeStatus(v *client.HostNode) {
v.NodeStatus.CurrentScheduleStatus = !k8sNode.Spec.Unschedulable v.NodeStatus.CurrentScheduleStatus = !k8sNode.Spec.Unschedulable
} }
} }
if v.Role.HasRule("manage") && !v.Role.HasRule("compute") { //manage install_success == runnint if (v.Role.HasRule("manage") || v.Role.HasRule("gateway")) && !v.Role.HasRule("compute") { //manage install_success == runnint
v.AvailableCPU = v.NodeStatus.NodeInfo.NumCPU v.AvailableCPU = v.NodeStatus.NodeInfo.NumCPU
v.AvailableMemory = int64(v.NodeStatus.NodeInfo.MemorySize) v.AvailableMemory = int64(v.NodeStatus.NodeInfo.MemorySize)
} }

View File

@ -43,7 +43,7 @@ type APIHostNode struct {
ExternalIP string `json:"external_ip" validate:"external_ip|ip"` ExternalIP string `json:"external_ip" validate:"external_ip|ip"`
RootPass string `json:"root_pass,omitempty"` RootPass string `json:"root_pass,omitempty"`
Privatekey string `json:"private_key,omitempty"` Privatekey string `json:"private_key,omitempty"`
Role string `json:"role" validate:"role|required"` Role string `json:"role" validate:"role|required|in:manage,compute,gateway"`
PodCIDR string `json:"podCIDR"` PodCIDR string `json:"podCIDR"`
AutoInstall bool `json:"auto_install"` AutoInstall bool `json:"auto_install"`
Labels map[string]string `json:"labels"` Labels map[string]string `json:"labels"`