代码拉取完成,页面将自动刷新
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
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。