-
Notifications
You must be signed in to change notification settings - Fork 0
/
formatter.go
45 lines (40 loc) · 1.68 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
38
39
40
41
42
43
44
45
package clusteregistrationtokens
import (
"strings"
"github.com/rancher/norman/types"
"github.com/rancher/norman/types/convert"
"github.com/rancher/types/client/management/v3"
"github.com/sirupsen/logrus"
)
func Formatter(request *types.APIContext, resource *types.RawResource) {
if convert.ToBool(resource.Values["internal"]) {
delete(resource.Links, "remove")
}
shellLink := request.URLBuilder.Link("shell", resource)
shellLink = strings.Replace(shellLink, "http", "ws", 1)
shellLink = strings.Replace(shellLink, "/shell", "?shell=true", 1)
resource.Links["shell"] = shellLink
resource.AddAction(request, "generateKubeconfig")
resource.AddAction(request, "importYaml")
resource.AddAction(request, "exportYaml")
if _, ok := resource.Values[client.ClusterSpecFieldRancherKubernetesEngineConfig]; ok {
resource.AddAction(request, "rotateCertificates")
}
if gkeConfig, ok := resource.Values[client.ClusterSpecFieldGoogleKubernetesEngineConfig]; ok {
configMap, ok := gkeConfig.(map[string]interface{})
if !ok {
logrus.Errorf("could not convert gke config to map")
return
}
setTrueIfNil(configMap, client.GoogleKubernetesEngineConfigFieldEnableStackdriverLogging)
setTrueIfNil(configMap, client.GoogleKubernetesEngineConfigFieldEnableStackdriverMonitoring)
setTrueIfNil(configMap, client.GoogleKubernetesEngineConfigFieldEnableHorizontalPodAutoscaling)
setTrueIfNil(configMap, client.GoogleKubernetesEngineConfigFieldEnableHTTPLoadBalancing)
setTrueIfNil(configMap, client.GoogleKubernetesEngineConfigFieldEnableNetworkPolicyConfig)
}
}
func setTrueIfNil(configMap map[string]interface{}, fieldName string) {
if configMap[fieldName] == nil {
configMap[fieldName] = true
}
}