diff --git a/Backlog b/Backlog index dd8e709..879a9c8 100644 --- a/Backlog +++ b/Backlog @@ -1,41 +1,44 @@ - Scheduled for December 2021: - - update local kind + - update local kind & kubectl - Build controller with Kubebuilder v3.2.0 - Remove warning for CronJob which was updated from beta to stable since Kubernetes 1.21 -- Scheduled for May 2022: +- add a test in spec_readinessProbe_test and spec_livenessProbe_test so that + we test the default behaviour when no option is set from the YAML + +- Scheduled for either December 2021 or Jan 2022: - #20 : Delete PVC -- Scheduled for June 2022: +- Scheduled for May 2022: - #12 : Reuse PVC (see below) and Primary becomes a Replica As part of the available options for the field "failover.pvc", there would be: - - "keep": the default option currently with Kubegres where PVC are kept but not reused for safety and investigation reasons + - "retain": the default option currently with Kubegres where PVC are kept but not reused for safety and investigation reasons - "delete": the PVC will be deleted - "reuse": if the state of the PVC is healthy, it will be reused by the newly created Replica pod. I think that matches with your suggestion? -- Scheduled for July 2022: +- Scheduled for June 2022: - #?: PG bouncer -- Scheduled for August 2022: +- Scheduled for July 2022: - #51: add documentation about how to recover backup - add use cases documentation, for example how to expand storage manually and how to upgrade Postgres major version. - check how to setup log archiving in case of replica does not found a data -- Scheduled for September 2022: +- Scheduled for August 2022: - #46: Define Service Type for Primary and Replica -- Scheduled for October 2022: +- Scheduled for September 2022: - #7 : Allow major version upgrade using pg_upgrade -- Scheduled for November 2022: +- Scheduled for October 2022: - #35 : Restore database from a PV backup -- Scheduled for December 2022: +- Scheduled for November 2022: - #10 : Deploy Kubegres with a HELM chart -- Scheduled for January 2023: +- Scheduled for December 2022: - #? : Add a field to allow restarting StatefulSets and Pods via the YAML of "Kind: Kubegres"? Blocked: diff --git a/api/v1/kubegres_types.go b/api/v1/kubegres_types.go index b1e97a6..28c8fd0 100644 --- a/api/v1/kubegres_types.go +++ b/api/v1/kubegres_types.go @@ -60,6 +60,11 @@ type Volume struct { VolumeClaimTemplates []VolumeClaimTemplate `json:"volumeClaimTemplates,omitempty"` } +type Probe struct { + LivenessProbe *v1.Probe `json:"livenessProbe,omitempty"` + ReadinessProbe *v1.Probe `json:"readinessProbe,omitempty"` +} + type KubegresSpec struct { Replicas *int32 `json:"replicas,omitempty"` Image string `json:"image,omitempty"` @@ -74,8 +79,7 @@ type KubegresSpec struct { Resources v1.ResourceRequirements `json:"resources,omitempty"` Volume Volume `json:"volume,omitempty"` SecurityContext *v1.PodSecurityContext `json:"securityContext,omitempty"` - LivenessProbe *v1.Probe `json:"livenessProbe,omitempty"` - ReadinessProbe *v1.Probe `json:"readinessProbe,omitempty"` + Probe Probe `json:"probe,omitempty"` } // ----------------------- STATUS ----------------------------------------- diff --git a/api/v1/zz_generated.deepcopy.go b/api/v1/zz_generated.deepcopy.go index ae62cee..cc11ebb 100644 --- a/api/v1/zz_generated.deepcopy.go +++ b/api/v1/zz_generated.deepcopy.go @@ -209,16 +209,7 @@ func (in *KubegresSpec) DeepCopyInto(out *KubegresSpec) { *out = new(corev1.PodSecurityContext) (*in).DeepCopyInto(*out) } - if in.LivenessProbe != nil { - in, out := &in.LivenessProbe, &out.LivenessProbe - *out = new(corev1.Probe) - (*in).DeepCopyInto(*out) - } - if in.ReadinessProbe != nil { - in, out := &in.ReadinessProbe, &out.ReadinessProbe - *out = new(corev1.Probe) - (*in).DeepCopyInto(*out) - } + in.Probe.DeepCopyInto(&out.Probe) } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KubegresSpec. @@ -278,6 +269,31 @@ func (in *KubegresStatus) DeepCopy() *KubegresStatus { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Probe) DeepCopyInto(out *Probe) { + *out = *in + if in.LivenessProbe != nil { + in, out := &in.LivenessProbe, &out.LivenessProbe + *out = new(corev1.Probe) + (*in).DeepCopyInto(*out) + } + if in.ReadinessProbe != nil { + in, out := &in.ReadinessProbe, &out.ReadinessProbe + *out = new(corev1.Probe) + (*in).DeepCopyInto(*out) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Probe. +func (in *Probe) DeepCopy() *Probe { + if in == nil { + return nil + } + out := new(Probe) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Volume) DeepCopyInto(out *Volume) { *out = *in diff --git a/config/crd/bases/kubegres.reactive-tech.io_kubegres.yaml b/config/crd/bases/kubegres.reactive-tech.io_kubegres.yaml index 135e3f9..023ef7b 100644 --- a/config/crd/bases/kubegres.reactive-tech.io_kubegres.yaml +++ b/config/crd/bases/kubegres.reactive-tech.io_kubegres.yaml @@ -177,232 +177,243 @@ spec: type: string type: object type: array - livenessProbe: - description: Probe describes a health check to be performed against - a container to determine whether it is alive or ready to receive - traffic. - properties: - exec: - description: One and only one of the following should be specified. - Exec specifies the action to take. - properties: - command: - description: Command is the command line to execute inside - the container, the working directory for the command is - root ('/') in the container's filesystem. The command is - simply exec'd, it is not run inside a shell, so traditional - shell instructions ('|', etc) won't work. To use a shell, - you need to explicitly call out to that shell. Exit status - of 0 is treated as live/healthy and non-zero is unhealthy. - items: - type: string - type: array - type: object - failureThreshold: - description: Minimum consecutive failures for the probe to be - considered failed after having succeeded. Defaults to 3. Minimum - value is 1. - format: int32 - type: integer - httpGet: - description: HTTPGet specifies the http request to perform. - properties: - host: - description: Host name to connect to, defaults to the pod - IP. You probably want to set "Host" in httpHeaders instead. - type: string - httpHeaders: - description: Custom headers to set in the request. HTTP allows - repeated headers. - items: - description: HTTPHeader describes a custom header to be - used in HTTP probes - properties: - name: - description: The header field name - type: string - value: - description: The header field value - type: string - required: - - name - - value - type: object - type: array - path: - description: Path to access on the HTTP server. - type: string - port: - anyOf: - - type: integer - - type: string - description: Name or number of the port to access on the container. - Number must be in the range 1 to 65535. Name must be an - IANA_SVC_NAME. - x-kubernetes-int-or-string: true - scheme: - description: Scheme to use for connecting to the host. Defaults - to HTTP. - type: string - required: - - port - type: object - initialDelaySeconds: - description: 'Number of seconds after the container has started - before liveness probes are initiated. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' - format: int32 - type: integer - periodSeconds: - description: How often (in seconds) to perform the probe. Default - to 10 seconds. Minimum value is 1. - format: int32 - type: integer - successThreshold: - description: Minimum consecutive successes for the probe to be - considered successful after having failed. Defaults to 1. Must - be 1 for liveness and startup. Minimum value is 1. - format: int32 - type: integer - tcpSocket: - description: 'TCPSocket specifies an action involving a TCP port. - TCP hooks not yet supported TODO: implement a realistic TCP - lifecycle hook' - properties: - host: - description: 'Optional: Host name to connect to, defaults - to the pod IP.' - type: string - port: - anyOf: - - type: integer - - type: string - description: Number or name of the port to access on the container. - Number must be in the range 1 to 65535. Name must be an - IANA_SVC_NAME. - x-kubernetes-int-or-string: true - required: - - port - type: object - timeoutSeconds: - description: 'Number of seconds after which the probe times out. - Defaults to 1 second. Minimum value is 1. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' - format: int32 - type: integer - type: object port: format: int32 type: integer - readinessProbe: - description: Probe describes a health check to be performed against - a container to determine whether it is alive or ready to receive - traffic. + probe: properties: - exec: - description: One and only one of the following should be specified. - Exec specifies the action to take. + livenessProbe: + description: Probe describes a health check to be performed against + a container to determine whether it is alive or ready to receive + traffic. properties: - command: - description: Command is the command line to execute inside - the container, the working directory for the command is - root ('/') in the container's filesystem. The command is - simply exec'd, it is not run inside a shell, so traditional - shell instructions ('|', etc) won't work. To use a shell, - you need to explicitly call out to that shell. Exit status - of 0 is treated as live/healthy and non-zero is unhealthy. - items: - type: string - type: array - type: object - failureThreshold: - description: Minimum consecutive failures for the probe to be - considered failed after having succeeded. Defaults to 3. Minimum - value is 1. - format: int32 - type: integer - httpGet: - description: HTTPGet specifies the http request to perform. - properties: - host: - description: Host name to connect to, defaults to the pod - IP. You probably want to set "Host" in httpHeaders instead. - type: string - httpHeaders: - description: Custom headers to set in the request. HTTP allows - repeated headers. - items: - description: HTTPHeader describes a custom header to be - used in HTTP probes - properties: - name: - description: The header field name - type: string - value: - description: The header field value + exec: + description: One and only one of the following should be specified. + Exec specifies the action to take. + properties: + command: + description: Command is the command line to execute inside + the container, the working directory for the command is + root ('/') in the container's filesystem. The command + is simply exec'd, it is not run inside a shell, so traditional + shell instructions ('|', etc) won't work. To use a shell, + you need to explicitly call out to that shell. Exit + status of 0 is treated as live/healthy and non-zero + is unhealthy. + items: type: string - required: - - name - - value - type: object - type: array - path: - description: Path to access on the HTTP server. - type: string - port: - anyOf: - - type: integer - - type: string - description: Name or number of the port to access on the container. - Number must be in the range 1 to 65535. Name must be an - IANA_SVC_NAME. - x-kubernetes-int-or-string: true - scheme: - description: Scheme to use for connecting to the host. Defaults - to HTTP. - type: string - required: - - port + type: array + type: object + failureThreshold: + description: Minimum consecutive failures for the probe to + be considered failed after having succeeded. Defaults to + 3. Minimum value is 1. + format: int32 + type: integer + httpGet: + description: HTTPGet specifies the http request to perform. + properties: + host: + description: Host name to connect to, defaults to the + pod IP. You probably want to set "Host" in httpHeaders + instead. + type: string + httpHeaders: + description: Custom headers to set in the request. HTTP + allows repeated headers. + items: + description: HTTPHeader describes a custom header to + be used in HTTP probes + properties: + name: + description: The header field name + type: string + value: + description: The header field value + type: string + required: + - name + - value + type: object + type: array + path: + description: Path to access on the HTTP server. + type: string + port: + anyOf: + - type: integer + - type: string + description: Name or number of the port to access on the + container. Number must be in the range 1 to 65535. Name + must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + scheme: + description: Scheme to use for connecting to the host. + Defaults to HTTP. + type: string + required: + - port + type: object + initialDelaySeconds: + description: 'Number of seconds after the container has started + before liveness probes are initiated. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + format: int32 + type: integer + periodSeconds: + description: How often (in seconds) to perform the probe. + Default to 10 seconds. Minimum value is 1. + format: int32 + type: integer + successThreshold: + description: Minimum consecutive successes for the probe to + be considered successful after having failed. Defaults to + 1. Must be 1 for liveness and startup. Minimum value is + 1. + format: int32 + type: integer + tcpSocket: + description: 'TCPSocket specifies an action involving a TCP + port. TCP hooks not yet supported TODO: implement a realistic + TCP lifecycle hook' + properties: + host: + description: 'Optional: Host name to connect to, defaults + to the pod IP.' + type: string + port: + anyOf: + - type: integer + - type: string + description: Number or name of the port to access on the + container. Number must be in the range 1 to 65535. Name + must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + required: + - port + type: object + timeoutSeconds: + description: 'Number of seconds after which the probe times + out. Defaults to 1 second. Minimum value is 1. More info: + https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + format: int32 + type: integer type: object - initialDelaySeconds: - description: 'Number of seconds after the container has started - before liveness probes are initiated. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' - format: int32 - type: integer - periodSeconds: - description: How often (in seconds) to perform the probe. Default - to 10 seconds. Minimum value is 1. - format: int32 - type: integer - successThreshold: - description: Minimum consecutive successes for the probe to be - considered successful after having failed. Defaults to 1. Must - be 1 for liveness and startup. Minimum value is 1. - format: int32 - type: integer - tcpSocket: - description: 'TCPSocket specifies an action involving a TCP port. - TCP hooks not yet supported TODO: implement a realistic TCP - lifecycle hook' + readinessProbe: + description: Probe describes a health check to be performed against + a container to determine whether it is alive or ready to receive + traffic. properties: - host: - description: 'Optional: Host name to connect to, defaults - to the pod IP.' - type: string - port: - anyOf: - - type: integer - - type: string - description: Number or name of the port to access on the container. - Number must be in the range 1 to 65535. Name must be an - IANA_SVC_NAME. - x-kubernetes-int-or-string: true - required: - - port + exec: + description: One and only one of the following should be specified. + Exec specifies the action to take. + properties: + command: + description: Command is the command line to execute inside + the container, the working directory for the command is + root ('/') in the container's filesystem. The command + is simply exec'd, it is not run inside a shell, so traditional + shell instructions ('|', etc) won't work. To use a shell, + you need to explicitly call out to that shell. Exit + status of 0 is treated as live/healthy and non-zero + is unhealthy. + items: + type: string + type: array + type: object + failureThreshold: + description: Minimum consecutive failures for the probe to + be considered failed after having succeeded. Defaults to + 3. Minimum value is 1. + format: int32 + type: integer + httpGet: + description: HTTPGet specifies the http request to perform. + properties: + host: + description: Host name to connect to, defaults to the + pod IP. You probably want to set "Host" in httpHeaders + instead. + type: string + httpHeaders: + description: Custom headers to set in the request. HTTP + allows repeated headers. + items: + description: HTTPHeader describes a custom header to + be used in HTTP probes + properties: + name: + description: The header field name + type: string + value: + description: The header field value + type: string + required: + - name + - value + type: object + type: array + path: + description: Path to access on the HTTP server. + type: string + port: + anyOf: + - type: integer + - type: string + description: Name or number of the port to access on the + container. Number must be in the range 1 to 65535. Name + must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + scheme: + description: Scheme to use for connecting to the host. + Defaults to HTTP. + type: string + required: + - port + type: object + initialDelaySeconds: + description: 'Number of seconds after the container has started + before liveness probes are initiated. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + format: int32 + type: integer + periodSeconds: + description: How often (in seconds) to perform the probe. + Default to 10 seconds. Minimum value is 1. + format: int32 + type: integer + successThreshold: + description: Minimum consecutive successes for the probe to + be considered successful after having failed. Defaults to + 1. Must be 1 for liveness and startup. Minimum value is + 1. + format: int32 + type: integer + tcpSocket: + description: 'TCPSocket specifies an action involving a TCP + port. TCP hooks not yet supported TODO: implement a realistic + TCP lifecycle hook' + properties: + host: + description: 'Optional: Host name to connect to, defaults + to the pod IP.' + type: string + port: + anyOf: + - type: integer + - type: string + description: Number or name of the port to access on the + container. Number must be in the range 1 to 65535. Name + must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + required: + - port + type: object + timeoutSeconds: + description: 'Number of seconds after which the probe times + out. Defaults to 1 second. Minimum value is 1. More info: + https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + format: int32 + type: integer type: object - timeoutSeconds: - description: 'Number of seconds after which the probe times out. - Defaults to 1 second. Minimum value is 1. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' - format: int32 - type: integer type: object replicas: format: int32 diff --git a/config/localresource/default-namespace/kubegres.yaml b/config/localresource/default-namespace/kubegres.yaml index 59a5bb8..a3ad50b 100644 --- a/config/localresource/default-namespace/kubegres.yaml +++ b/config/localresource/default-namespace/kubegres.yaml @@ -16,29 +16,31 @@ spec: customConfig: mypostgres-conf - # livenessProbe: - # exec: - # command: - # - sh - # - -c - # - exec pg_isready -U postgres -h $POD_IP - # failureThreshold: 10 - # initialDelaySeconds: 60 - # periodSeconds: 20 - # successThreshold: 1 - # timeoutSeconds: 15 + #probe: + # + # livenessProbe: + # exec: + # command: + # - sh + # - -c + # - exec pg_isready -U postgres -h $POD_IP + # failureThreshold: 10 + # initialDelaySeconds: 60 + # periodSeconds: 20 + # successThreshold: 1 + # timeoutSeconds: 15 - # readinessProbe: - # exec: - # command: - # - sh - # - -c - # - exec pg_isready -U postgres -h $POD_IP - # failureThreshold: 3 - # initialDelaySeconds: 5 - # periodSeconds: 5 - # successThreshold: 1 - # timeoutSeconds: 3 + # readinessProbe: + # exec: + # command: + # - sh + # - -c + # - exec pg_isready -U postgres -h $POD_IP + # failureThreshold: 3 + # initialDelaySeconds: 5 + # periodSeconds: 5 + # successThreshold: 1 + # timeoutSeconds: 3 #securityContext: # runAsNonRoot: true diff --git a/controllers/spec/enforcer/statefulset_spec/LivenessProbeSpecEnforcer.go b/controllers/spec/enforcer/statefulset_spec/LivenessProbeSpecEnforcer.go index 31347ed..5894f23 100644 --- a/controllers/spec/enforcer/statefulset_spec/LivenessProbeSpecEnforcer.go +++ b/controllers/spec/enforcer/statefulset_spec/LivenessProbeSpecEnforcer.go @@ -42,7 +42,7 @@ func (r *LivenessProbeSpecEnforcer) GetSpecName() string { func (r *LivenessProbeSpecEnforcer) CheckForSpecDifference(statefulSet *apps.StatefulSet) StatefulSetSpecDifference { current := statefulSet.Spec.Template.Spec.Containers[0].LivenessProbe - expected := r.kubegresContext.Kubegres.Spec.LivenessProbe + expected := r.kubegresContext.Kubegres.Spec.Probe.LivenessProbe if expected == nil { return StatefulSetSpecDifference{} @@ -60,7 +60,7 @@ func (r *LivenessProbeSpecEnforcer) CheckForSpecDifference(statefulSet *apps.Sta } func (r *LivenessProbeSpecEnforcer) EnforceSpec(statefulSet *apps.StatefulSet) (wasSpecUpdated bool, err error) { - statefulSet.Spec.Template.Spec.Containers[0].LivenessProbe = r.kubegresContext.Kubegres.Spec.LivenessProbe + statefulSet.Spec.Template.Spec.Containers[0].LivenessProbe = r.kubegresContext.Kubegres.Spec.Probe.LivenessProbe return true, nil } diff --git a/controllers/spec/enforcer/statefulset_spec/ReadinessProbeSpecEnforcer.go b/controllers/spec/enforcer/statefulset_spec/ReadinessProbeSpecEnforcer.go index 636d0ff..c63a8c1 100644 --- a/controllers/spec/enforcer/statefulset_spec/ReadinessProbeSpecEnforcer.go +++ b/controllers/spec/enforcer/statefulset_spec/ReadinessProbeSpecEnforcer.go @@ -40,7 +40,7 @@ func (r *ReadinessProbeSpecEnforcer) GetSpecName() string { func (r *ReadinessProbeSpecEnforcer) CheckForSpecDifference(statefulSet *apps.StatefulSet) StatefulSetSpecDifference { current := statefulSet.Spec.Template.Spec.Containers[0].ReadinessProbe - expected := r.kubegresContext.Kubegres.Spec.ReadinessProbe + expected := r.kubegresContext.Kubegres.Spec.Probe.ReadinessProbe if expected == nil { return StatefulSetSpecDifference{} @@ -58,7 +58,7 @@ func (r *ReadinessProbeSpecEnforcer) CheckForSpecDifference(statefulSet *apps.St } func (r *ReadinessProbeSpecEnforcer) EnforceSpec(statefulSet *apps.StatefulSet) (wasSpecUpdated bool, err error) { - statefulSet.Spec.Template.Spec.Containers[0].ReadinessProbe = r.kubegresContext.Kubegres.Spec.ReadinessProbe + statefulSet.Spec.Template.Spec.Containers[0].ReadinessProbe = r.kubegresContext.Kubegres.Spec.Probe.ReadinessProbe return true, nil } diff --git a/controllers/spec/template/ResourcesCreatorFromTemplate.go b/controllers/spec/template/ResourcesCreatorFromTemplate.go index ecc1c9b..4adedcd 100644 --- a/controllers/spec/template/ResourcesCreatorFromTemplate.go +++ b/controllers/spec/template/ResourcesCreatorFromTemplate.go @@ -257,12 +257,12 @@ func (r *ResourcesCreatorFromTemplate) initStatefulSet( statefulSetTemplate.Spec.Template.Spec.SecurityContext = postgresSpec.SecurityContext } - if postgresSpec.LivenessProbe != nil { - statefulSetTemplate.Spec.Template.Spec.Containers[0].LivenessProbe = postgresSpec.LivenessProbe + if postgresSpec.Probe.LivenessProbe != nil { + statefulSetTemplate.Spec.Template.Spec.Containers[0].LivenessProbe = postgresSpec.Probe.LivenessProbe } - if postgresSpec.ReadinessProbe != nil { - statefulSetTemplate.Spec.Template.Spec.Containers[0].ReadinessProbe = postgresSpec.ReadinessProbe + if postgresSpec.Probe.ReadinessProbe != nil { + statefulSetTemplate.Spec.Template.Spec.Containers[0].ReadinessProbe = postgresSpec.Probe.ReadinessProbe } } diff --git a/controllers/spec/template/yaml/PrimaryStatefulSetTemplate.yaml b/controllers/spec/template/yaml/PrimaryStatefulSetTemplate.yaml index 002837e..8e52ffb 100644 --- a/controllers/spec/template/yaml/PrimaryStatefulSetTemplate.yaml +++ b/controllers/spec/template/yaml/PrimaryStatefulSetTemplate.yaml @@ -69,11 +69,11 @@ spec: - sh - -c - exec pg_isready -U postgres -h $POD_IP - failureThreshold: 6 + failureThreshold: 10 initialDelaySeconds: 60 - periodSeconds: 10 + periodSeconds: 20 successThreshold: 1 - timeoutSeconds: 5 + timeoutSeconds: 15 readinessProbe: exec: @@ -83,7 +83,7 @@ spec: - exec pg_isready -U postgres -h $POD_IP failureThreshold: 3 initialDelaySeconds: 5 - periodSeconds: 5 + periodSeconds: 10 successThreshold: 1 timeoutSeconds: 3 diff --git a/controllers/spec/template/yaml/ReplicaStatefulSetTemplate.yaml b/controllers/spec/template/yaml/ReplicaStatefulSetTemplate.yaml index 9b92168..cb4bbe9 100644 --- a/controllers/spec/template/yaml/ReplicaStatefulSetTemplate.yaml +++ b/controllers/spec/template/yaml/ReplicaStatefulSetTemplate.yaml @@ -91,11 +91,11 @@ spec: - sh - -c - exec pg_isready -U postgres -h $POD_IP - failureThreshold: 6 + failureThreshold: 10 initialDelaySeconds: 60 - periodSeconds: 10 + periodSeconds: 20 successThreshold: 1 - timeoutSeconds: 5 + timeoutSeconds: 15 readinessProbe: exec: @@ -105,7 +105,7 @@ spec: - exec pg_isready -U postgres -h $POD_IP failureThreshold: 3 initialDelaySeconds: 5 - periodSeconds: 5 + periodSeconds: 10 successThreshold: 1 timeoutSeconds: 3 diff --git a/controllers/spec/template/yaml/Templates.go b/controllers/spec/template/yaml/Templates.go index 41f33c3..fbc0fef 100644 --- a/controllers/spec/template/yaml/Templates.go +++ b/controllers/spec/template/yaml/Templates.go @@ -406,11 +406,11 @@ spec: - sh - -c - exec pg_isready -U postgres -h $POD_IP - failureThreshold: 6 + failureThreshold: 10 initialDelaySeconds: 60 - periodSeconds: 10 + periodSeconds: 20 successThreshold: 1 - timeoutSeconds: 5 + timeoutSeconds: 15 readinessProbe: exec: @@ -420,7 +420,7 @@ spec: - exec pg_isready -U postgres -h $POD_IP failureThreshold: 3 initialDelaySeconds: 5 - periodSeconds: 5 + periodSeconds: 10 successThreshold: 1 timeoutSeconds: 3 @@ -554,11 +554,11 @@ spec: - sh - -c - exec pg_isready -U postgres -h $POD_IP - failureThreshold: 6 + failureThreshold: 10 initialDelaySeconds: 60 - periodSeconds: 10 + periodSeconds: 20 successThreshold: 1 - timeoutSeconds: 5 + timeoutSeconds: 15 readinessProbe: exec: @@ -568,7 +568,7 @@ spec: - exec pg_isready -U postgres -h $POD_IP failureThreshold: 3 initialDelaySeconds: 5 - periodSeconds: 5 + periodSeconds: 10 successThreshold: 1 timeoutSeconds: 3 diff --git a/kubegres.yaml b/kubegres.yaml index f92afbc..8a84194 100644 --- a/kubegres.yaml +++ b/kubegres.yaml @@ -153,178 +153,181 @@ spec: type: string type: object type: array - livenessProbe: - description: Probe describes a health check to be performed against a container to determine whether it is alive or ready to receive traffic. - properties: - exec: - description: One and only one of the following should be specified. Exec specifies the action to take. - properties: - command: - description: Command is the command line to execute inside the container, the working directory for the command is root ('/') in the container's filesystem. The command is simply exec'd, it is not run inside a shell, so traditional shell instructions ('|', etc) won't work. To use a shell, you need to explicitly call out to that shell. Exit status of 0 is treated as live/healthy and non-zero is unhealthy. - items: - type: string - type: array - type: object - failureThreshold: - description: Minimum consecutive failures for the probe to be considered failed after having succeeded. Defaults to 3. Minimum value is 1. - format: int32 - type: integer - httpGet: - description: HTTPGet specifies the http request to perform. - properties: - host: - description: Host name to connect to, defaults to the pod IP. You probably want to set "Host" in httpHeaders instead. - type: string - httpHeaders: - description: Custom headers to set in the request. HTTP allows repeated headers. - items: - description: HTTPHeader describes a custom header to be used in HTTP probes - properties: - name: - description: The header field name - type: string - value: - description: The header field value - type: string - required: - - name - - value - type: object - type: array - path: - description: Path to access on the HTTP server. - type: string - port: - anyOf: - - type: integer - - type: string - description: Name or number of the port to access on the container. Number must be in the range 1 to 65535. Name must be an IANA_SVC_NAME. - x-kubernetes-int-or-string: true - scheme: - description: Scheme to use for connecting to the host. Defaults to HTTP. - type: string - required: - - port - type: object - initialDelaySeconds: - description: 'Number of seconds after the container has started before liveness probes are initiated. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' - format: int32 - type: integer - periodSeconds: - description: How often (in seconds) to perform the probe. Default to 10 seconds. Minimum value is 1. - format: int32 - type: integer - successThreshold: - description: Minimum consecutive successes for the probe to be considered successful after having failed. Defaults to 1. Must be 1 for liveness and startup. Minimum value is 1. - format: int32 - type: integer - tcpSocket: - description: 'TCPSocket specifies an action involving a TCP port. TCP hooks not yet supported TODO: implement a realistic TCP lifecycle hook' - properties: - host: - description: 'Optional: Host name to connect to, defaults to the pod IP.' - type: string - port: - anyOf: - - type: integer - - type: string - description: Number or name of the port to access on the container. Number must be in the range 1 to 65535. Name must be an IANA_SVC_NAME. - x-kubernetes-int-or-string: true - required: - - port - type: object - timeoutSeconds: - description: 'Number of seconds after which the probe times out. Defaults to 1 second. Minimum value is 1. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' - format: int32 - type: integer - type: object port: format: int32 type: integer - readinessProbe: - description: Probe describes a health check to be performed against a container to determine whether it is alive or ready to receive traffic. + probe: properties: - exec: - description: One and only one of the following should be specified. Exec specifies the action to take. + livenessProbe: + description: Probe describes a health check to be performed against a container to determine whether it is alive or ready to receive traffic. properties: - command: - description: Command is the command line to execute inside the container, the working directory for the command is root ('/') in the container's filesystem. The command is simply exec'd, it is not run inside a shell, so traditional shell instructions ('|', etc) won't work. To use a shell, you need to explicitly call out to that shell. Exit status of 0 is treated as live/healthy and non-zero is unhealthy. - items: - type: string - type: array - type: object - failureThreshold: - description: Minimum consecutive failures for the probe to be considered failed after having succeeded. Defaults to 3. Minimum value is 1. - format: int32 - type: integer - httpGet: - description: HTTPGet specifies the http request to perform. - properties: - host: - description: Host name to connect to, defaults to the pod IP. You probably want to set "Host" in httpHeaders instead. - type: string - httpHeaders: - description: Custom headers to set in the request. HTTP allows repeated headers. - items: - description: HTTPHeader describes a custom header to be used in HTTP probes - properties: - name: - description: The header field name - type: string - value: - description: The header field value + exec: + description: One and only one of the following should be specified. Exec specifies the action to take. + properties: + command: + description: Command is the command line to execute inside the container, the working directory for the command is root ('/') in the container's filesystem. The command is simply exec'd, it is not run inside a shell, so traditional shell instructions ('|', etc) won't work. To use a shell, you need to explicitly call out to that shell. Exit status of 0 is treated as live/healthy and non-zero is unhealthy. + items: type: string - required: - - name - - value - type: object - type: array - path: - description: Path to access on the HTTP server. - type: string - port: - anyOf: - - type: integer - - type: string - description: Name or number of the port to access on the container. Number must be in the range 1 to 65535. Name must be an IANA_SVC_NAME. - x-kubernetes-int-or-string: true - scheme: - description: Scheme to use for connecting to the host. Defaults to HTTP. - type: string - required: - - port + type: array + type: object + failureThreshold: + description: Minimum consecutive failures for the probe to be considered failed after having succeeded. Defaults to 3. Minimum value is 1. + format: int32 + type: integer + httpGet: + description: HTTPGet specifies the http request to perform. + properties: + host: + description: Host name to connect to, defaults to the pod IP. You probably want to set "Host" in httpHeaders instead. + type: string + httpHeaders: + description: Custom headers to set in the request. HTTP allows repeated headers. + items: + description: HTTPHeader describes a custom header to be used in HTTP probes + properties: + name: + description: The header field name + type: string + value: + description: The header field value + type: string + required: + - name + - value + type: object + type: array + path: + description: Path to access on the HTTP server. + type: string + port: + anyOf: + - type: integer + - type: string + description: Name or number of the port to access on the container. Number must be in the range 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + scheme: + description: Scheme to use for connecting to the host. Defaults to HTTP. + type: string + required: + - port + type: object + initialDelaySeconds: + description: 'Number of seconds after the container has started before liveness probes are initiated. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + format: int32 + type: integer + periodSeconds: + description: How often (in seconds) to perform the probe. Default to 10 seconds. Minimum value is 1. + format: int32 + type: integer + successThreshold: + description: Minimum consecutive successes for the probe to be considered successful after having failed. Defaults to 1. Must be 1 for liveness and startup. Minimum value is 1. + format: int32 + type: integer + tcpSocket: + description: 'TCPSocket specifies an action involving a TCP port. TCP hooks not yet supported TODO: implement a realistic TCP lifecycle hook' + properties: + host: + description: 'Optional: Host name to connect to, defaults to the pod IP.' + type: string + port: + anyOf: + - type: integer + - type: string + description: Number or name of the port to access on the container. Number must be in the range 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + required: + - port + type: object + timeoutSeconds: + description: 'Number of seconds after which the probe times out. Defaults to 1 second. Minimum value is 1. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + format: int32 + type: integer type: object - initialDelaySeconds: - description: 'Number of seconds after the container has started before liveness probes are initiated. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' - format: int32 - type: integer - periodSeconds: - description: How often (in seconds) to perform the probe. Default to 10 seconds. Minimum value is 1. - format: int32 - type: integer - successThreshold: - description: Minimum consecutive successes for the probe to be considered successful after having failed. Defaults to 1. Must be 1 for liveness and startup. Minimum value is 1. - format: int32 - type: integer - tcpSocket: - description: 'TCPSocket specifies an action involving a TCP port. TCP hooks not yet supported TODO: implement a realistic TCP lifecycle hook' + readinessProbe: + description: Probe describes a health check to be performed against a container to determine whether it is alive or ready to receive traffic. properties: - host: - description: 'Optional: Host name to connect to, defaults to the pod IP.' - type: string - port: - anyOf: - - type: integer - - type: string - description: Number or name of the port to access on the container. Number must be in the range 1 to 65535. Name must be an IANA_SVC_NAME. - x-kubernetes-int-or-string: true - required: - - port + exec: + description: One and only one of the following should be specified. Exec specifies the action to take. + properties: + command: + description: Command is the command line to execute inside the container, the working directory for the command is root ('/') in the container's filesystem. The command is simply exec'd, it is not run inside a shell, so traditional shell instructions ('|', etc) won't work. To use a shell, you need to explicitly call out to that shell. Exit status of 0 is treated as live/healthy and non-zero is unhealthy. + items: + type: string + type: array + type: object + failureThreshold: + description: Minimum consecutive failures for the probe to be considered failed after having succeeded. Defaults to 3. Minimum value is 1. + format: int32 + type: integer + httpGet: + description: HTTPGet specifies the http request to perform. + properties: + host: + description: Host name to connect to, defaults to the pod IP. You probably want to set "Host" in httpHeaders instead. + type: string + httpHeaders: + description: Custom headers to set in the request. HTTP allows repeated headers. + items: + description: HTTPHeader describes a custom header to be used in HTTP probes + properties: + name: + description: The header field name + type: string + value: + description: The header field value + type: string + required: + - name + - value + type: object + type: array + path: + description: Path to access on the HTTP server. + type: string + port: + anyOf: + - type: integer + - type: string + description: Name or number of the port to access on the container. Number must be in the range 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + scheme: + description: Scheme to use for connecting to the host. Defaults to HTTP. + type: string + required: + - port + type: object + initialDelaySeconds: + description: 'Number of seconds after the container has started before liveness probes are initiated. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + format: int32 + type: integer + periodSeconds: + description: How often (in seconds) to perform the probe. Default to 10 seconds. Minimum value is 1. + format: int32 + type: integer + successThreshold: + description: Minimum consecutive successes for the probe to be considered successful after having failed. Defaults to 1. Must be 1 for liveness and startup. Minimum value is 1. + format: int32 + type: integer + tcpSocket: + description: 'TCPSocket specifies an action involving a TCP port. TCP hooks not yet supported TODO: implement a realistic TCP lifecycle hook' + properties: + host: + description: 'Optional: Host name to connect to, defaults to the pod IP.' + type: string + port: + anyOf: + - type: integer + - type: string + description: Number or name of the port to access on the container. Number must be in the range 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + required: + - port + type: object + timeoutSeconds: + description: 'Number of seconds after which the probe times out. Defaults to 1 second. Minimum value is 1. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + format: int32 + type: integer type: object - timeoutSeconds: - description: 'Number of seconds after which the probe times out. Defaults to 1 second. Minimum value is 1. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' - format: int32 - type: integer type: object replicas: format: int32 diff --git a/test/spec_livenessProbe_test.go b/test/spec_livenessProbe_test.go index c3dc69a..c0e005c 100644 --- a/test/spec_livenessProbe_test.go +++ b/test/spec_livenessProbe_test.go @@ -145,7 +145,7 @@ func (r *SpecLivenessProbeTest) givenLivenessProbe2() *v12.Probe { func (r *SpecLivenessProbeTest) givenNewKubegresSpecIsSetTo(livenessProbe *v12.Probe, specNbreReplicas int32) { r.kubegresResource = resourceConfigs.LoadKubegresYaml() - r.kubegresResource.Spec.LivenessProbe = livenessProbe + r.kubegresResource.Spec.Probe.LivenessProbe = livenessProbe r.kubegresResource.Spec.Replicas = &specNbreReplicas } @@ -159,7 +159,7 @@ func (r *SpecLivenessProbeTest) givenExistingKubegresSpecIsSetTo(livenessProbe * return } - r.kubegresResource.Spec.LivenessProbe = livenessProbe + r.kubegresResource.Spec.Probe.LivenessProbe = livenessProbe } func (r *SpecLivenessProbeTest) whenKubegresIsCreated() { @@ -209,6 +209,6 @@ func (r *SpecLivenessProbeTest) thenDeployedKubegresSpecShouldBeSetTo(expectedPr return } - currentProbe := r.kubegresResource.Spec.LivenessProbe + currentProbe := r.kubegresResource.Spec.Probe.LivenessProbe Expect(currentProbe).Should(Equal(expectedProbe)) } diff --git a/test/spec_readinessProbe_test.go b/test/spec_readinessProbe_test.go index 1a66d40..7fba919 100644 --- a/test/spec_readinessProbe_test.go +++ b/test/spec_readinessProbe_test.go @@ -145,7 +145,7 @@ func (r *SpecReadinessProbeTest) givenReadinessProbe2() *v12.Probe { func (r *SpecReadinessProbeTest) givenNewKubegresSpecIsSetTo(readinessProbe *v12.Probe, specNbreReplicas int32) { r.kubegresResource = resourceConfigs.LoadKubegresYaml() - r.kubegresResource.Spec.ReadinessProbe = readinessProbe + r.kubegresResource.Spec.Probe.ReadinessProbe = readinessProbe r.kubegresResource.Spec.Replicas = &specNbreReplicas } @@ -159,7 +159,7 @@ func (r *SpecReadinessProbeTest) givenExistingKubegresSpecIsSetTo(readinessProbe return } - r.kubegresResource.Spec.ReadinessProbe = readinessProbe + r.kubegresResource.Spec.Probe.ReadinessProbe = readinessProbe } func (r *SpecReadinessProbeTest) whenKubegresIsCreated() { @@ -209,6 +209,6 @@ func (r *SpecReadinessProbeTest) thenDeployedKubegresSpecShouldBeSetTo(expectedP return } - currentProbe := r.kubegresResource.Spec.ReadinessProbe + currentProbe := r.kubegresResource.Spec.Probe.ReadinessProbe Expect(currentProbe).Should(Equal(expectedProbe)) }