-
Notifications
You must be signed in to change notification settings - Fork 0
/
formatter.go
37 lines (31 loc) · 1.13 KB
/
formatter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package clusterregistrationtokens
import (
"fmt"
"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 = "docker run -d --restart=unless-stopped --net=host -v /etc/kubernetes/ssl:/etc/kubernetes/ssl -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 := request.URLBuilder.RelativeToRoot("/v3/import/" + token + ".yaml")
resource.Values["insecureCommand"] = fmt.Sprintf(insecureCommandFormat, url)
resource.Values["command"] = fmt.Sprintf(commandFormat, url)
resource.Values["nodeCommand"] = fmt.Sprintf(nodeCommandFormat,
settings.AgentImage.Get(),
request.URLBuilder.RelativeToRoot(""),
token,
ca)
resource.Values["token"] = token
resource.Values["manifestUrl"] = url
}
}