/
default.go
114 lines (94 loc) · 5.93 KB
/
default.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package sync
import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"github.com/openshift/openshift-azure/pkg/util/jsonpath"
)
func defaultContainerSpec(obj map[string]interface{}) {
jsonpath.MustCompile("$.livenessProbe.failureThreshold").DeleteIfMatch(obj, int64(3))
jsonpath.MustCompile("$.livenessProbe.periodSeconds").DeleteIfMatch(obj, int64(10))
jsonpath.MustCompile("$.livenessProbe.successThreshold").DeleteIfMatch(obj, int64(1))
jsonpath.MustCompile("$.livenessProbe.timeoutSeconds").DeleteIfMatch(obj, int64(1))
jsonpath.MustCompile("$.ports.*.protocol").DeleteIfMatch(obj, "TCP")
jsonpath.MustCompile("$.readinessProbe.failureThreshold").DeleteIfMatch(obj, int64(3))
jsonpath.MustCompile("$.readinessProbe.periodSeconds").DeleteIfMatch(obj, int64(10))
jsonpath.MustCompile("$.readinessProbe.successThreshold").DeleteIfMatch(obj, int64(1))
jsonpath.MustCompile("$.readinessProbe.timeoutSeconds").DeleteIfMatch(obj, int64(1))
jsonpath.MustCompile("$.resources").DeleteIfMatch(obj, map[string]interface{}{})
jsonpath.MustCompile("$.terminationMessagePath").DeleteIfMatch(obj, "/dev/termination-log")
jsonpath.MustCompile("$.terminationMessagePolicy").DeleteIfMatch(obj, "File")
}
func defaultPodSpec(obj map[string]interface{}) {
for _, c := range jsonpath.MustCompile("$.containers.*").Get(obj) {
defaultContainerSpec(c.(map[string]interface{}))
}
for _, c := range jsonpath.MustCompile("$.initContainers.*").Get(obj) {
defaultContainerSpec(c.(map[string]interface{}))
}
jsonpath.MustCompile("$.dnsPolicy").DeleteIfMatch(obj, "ClusterFirst")
jsonpath.MustCompile("$.restartPolicy").DeleteIfMatch(obj, "Always")
jsonpath.MustCompile("$.schedulerName").DeleteIfMatch(obj, "default-scheduler")
jsonpath.MustCompile("$.securityContext").DeleteIfMatch(obj, map[string]interface{}{})
jsonpath.MustCompile("$.serviceAccount").Delete(obj) // deprecated alias of serviceAccountName
jsonpath.MustCompile("$.terminationGracePeriodSeconds").DeleteIfMatch(obj, int64(30))
jsonpath.MustCompile("$.volumes.*.configMap.defaultMode").DeleteIfMatch(obj, int64(0644))
jsonpath.MustCompile("$.volumes.*.hostPath.type").DeleteIfMatch(obj, "")
jsonpath.MustCompile("$.volumes.*.secret.defaultMode").DeleteIfMatch(obj, int64(0644))
}
// defaults removes default values, which don't have to be specified in sync pods config
// and are filled when applying the configuration to a cluster
func defaults(o unstructured.Unstructured) {
gk := o.GroupVersionKind().GroupKind()
switch gk.String() {
case "CronJob.batch":
for _, c := range jsonpath.MustCompile("$.spec.jobTemplate.spec.template.spec").Get(o.Object) {
defaultPodSpec(c.(map[string]interface{}))
}
jsonpath.MustCompile("$.spec.concurrencyPolicy").DeleteIfMatch(o.Object, "Allow")
jsonpath.MustCompile("$.spec.failedJobsHistoryLimit").DeleteIfMatch(o.Object, int64(1))
jsonpath.MustCompile("$.spec.successfulJobsHistoryLimit").DeleteIfMatch(o.Object, int64(3))
jsonpath.MustCompile("$.spec.suspend").DeleteIfMatch(o.Object, false)
case "DaemonSet.apps":
jsonpath.MustCompile("$.spec.revisionHistoryLimit").DeleteIfMatch(o.Object, int64(10))
for _, c := range jsonpath.MustCompile("$.spec.template.spec").Get(o.Object) {
defaultPodSpec(c.(map[string]interface{}))
}
jsonpath.MustCompile("$.spec.updateStrategy.rollingUpdate.maxUnavailable").DeleteIfMatch(o.Object, int64(1))
jsonpath.MustCompile("$.spec.updateStrategy.rollingUpdate").DeleteIfMatch(o.Object, map[string]interface{}{})
jsonpath.MustCompile("$.spec.updateStrategy.type").DeleteIfMatch(o.Object, "RollingUpdate")
jsonpath.MustCompile("$.spec.updateStrategy").DeleteIfMatch(o.Object, map[string]interface{}{})
case "Deployment.apps":
jsonpath.MustCompile("$.spec.progressDeadlineSeconds").DeleteIfMatch(o.Object, int64(600))
jsonpath.MustCompile("$.spec.revisionHistoryLimit").DeleteIfMatch(o.Object, int64(10))
jsonpath.MustCompile("$.spec.strategy.rollingUpdate.maxSurge").DeleteIfMatch(o.Object, "25%")
jsonpath.MustCompile("$.spec.strategy.rollingUpdate.maxUnavailable").DeleteIfMatch(o.Object, "25%")
jsonpath.MustCompile("$.spec.strategy.rollingUpdate").DeleteIfMatch(o.Object, map[string]interface{}{})
jsonpath.MustCompile("$.spec.strategy.type").DeleteIfMatch(o.Object, "RollingUpdate")
jsonpath.MustCompile("$.spec.strategy").DeleteIfMatch(o.Object, map[string]interface{}{})
for _, c := range jsonpath.MustCompile("$.spec.template.spec").Get(o.Object) {
defaultPodSpec(c.(map[string]interface{}))
}
case "Secret":
jsonpath.MustCompile("$.type").DeleteIfMatch(o.Object, "Opaque")
case "Service":
jsonpath.MustCompile("$.spec.ports.*.protocol").DeleteIfMatch(o.Object, "TCP")
jsonpath.MustCompile("$.spec.sessionAffinity").DeleteIfMatch(o.Object, "None")
jsonpath.MustCompile("$.spec.type").DeleteIfMatch(o.Object, "ClusterIP")
for _, p := range jsonpath.MustCompile("$.spec.ports.*").Get(o.Object) {
jsonpath.MustCompile("$.targetPort").DeleteIfMatch(p, jsonpath.MustCompile("$.port").Get(p)[0].(int64))
}
case "StatefulSet.apps":
jsonpath.MustCompile("$.spec.podManagementPolicy").DeleteIfMatch(o.Object, "OrderedReady")
jsonpath.MustCompile("$.spec.revisionHistoryLimit").DeleteIfMatch(o.Object, int64(10))
jsonpath.MustCompile("$.spec.serviceName").DeleteIfMatch(o.Object, "")
jsonpath.MustCompile("$.spec.updateStrategy.rollingUpdate.partition").DeleteIfMatch(o.Object, int64(0))
jsonpath.MustCompile("$.spec.updateStrategy.rollingUpdate").DeleteIfMatch(o.Object, map[string]interface{}{})
jsonpath.MustCompile("$.spec.updateStrategy.type").DeleteIfMatch(o.Object, "RollingUpdate")
jsonpath.MustCompile("$.spec.updateStrategy").DeleteIfMatch(o.Object, map[string]interface{}{})
for _, c := range jsonpath.MustCompile("$.spec.template.spec").Get(o.Object) {
defaultPodSpec(c.(map[string]interface{}))
}
case "StorageClass.storage.k8s.io":
jsonpath.MustCompile("$.reclaimPolicy").DeleteIfMatch(o.Object, "Delete")
jsonpath.MustCompile("$.volumeBindingMode").DeleteIfMatch(o.Object, "Immediate")
}
}