-
Notifications
You must be signed in to change notification settings - Fork 0
/
formatter.go
63 lines (53 loc) · 1.88 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package clusteregistrationtokens
import (
"strings"
"github.com/rancher/norman/types"
"github.com/rancher/norman/types/convert"
"github.com/rancher/types/apis/management.cattle.io/v3"
"github.com/sirupsen/logrus"
)
type Formatter struct {
KontainerDriverLister v3.KontainerDriverLister
}
func (f *Formatter) 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 convert.ToBool(resource.Values["enableClusterMonitoring"]) {
resource.AddAction(request, "disableMonitoring")
} else {
resource.AddAction(request, "enableMonitoring")
}
if gkeConfig, ok := resource.Values["googleKubernetesEngineConfig"]; ok {
configMap, ok := gkeConfig.(map[string]interface{})
if !ok {
logrus.Errorf("could not convert gke config to map")
return
}
setTrueIfNil(configMap, "enableStackdriverLogging")
setTrueIfNil(configMap, "enableStackdriverMonitoring")
setTrueIfNil(configMap, "enableHorizontalPodAutoscaling")
setTrueIfNil(configMap, "enableHttpLoadBalancing")
setTrueIfNil(configMap, "enableNetworkPolicyConfig")
}
if eksConfig, ok := resource.Values["amazonElasticContainerServiceConfig"]; ok {
configMap, ok := eksConfig.(map[string]interface{})
if !ok {
logrus.Errorf("could not convert eks config to map")
return
}
setTrueIfNil(configMap, "associateWorkerNodePublicIp")
}
}
func setTrueIfNil(configMap map[string]interface{}, fieldName string) {
if configMap[fieldName] == nil {
configMap[fieldName] = true
}
}