可以直接在节点启动时自动注册节点

This commit is contained in:
GoEdgeLab
2020-10-17 11:14:07 +08:00
parent b2bea2e0ed
commit 282900d611
6 changed files with 98 additions and 3 deletions

View File

@@ -0,0 +1,72 @@
package cluster
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
"strings"
)
type InstallNodesAction struct {
actionutils.ParentAction
}
func (this *InstallNodesAction) Init() {
this.Nav("", "node", "install")
this.SecondMenu("nodes")
}
func (this *InstallNodesAction) RunGet(params struct {
ClusterId int64
}) {
clusterResp, err := this.RPC().NodeClusterRPC().FindEnabledNodeCluster(this.AdminContext(), &pb.FindEnabledNodeClusterRequest{ClusterId: params.ClusterId})
if err != nil {
this.ErrorPage(err)
return
}
if clusterResp.Cluster == nil {
this.NotFound("nodeCluster", params.ClusterId)
return
}
cluster := clusterResp.Cluster
clusterAPINodesResp, err := this.RPC().NodeClusterRPC().FindAPINodesWithNodeCluster(this.AdminContext(), &pb.FindAPINodesWithNodeClusterRequest{ClusterId: params.ClusterId})
if err != nil {
this.ErrorPage(err)
return
}
if err != nil {
this.ErrorPage(err)
return
}
apiNodeAddrs := []string{}
if clusterAPINodesResp.UseAllAPINodes {
apiNodesResp, err := this.RPC().APINodeRPC().FindAllEnabledAPINodes(this.AdminContext(), &pb.FindAllEnabledAPINodesRequest{})
if err != nil {
this.ErrorPage(err)
return
}
for _, apiNode := range apiNodesResp.Nodes {
if !apiNode.IsOn {
continue
}
apiNodeAddrs = append(apiNodeAddrs, apiNode.AccessAddrs...)
}
} else {
for _, apiNode := range clusterAPINodesResp.ApiNodes {
if !apiNode.IsOn {
continue
}
apiNodeAddrs = append(apiNodeAddrs, apiNode.AccessAddrs...)
}
}
this.Data["cluster"] = maps.Map{
"uniqueId": cluster.UniqueId,
"secret": cluster.Secret,
"endpoints": "\"" + strings.Join(apiNodeAddrs, "\", \"") + "\"",
}
this.Show()
}