Skip to content

Commit fe43537

Browse files
committed
allow overriding startupProbe property
1 parent ca71755 commit fe43537

File tree

9 files changed

+373
-0
lines changed

9 files changed

+373
-0
lines changed

api/v1/kubegres_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ type Volume struct {
6363
type Probe struct {
6464
LivenessProbe *v1.Probe `json:"livenessProbe,omitempty"`
6565
ReadinessProbe *v1.Probe `json:"readinessProbe,omitempty"`
66+
StartupProbe *v1.Probe `json:"startupProbe,omitempty"`
6667
}
6768

6869
type KubegresSpec struct {

api/v1/zz_generated.deepcopy.go

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

config/crd/bases/kubegres.reactive-tech.io_kubegres.yaml

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,156 @@ spec:
488488
format: int32
489489
type: integer
490490
type: object
491+
startupProbe:
492+
description: Probe describes a health check to be performed against
493+
a container to determine whether it is alive or ready to receive
494+
traffic.
495+
properties:
496+
exec:
497+
description: Exec specifies the action to take.
498+
properties:
499+
command:
500+
description: Command is the command line to execute inside
501+
the container, the working directory for the command is
502+
root ('/') in the container's filesystem. The command
503+
is simply exec'd, it is not run inside a shell, so traditional
504+
shell instructions ('|', etc) won't work. To use a shell,
505+
you need to explicitly call out to that shell. Exit
506+
status of 0 is treated as live/healthy and non-zero
507+
is unhealthy.
508+
items:
509+
type: string
510+
type: array
511+
type: object
512+
failureThreshold:
513+
description: Minimum consecutive failures for the probe to
514+
be considered failed after having succeeded. Defaults to
515+
3. Minimum value is 1.
516+
format: int32
517+
type: integer
518+
grpc:
519+
description: GRPC specifies an action involving a GRPC port.
520+
This is a beta field and requires enabling GRPCContainerProbe
521+
feature gate.
522+
properties:
523+
port:
524+
description: Port number of the gRPC service. Number must
525+
be in the range 1 to 65535.
526+
format: int32
527+
type: integer
528+
service:
529+
description: "Service is the name of the service to place
530+
in the gRPC HealthCheckRequest (see https://github.com/grpc/grpc/blob/master/doc/health-checking.md).
531+
\n If this is not specified, the default behavior is
532+
defined by gRPC."
533+
type: string
534+
required:
535+
- port
536+
type: object
537+
httpGet:
538+
description: HTTPGet specifies the http request to perform.
539+
properties:
540+
host:
541+
description: Host name to connect to, defaults to the
542+
pod IP. You probably want to set "Host" in httpHeaders
543+
instead.
544+
type: string
545+
httpHeaders:
546+
description: Custom headers to set in the request. HTTP
547+
allows repeated headers.
548+
items:
549+
description: HTTPHeader describes a custom header to
550+
be used in HTTP probes
551+
properties:
552+
name:
553+
description: The header field name
554+
type: string
555+
value:
556+
description: The header field value
557+
type: string
558+
required:
559+
- name
560+
- value
561+
type: object
562+
type: array
563+
path:
564+
description: Path to access on the HTTP server.
565+
type: string
566+
port:
567+
anyOf:
568+
- type: integer
569+
- type: string
570+
description: Name or number of the port to access on the
571+
container. Number must be in the range 1 to 65535. Name
572+
must be an IANA_SVC_NAME.
573+
x-kubernetes-int-or-string: true
574+
scheme:
575+
description: Scheme to use for connecting to the host.
576+
Defaults to HTTP.
577+
type: string
578+
required:
579+
- port
580+
type: object
581+
initialDelaySeconds:
582+
description: 'Number of seconds after the container has started
583+
before liveness probes are initiated. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes'
584+
format: int32
585+
type: integer
586+
periodSeconds:
587+
description: How often (in seconds) to perform the probe.
588+
Default to 10 seconds. Minimum value is 1.
589+
format: int32
590+
type: integer
591+
successThreshold:
592+
description: Minimum consecutive successes for the probe to
593+
be considered successful after having failed. Defaults to
594+
1. Must be 1 for liveness and startup. Minimum value is
595+
1.
596+
format: int32
597+
type: integer
598+
tcpSocket:
599+
description: TCPSocket specifies an action involving a TCP
600+
port.
601+
properties:
602+
host:
603+
description: 'Optional: Host name to connect to, defaults
604+
to the pod IP.'
605+
type: string
606+
port:
607+
anyOf:
608+
- type: integer
609+
- type: string
610+
description: Number or name of the port to access on the
611+
container. Number must be in the range 1 to 65535. Name
612+
must be an IANA_SVC_NAME.
613+
x-kubernetes-int-or-string: true
614+
required:
615+
- port
616+
type: object
617+
terminationGracePeriodSeconds:
618+
description: Optional duration in seconds the pod needs to
619+
terminate gracefully upon probe failure. The grace period
620+
is the duration in seconds after the processes running in
621+
the pod are sent a termination signal and the time when
622+
the processes are forcibly halted with a kill signal. Set
623+
this value longer than the expected cleanup time for your
624+
process. If this value is nil, the pod's terminationGracePeriodSeconds
625+
will be used. Otherwise, this value overrides the value
626+
provided by the pod spec. Value must be non-negative integer.
627+
The value zero indicates stop immediately via the kill signal
628+
(no opportunity to shut down). This is a beta field and
629+
requires enabling ProbeTerminationGracePeriod feature gate.
630+
Minimum value is 1. spec.terminationGracePeriodSeconds is
631+
used if unset.
632+
format: int64
633+
type: integer
634+
timeoutSeconds:
635+
description: 'Number of seconds after which the probe times
636+
out. Defaults to 1 second. Minimum value is 1. More info:
637+
https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes'
638+
format: int32
639+
type: integer
640+
type: object
491641
type: object
492642
replicas:
493643
format: int32

controllers/ctx/resources/ResourcesContext.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ func addStatefulSetSpecEnforcers(rc *ResourcesContext) {
166166
securityContextSpecEnforcer := statefulset_spec.CreateSecurityContextSpecEnforcer(rc.KubegresContext)
167167
livenessProbeSpecEnforcer := statefulset_spec.CreateLivenessProbeSpecEnforcer(rc.KubegresContext)
168168
readinessProbeSpecEnforcer := statefulset_spec.CreateReadinessProbeSpecEnforcer(rc.KubegresContext)
169+
startupProbeSpecEnforcer := statefulset_spec.CreateStartupProbeSpecEnforcer(rc.KubegresContext)
169170

170171
rc.StatefulSetsSpecsEnforcer = statefulset_spec.CreateStatefulSetsSpecsEnforcer(rc.KubegresContext)
171172
rc.StatefulSetsSpecsEnforcer.AddSpecEnforcer(&imageSpecEnforcer)
@@ -179,6 +180,7 @@ func addStatefulSetSpecEnforcers(rc *ResourcesContext) {
179180
rc.StatefulSetsSpecsEnforcer.AddSpecEnforcer(&securityContextSpecEnforcer)
180181
rc.StatefulSetsSpecsEnforcer.AddSpecEnforcer(&livenessProbeSpecEnforcer)
181182
rc.StatefulSetsSpecsEnforcer.AddSpecEnforcer(&readinessProbeSpecEnforcer)
183+
rc.StatefulSetsSpecsEnforcer.AddSpecEnforcer(&startupProbeSpecEnforcer)
182184

183185
rc.AllStatefulSetsSpecEnforcer = statefulset_spec.CreateAllStatefulSetsSpecEnforcer(rc.KubegresContext, rc.ResourcesStates, rc.BlockingOperation, rc.StatefulSetsSpecsEnforcer)
184186
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
Copyright 2021 Reactive Tech Limited.
3+
"Reactive Tech Limited" is a company located in England, United Kingdom.
4+
https://www.reactive-tech.io
5+
6+
Lead Developer: Alex Arica
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
*/
20+
21+
package statefulset_spec
22+
23+
import (
24+
apps "k8s.io/api/apps/v1"
25+
"reactive-tech.io/kubegres/controllers/ctx"
26+
"reactive-tech.io/kubegres/controllers/states"
27+
"reflect"
28+
)
29+
30+
type StartupProbeSpecEnforcer struct {
31+
kubegresContext ctx.KubegresContext
32+
resourcesStates states.ResourcesStates
33+
}
34+
35+
func CreateStartupProbeSpecEnforcer(kubegresContext ctx.KubegresContext) StartupProbeSpecEnforcer {
36+
return StartupProbeSpecEnforcer{kubegresContext: kubegresContext}
37+
}
38+
39+
func (r *StartupProbeSpecEnforcer) GetSpecName() string {
40+
return "StartupProbe"
41+
}
42+
43+
func (r *StartupProbeSpecEnforcer) CheckForSpecDifference(statefulSet *apps.StatefulSet) StatefulSetSpecDifference {
44+
current := statefulSet.Spec.Template.Spec.Containers[0].StartupProbe
45+
expected := r.kubegresContext.Kubegres.Spec.Probe.StartupProbe
46+
47+
if expected == nil {
48+
return StatefulSetSpecDifference{}
49+
}
50+
51+
if !reflect.DeepEqual(current, expected) {
52+
return StatefulSetSpecDifference{
53+
SpecName: r.GetSpecName(),
54+
Current: current.String(),
55+
Expected: expected.String(),
56+
}
57+
}
58+
59+
return StatefulSetSpecDifference{}
60+
}
61+
62+
func (r *StartupProbeSpecEnforcer) EnforceSpec(statefulSet *apps.StatefulSet) (wasSpecUpdated bool, err error) {
63+
statefulSet.Spec.Template.Spec.Containers[0].StartupProbe = r.kubegresContext.Kubegres.Spec.Probe.StartupProbe
64+
return true, nil
65+
}
66+
67+
func (r *StartupProbeSpecEnforcer) OnSpecEnforcedSuccessfully(statefulSet *apps.StatefulSet) error {
68+
return nil
69+
}

controllers/spec/template/yaml/PrimaryStatefulSetTemplate.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,17 @@ spec:
6363
apiVersion: v1
6464
fieldPath: status.podIP
6565

66+
startupProbe:
67+
exec:
68+
command:
69+
- sh
70+
- -c
71+
- exec pg_isready -U $POSTGRES_USER -h $POD_IP
72+
failureThreshold: 15
73+
initialDelaySeconds: 10
74+
periodSeconds: 60
75+
successThreshold: 1
76+
6677
livenessProbe:
6778
exec:
6879
command:

controllers/spec/template/yaml/ReplicaStatefulSetTemplate.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,17 @@ spec:
8585
apiVersion: v1
8686
fieldPath: status.podIP
8787

88+
startupProbe:
89+
exec:
90+
command:
91+
- sh
92+
- -c
93+
- exec pg_isready -U $POSTGRES_USER -h $POD_IP
94+
failureThreshold: 15
95+
initialDelaySeconds: 10
96+
periodSeconds: 60
97+
successThreshold: 1
98+
8899
livenessProbe:
89100
exec:
90101
command:

controllers/spec/template/yaml/Templates.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,17 @@ spec:
400400
apiVersion: v1
401401
fieldPath: status.podIP
402402
403+
startupProbe:
404+
exec:
405+
command:
406+
- sh
407+
- -c
408+
- exec pg_isready -U $POSTGRES_USER -h $POD_IP
409+
failureThreshold: 15
410+
initialDelaySeconds: 10
411+
periodSeconds: 60
412+
successThreshold: 1
413+
403414
livenessProbe:
404415
exec:
405416
command:
@@ -548,6 +559,17 @@ spec:
548559
apiVersion: v1
549560
fieldPath: status.podIP
550561
562+
startupProbe:
563+
exec:
564+
command:
565+
- sh
566+
- -c
567+
- exec pg_isready -U $POSTGRES_USER -h $POD_IP
568+
failureThreshold: 15
569+
initialDelaySeconds: 10
570+
periodSeconds: 60
571+
successThreshold: 1
572+
551573
livenessProbe:
552574
exec:
553575
command:

0 commit comments

Comments
 (0)