-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathcommon.go
More file actions
94 lines (87 loc) · 2.62 KB
/
common.go
File metadata and controls
94 lines (87 loc) · 2.62 KB
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
package common
import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/intstr"
)
// GetDefaultMicroProfileStartupProbe returns the default values for MicroProfile Health-based startup probe.
func GetDefaultMicroProfileStartupProbe(ba BaseComponent) *corev1.Probe {
return &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Path: "/health/started",
Port: intstr.FromInt(int(ba.GetService().GetPort())),
Scheme: "HTTPS",
},
},
PeriodSeconds: 10,
TimeoutSeconds: 2,
FailureThreshold: 20,
}
}
// GetDefaultMicroProfileReadinessProbe returns the default values for MicroProfile Health-based readiness probe.
func GetDefaultMicroProfileReadinessProbe(ba BaseComponent) *corev1.Probe {
return &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Path: "/health/ready",
Port: intstr.FromInt(int(ba.GetService().GetPort())),
Scheme: "HTTPS",
},
},
InitialDelaySeconds: 10,
PeriodSeconds: 10,
TimeoutSeconds: 2,
FailureThreshold: 10,
}
}
// GetDefaultMicroProfileLivenessProbe returns the default values for MicroProfile Health-based liveness probe.
func GetDefaultMicroProfileLivenessProbe(ba BaseComponent) *corev1.Probe {
return &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Path: "/health/live",
Port: intstr.FromInt(int(ba.GetService().GetPort())),
Scheme: "HTTPS",
},
},
InitialDelaySeconds: 60,
PeriodSeconds: 10,
TimeoutSeconds: 2,
FailureThreshold: 3,
}
}
// GetComponentNameLabel returns the component's name label.
func GetComponentNameLabel(ba BaseComponent) string {
return ba.GetGroupName() + "/name"
}
func GetSecurityContext(asc *AppSecurityContext) *corev1.SecurityContext {
if asc == nil {
return nil
}
sc := asc.SecurityContext
securityContext := &corev1.SecurityContext{}
sc.DeepCopyInto(securityContext)
return securityContext
}
func PatchPodSecurityContext(asc *AppSecurityContext, podSecurityContext *corev1.PodSecurityContext) *corev1.PodSecurityContext {
if asc == nil {
return podSecurityContext
}
if podSecurityContext == nil {
podSecurityContext = &corev1.PodSecurityContext{}
}
sc := asc.IsolatedPodSecurityContext
if len(sc.SupplementalGroups) > 0 {
podSecurityContext.SupplementalGroups = sc.SupplementalGroups
}
if sc.FSGroup != nil {
podSecurityContext.FSGroup = sc.FSGroup
}
if len(sc.Sysctls) > 0 {
podSecurityContext.Sysctls = sc.Sysctls
}
if sc.FSGroupChangePolicy != nil {
podSecurityContext.FSGroupChangePolicy = sc.FSGroupChangePolicy
}
return podSecurityContext
}