代码拉取完成,页面将自动刷新
package clusterregistrationtokens
import (
"fmt"
"net/url"
"github.com/rancher/norman/types"
"github.com/rancher/rancher/pkg/settings"
"github.com/rancher/rancher/pkg/systemtemplate"
)
const (
commandFormat = "kubectl apply -f %s"
insecureCommandFormat = "curl --insecure -sfL %s | kubectl apply -f -"
nodeCommandFormat = "sudo docker run -d --privileged --restart=unless-stopped --net=host -v /etc/kubernetes:/etc/kubernetes -v /var/run:/var/run %s --server %s --token %s%s"
)
func Formatter(request *types.APIContext, resource *types.RawResource) {
ca := systemtemplate.CAChecksum()
if ca != "" {
ca = " --ca-checksum " + ca
}
token, _ := resource.Values["token"].(string)
if token != "" {
url := getURL(request, token)
resource.Values["insecureCommand"] = fmt.Sprintf(insecureCommandFormat, url)
resource.Values["command"] = fmt.Sprintf(commandFormat, url)
resource.Values["nodeCommand"] = fmt.Sprintf(nodeCommandFormat,
settings.AgentImage.Get(),
getRootURL(request),
token,
ca)
resource.Values["token"] = token
resource.Values["manifestUrl"] = url
}
}
func NodeCommand(token string) string {
ca := systemtemplate.CAChecksum()
if ca != "" {
ca = " --ca-checksum " + ca
}
return fmt.Sprintf(nodeCommandFormat,
settings.AgentImage.Get(),
getRootURL(nil),
token,
ca)
}
func getRootURL(request *types.APIContext) string {
serverURL := settings.ServerURL.Get()
if serverURL == "" {
if request != nil {
serverURL = request.URLBuilder.RelativeToRoot("")
}
} else {
u, err := url.Parse(serverURL)
if err != nil {
if request != nil {
serverURL = request.URLBuilder.RelativeToRoot("")
}
} else {
u.Path = ""
serverURL = u.String()
}
}
return serverURL
}
func getURL(request *types.APIContext, token string) string {
path := "/v3/import/" + token + ".yaml"
serverURL := settings.ServerURL.Get()
if serverURL == "" {
serverURL = request.URLBuilder.RelativeToRoot(path)
} else {
u, err := url.Parse(serverURL)
if err != nil {
serverURL = request.URLBuilder.RelativeToRoot(path)
} else {
u.Path = path
serverURL = u.String()
}
}
return serverURL
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。