37 Star 411 Fork 76

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
node.go 1.49 KB
一键复制 编辑 原始数据 按行查看 历史
Darren Shepherd 提交于 2018-04-14 23:45 . Add docker info to agent checkin
package node
import (
"context"
"os"
"strings"
"github.com/docker/docker/client"
"github.com/rancher/norman/types/slice"
"github.com/sirupsen/logrus"
)
func TokenAndURL() (string, string, error) {
return os.Getenv("CATTLE_TOKEN"), os.Getenv("CATTLE_SERVER"), nil
}
func Params() map[string]interface{} {
roles := split(os.Getenv("CATTLE_ROLE"))
params := map[string]interface{}{
"customConfig": map[string]interface{}{
"address": os.Getenv("CATTLE_ADDRESS"),
"internalAddress": os.Getenv("CATTLE_INTERNAL_ADDRESS"),
"roles": split(os.Getenv("CATTLE_ROLE")),
},
"etcd": slice.ContainsString(roles, "etcd"),
"controlPlane": slice.ContainsString(roles, "controlplane"),
"worker": slice.ContainsString(roles, "worker"),
"requestedHostname": os.Getenv("CATTLE_NODE_NAME"),
}
for k, v := range params {
if m, ok := v.(map[string]string); ok {
for k, v := range m {
logrus.Infof("Option %s=%s", k, v)
}
} else {
logrus.Infof("Option %s=%v", k, v)
}
}
dclient, err := client.NewEnvClient()
if err == nil {
info, err := dclient.Info(context.Background())
if err == nil {
params["dockerInfo"] = info
}
}
return map[string]interface{}{
"node": params,
}
}
func split(s string) []string {
var result []string
for _, part := range strings.Split(s, ",") {
p := strings.TrimSpace(part)
if p != "" {
result = append(result, p)
}
}
if len(result) == 1 && result[0] == "" {
return nil
}
return result
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.0.1-rc6

搜索帮助

0d507c66 1850385 C8b1a773 1850385