Skip to content

Commit 43135df

Browse files
authored
Feature: Allow to customize probe configuration (#519)
1 parent c8a5d79 commit 43135df

File tree

10 files changed

+728
-163
lines changed

10 files changed

+728
-163
lines changed

pkg/apis/deployment/v1/server_group_spec.go

Lines changed: 87 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -72,37 +72,101 @@ type ServerGroupSpec struct {
7272
type ServerGroupProbesSpec struct {
7373
// LivenessProbeDisabled if true livenessProbes are disabled
7474
LivenessProbeDisabled *bool `json:"livenessProbeDisabled,omitempty"`
75-
// LivenessProbeDisabled if specified the given probes is used as liveness probe
76-
//LivenessProbeOverride *v1.Probe `json:"LivenessProbeOverride,omitempty"`
77-
// LivenessProbeDisabled if true readinessProbes are disabled
78-
ReadinessProbeDisabled *bool `json:"ReadinessProbeDisabled,omitempty"`
79-
// ReadinessProbeOverride if specified the given probes is used as readiness probe
80-
//ReadinessProbeOverride *v1.Probe `json:"ReadinessProbeOverride,omitempty"`
75+
// LivenessProbeSpec override liveness probe configuration
76+
LivenessProbeSpec *ServerGroupProbeSpec `json:"livenessProbeSpec,omitempty"`
77+
78+
// OldReadinessProbeDisabled if true readinessProbes are disabled
79+
//
80+
// Deprecated: This field is deprecated, keept only for backward compatibility.
81+
OldReadinessProbeDisabled *bool `json:"ReadinessProbeDisabled,omitempty"`
82+
// ReadinessProbeDisabled override flag for probe disabled in good manner (lowercase) with backward compatibility
83+
ReadinessProbeDisabled *bool `json:"readinessProbeDisabled,omitempty"`
84+
// ReadinessProbeSpec override readiness probe configuration
85+
ReadinessProbeSpec *ServerGroupProbeSpec `json:"readinessProbeSpec,omitempty"`
8186
}
8287

83-
// // HasLivenessProbeOverride returns true if a livenessprobe override is set
84-
// func (s ServerGroupProbesSpec) HasLivenessProbeOverride() bool {
85-
// return s.LivenessProbeOverride != nil
86-
// }
88+
// GetReadinessProbeDisabled returns in proper manner readiness probe flag with backward compatibility.
89+
func (s ServerGroupProbesSpec) GetReadinessProbeDisabled() *bool {
90+
if s.OldReadinessProbeDisabled != nil {
91+
return s.OldReadinessProbeDisabled
92+
}
8793

88-
// // HasReadinessProbeOverride returns true if a readinessprobe override is set
89-
// func (s ServerGroupProbesSpec) HasReadinessProbeOverride() bool {
90-
// return s.ReadinessProbeOverride != nil
91-
// }
94+
return s.ReadinessProbeDisabled
95+
}
9296

93-
// GetSidecars returns a list of sidecars the use wish to add
94-
func (s ServerGroupSpec) GetSidecars() []v1.Container {
95-
return s.Sidecars
97+
// ServerGroupProbeSpec
98+
type ServerGroupProbeSpec struct {
99+
InitialDelaySeconds *int32 `json:"initialDelaySeconds,omitempty"`
100+
PeriodSeconds *int32 `json:"periodSeconds,omitempty"`
101+
TimeoutSeconds *int32 `json:"timeoutSeconds,omitempty"`
102+
SuccessThreshold *int32 `json:"successThreshold,omitempty"`
103+
FailureThreshold *int32 `json:"failureThreshold,omitempty"`
104+
}
105+
106+
// GetInitialDelaySeconds return InitialDelaySeconds valid value. In case if InitialDelaySeconds is nil default is returned.
107+
func (s *ServerGroupProbeSpec) GetInitialDelaySeconds(d int32) int32 {
108+
if s == nil || s.InitialDelaySeconds == nil {
109+
return d // Default Kubernetes value
110+
}
111+
112+
return *s.InitialDelaySeconds
96113
}
97114

98-
// IsLivenessProbeDisabled returns true if liveness probes are disabled
99-
func (s ServerGroupProbesSpec) IsLivenessProbeDisabled() bool {
100-
return util.BoolOrDefault(s.LivenessProbeDisabled)
115+
// GetPeriodSeconds return PeriodSeconds valid value. In case if PeriodSeconds is nil default is returned.
116+
func (s *ServerGroupProbeSpec) GetPeriodSeconds(d int32) int32 {
117+
if s == nil || s.PeriodSeconds == nil {
118+
return d
119+
}
120+
121+
if *s.PeriodSeconds <= 0 {
122+
return 1 // Value 0 is not allowed
123+
}
124+
125+
return *s.PeriodSeconds
101126
}
102127

103-
// IsReadinessProbeDisabled returns true if readiness probes are disabled
104-
func (s ServerGroupProbesSpec) IsReadinessProbeDisabled() bool {
105-
return util.BoolOrDefault(s.ReadinessProbeDisabled)
128+
// GetTimeoutSeconds return TimeoutSeconds valid value. In case if TimeoutSeconds is nil default is returned.
129+
func (s *ServerGroupProbeSpec) GetTimeoutSeconds(d int32) int32 {
130+
if s == nil || s.TimeoutSeconds == nil {
131+
return d
132+
}
133+
134+
if *s.TimeoutSeconds <= 0 {
135+
return 1 // Value 0 is not allowed
136+
}
137+
138+
return *s.TimeoutSeconds
139+
}
140+
141+
// GetSuccessThreshold return SuccessThreshold valid value. In case if SuccessThreshold is nil default is returned.
142+
func (s *ServerGroupProbeSpec) GetSuccessThreshold(d int32) int32 {
143+
if s == nil || s.SuccessThreshold == nil {
144+
return d
145+
}
146+
147+
if *s.SuccessThreshold <= 0 {
148+
return 1 // Value 0 is not allowed
149+
}
150+
151+
return *s.SuccessThreshold
152+
}
153+
154+
// GetFailureThreshold return FailureThreshold valid value. In case if FailureThreshold is nil default is returned.
155+
func (s *ServerGroupProbeSpec) GetFailureThreshold(d int32) int32 {
156+
if s == nil || s.FailureThreshold == nil {
157+
return d
158+
}
159+
160+
if *s.FailureThreshold <= 0 {
161+
return 1 // Value 0 is not allowed
162+
}
163+
164+
return *s.FailureThreshold
165+
}
166+
167+
// GetSidecars returns a list of sidecars the use wish to add
168+
func (s ServerGroupSpec) GetSidecars() []v1.Container {
169+
return s.Sidecars
106170
}
107171

108172
// HasVolumeClaimTemplate returns whether there is a volumeClaimTemplate or not

pkg/apis/deployment/v1/zz_generated.deepcopy.go

Lines changed: 56 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/deployment/pod/probes.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2020 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
// Author Adam Janikowski
21+
//
22+
23+
package pod
24+
25+
import api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
26+
27+
func newProbe(canBeEnabled, enabledByDefault bool) Probe {
28+
return Probe{
29+
EnabledByDefault: enabledByDefault,
30+
CanBeEnabled: canBeEnabled,
31+
}
32+
}
33+
34+
func ReadinessSpec(group api.ServerGroup) Probe {
35+
return probeMap[group].readiness
36+
}
37+
38+
func LivenessSpec(group api.ServerGroup) Probe {
39+
return probeMap[group].liveness
40+
}
41+
42+
type Probe struct {
43+
CanBeEnabled, EnabledByDefault bool
44+
}
45+
46+
type probes struct {
47+
liveness, readiness Probe
48+
}
49+
50+
// probeMap defines default values and if Probe can be enabled
51+
var probeMap = map[api.ServerGroup]probes{
52+
api.ServerGroupSingle: {
53+
liveness: newProbe(true, true),
54+
readiness: newProbe(true, true),
55+
},
56+
api.ServerGroupAgents: {
57+
liveness: newProbe(true, true),
58+
readiness: newProbe(false, false),
59+
},
60+
api.ServerGroupDBServers: {
61+
liveness: newProbe(true, true),
62+
readiness: newProbe(false, false),
63+
},
64+
api.ServerGroupCoordinators: {
65+
liveness: newProbe(false, false),
66+
readiness: newProbe(true, true),
67+
},
68+
api.ServerGroupSyncMasters: {
69+
liveness: newProbe(true, true),
70+
readiness: newProbe(false, false),
71+
},
72+
api.ServerGroupSyncWorkers: {
73+
liveness: newProbe(true, true),
74+
readiness: newProbe(false, false),
75+
},
76+
}

0 commit comments

Comments
 (0)