|
1 | 1 | package config |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "strconv" |
4 | 5 | "strings" |
5 | 6 |
|
6 | 7 | cnpgv1 "github.com/cloudnative-pg/cloudnative-pg/api/v1" |
@@ -57,6 +58,29 @@ type PluginConfiguration struct { |
57 | 58 |
|
58 | 59 | ReplicaSourceBarmanObjectName string |
59 | 60 | ReplicaSourceServerName string |
| 61 | + |
| 62 | + // Probe configuration |
| 63 | + StartupProbeConfig *ProbeConfig |
| 64 | +} |
| 65 | + |
| 66 | +// ProbeConfig holds configuration for Kubernetes probes |
| 67 | +type ProbeConfig struct { |
| 68 | + InitialDelaySeconds int32 |
| 69 | + TimeoutSeconds int32 |
| 70 | + PeriodSeconds int32 |
| 71 | + FailureThreshold int32 |
| 72 | + SuccessThreshold int32 |
| 73 | +} |
| 74 | + |
| 75 | +// DefaultProbeConfig returns the default probe configuration |
| 76 | +func DefaultProbeConfig() *ProbeConfig { |
| 77 | + return &ProbeConfig{ |
| 78 | + InitialDelaySeconds: 0, |
| 79 | + TimeoutSeconds: 10, |
| 80 | + PeriodSeconds: 10, |
| 81 | + FailureThreshold: 10, |
| 82 | + SuccessThreshold: 1, |
| 83 | + } |
60 | 84 | } |
61 | 85 |
|
62 | 86 | // GetBarmanObjectKey gets the namespaced name of the barman object |
@@ -166,11 +190,50 @@ func NewFromCluster(cluster *cnpgv1.Cluster) *PluginConfiguration { |
166 | 190 | // used for wal_restore in the designed primary of a replica cluster |
167 | 191 | ReplicaSourceServerName: replicaSourceServerName, |
168 | 192 | ReplicaSourceBarmanObjectName: replicaSourceBarmanObjectName, |
| 193 | + // probe configuration |
| 194 | + StartupProbeConfig: parseProbeConfig(helper.Parameters), |
169 | 195 | } |
170 | 196 |
|
171 | 197 | return result |
172 | 198 | } |
173 | 199 |
|
| 200 | +// parseProbeConfig parses probe configuration from plugin parameters |
| 201 | +func parseProbeConfig(parameters map[string]string) *ProbeConfig { |
| 202 | + config := DefaultProbeConfig() |
| 203 | + |
| 204 | + if val, ok := parameters["startupProbe.initialDelaySeconds"]; ok { |
| 205 | + if parsed, err := strconv.ParseInt(val, 10, 32); err == nil { |
| 206 | + config.InitialDelaySeconds = int32(parsed) |
| 207 | + } |
| 208 | + } |
| 209 | + |
| 210 | + if val, ok := parameters["startupProbe.timeoutSeconds"]; ok { |
| 211 | + if parsed, err := strconv.ParseInt(val, 10, 32); err == nil { |
| 212 | + config.TimeoutSeconds = int32(parsed) |
| 213 | + } |
| 214 | + } |
| 215 | + |
| 216 | + if val, ok := parameters["startupProbe.periodSeconds"]; ok { |
| 217 | + if parsed, err := strconv.ParseInt(val, 10, 32); err == nil { |
| 218 | + config.PeriodSeconds = int32(parsed) |
| 219 | + } |
| 220 | + } |
| 221 | + |
| 222 | + if val, ok := parameters["startupProbe.failureThreshold"]; ok { |
| 223 | + if parsed, err := strconv.ParseInt(val, 10, 32); err == nil { |
| 224 | + config.FailureThreshold = int32(parsed) |
| 225 | + } |
| 226 | + } |
| 227 | + |
| 228 | + if val, ok := parameters["startupProbe.successThreshold"]; ok { |
| 229 | + if parsed, err := strconv.ParseInt(val, 10, 32); err == nil { |
| 230 | + config.SuccessThreshold = int32(parsed) |
| 231 | + } |
| 232 | + } |
| 233 | + |
| 234 | + return config |
| 235 | +} |
| 236 | + |
174 | 237 | func getRecoveryParameters(cluster *cnpgv1.Cluster) map[string]string { |
175 | 238 | recoveryPluginConfiguration := getRecoverySourcePlugin(cluster) |
176 | 239 | if recoveryPluginConfiguration == nil { |
|
0 commit comments