forked from mogensen/kubernetes-split-yaml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kubernetes-resources.go
57 lines (44 loc) · 1.15 KB
/
kubernetes-resources.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
package main
import (
"encoding/json"
"os"
"strings"
)
type shortNameMap map[string]string
func getShortName(kind string, shortNameMap shortNameMap) string {
if shortNameMap == nil {
shortNameMap = getDefaultShortNameMap()
}
kindLower := strings.ToLower(kind)
shortname, exists := shortNameMap[kindLower]
if !exists {
return kindLower
}
return shortname
}
func getDefaultShortNameMap() shortNameMap {
return shortNameMap{
"service": "svc",
"serviceaccount": "sa",
"rolebinding": "rb",
"clusterrolebinding": "crb",
"clusterrole": "cr",
"horizontalpodautoscaler": "hpa",
"poddisruptionbudget": "pdb",
"customresourcedefinition": "crd",
"configmap": "cm",
}
}
func loadCustomShortnameMapFile(path string) (shortNameMap, error) {
customShortnameMapFile, err := os.Open(path)
if err != nil {
return nil, err
}
defer customShortnameMapFile.Close()
decoder := json.NewDecoder(customShortnameMapFile)
shortnameMap := getDefaultShortNameMap()
if err := decoder.Decode(&shortnameMap); err != nil {
return nil, err
}
return shortnameMap, nil
}