Skip to content

Commit

Permalink
add support for configurable probe handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
com6056 committed May 17, 2024
1 parent fae7db7 commit 02a84ba
Show file tree
Hide file tree
Showing 26 changed files with 2,768 additions and 690 deletions.
40 changes: 8 additions & 32 deletions api/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,26 +76,6 @@ type TLSConfig struct {
Secret corev1.SecretVolumeSource `json:"secret"`
}

// Probe is a interface for ReadinessProbe and LivenessProbe
// +k8s:deepcopy-gen=true
type Probe struct {
// +kubebuilder:validation:Minimum=1
// +kubebuilder:default=1
InitialDelaySeconds int32 `json:"initialDelaySeconds,omitempty" protobuf:"varint,2,opt,name=initialDelaySeconds"`
// +kubebuilder:validation:Minimum=1
// +kubebuilder:default=1
TimeoutSeconds int32 `json:"timeoutSeconds,omitempty" protobuf:"varint,3,opt,name=timeoutSeconds"`
// +kubebuilder:validation:Minimum=1
// +kubebuilder:default=10
PeriodSeconds int32 `json:"periodSeconds,omitempty" protobuf:"varint,4,opt,name=periodSeconds"`
// +kubebuilder:validation:Minimum=1
// +kubebuilder:default=1
SuccessThreshold int32 `json:"successThreshold,omitempty" protobuf:"varint,5,opt,name=successThreshold"`
// +kubebuilder:validation:Minimum=1
// +kubebuilder:default=3
FailureThreshold int32 `json:"failureThreshold,omitempty" protobuf:"varint,6,opt,name=failureThreshold"`
}

// Sidecar for each Redis pods
// +k8s:deepcopy-gen=true
type Sidecar struct {
Expand All @@ -113,12 +93,10 @@ type RedisLeader struct {
RedisConfig *RedisConfig `json:"redisConfig,omitempty"`
Affinity *corev1.Affinity `json:"affinity,omitempty"`
PodDisruptionBudget *RedisPodDisruptionBudget `json:"pdb,omitempty"`
// +kubebuilder:default:={initialDelaySeconds: 1, timeoutSeconds: 1, periodSeconds: 10, successThreshold: 1, failureThreshold:3}
ReadinessProbe *Probe `json:"readinessProbe,omitempty" protobuf:"bytes,11,opt,name=readinessProbe"`
// +kubebuilder:default:={initialDelaySeconds: 1, timeoutSeconds: 1, periodSeconds: 10, successThreshold: 1, failureThreshold:3}
LivenessProbe *Probe `json:"livenessProbe,omitempty" protobuf:"bytes,11,opt,name=livenessProbe"`
Tolerations *[]corev1.Toleration `json:"tolerations,omitempty"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
ReadinessProbe *corev1.Probe `json:"readinessProbe,omitempty" protobuf:"bytes,11,opt,name=readinessProbe"`
LivenessProbe *corev1.Probe `json:"livenessProbe,omitempty" protobuf:"bytes,12,opt,name=livenessProbe"`
Tolerations *[]corev1.Toleration `json:"tolerations,omitempty"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
}

// RedisFollower interface will have the redis follower configuration
Expand All @@ -128,12 +106,10 @@ type RedisFollower struct {
RedisConfig *RedisConfig `json:"redisConfig,omitempty"`
Affinity *corev1.Affinity `json:"affinity,omitempty"`
PodDisruptionBudget *RedisPodDisruptionBudget `json:"pdb,omitempty"`
// +kubebuilder:default:={initialDelaySeconds: 1, timeoutSeconds: 1, periodSeconds: 10, successThreshold: 1, failureThreshold:3}
ReadinessProbe *Probe `json:"readinessProbe,omitempty" protobuf:"bytes,11,opt,name=readinessProbe"`
// +kubebuilder:default:={initialDelaySeconds: 1, timeoutSeconds: 1, periodSeconds: 10, successThreshold: 1, failureThreshold:3}
LivenessProbe *Probe `json:"livenessProbe,omitempty" protobuf:"bytes,11,opt,name=livenessProbe"`
Tolerations *[]corev1.Toleration `json:"tolerations,omitempty"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
ReadinessProbe *corev1.Probe `json:"readinessProbe,omitempty" protobuf:"bytes,11,opt,name=readinessProbe"`
LivenessProbe *corev1.Probe `json:"livenessProbe,omitempty" protobuf:"bytes,12,opt,name=livenessProbe"`
Tolerations *[]corev1.Toleration `json:"tolerations,omitempty"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
}

// RedisPodDisruptionBudget configure a PodDisruptionBudget on the resource (leader/follower)
Expand Down
5 changes: 0 additions & 5 deletions api/v1beta1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,6 @@ type TLSConfig struct {
common.TLSConfig `json:",inline"`
}

// Probe is a interface for ReadinessProbe and LivenessProbe
type Probe struct {
common.Probe `json:",inline"`
}

// Sidecar for each Redis pods
type Sidecar struct {
common.Sidecar `json:",inline"`
Expand Down
17 changes: 9 additions & 8 deletions api/v1beta1/redis_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v1beta1

import (
redisv1beta2 "github.com/OT-CONTAINER-KIT/redis-operator/api/v1beta2"
corev1 "k8s.io/api/core/v1"
"sigs.k8s.io/controller-runtime/pkg/conversion"
)

Expand Down Expand Up @@ -60,13 +61,13 @@ func (src *Redis) ConvertTo(dstRaw conversion.Hub) error {
}
// ReadinessProbe
if src.Spec.ReadinessProbe != nil {
dst.Spec.ReadinessProbe = &redisv1beta2.Probe{}
dst.Spec.ReadinessProbe.Probe = src.Spec.ReadinessProbe.Probe
dst.Spec.ReadinessProbe = &corev1.Probe{}
dst.Spec.ReadinessProbe = src.Spec.ReadinessProbe
}
// LivenessProbe
if src.Spec.LivenessProbe != nil {
dst.Spec.LivenessProbe = &redisv1beta2.Probe{}
dst.Spec.LivenessProbe.Probe = src.Spec.LivenessProbe.Probe
dst.Spec.LivenessProbe = &corev1.Probe{}
dst.Spec.LivenessProbe = src.Spec.LivenessProbe
}
// Sidecars
if src.Spec.Sidecars != nil {
Expand Down Expand Up @@ -141,13 +142,13 @@ func (dst *Redis) ConvertFrom(srcRaw conversion.Hub) error {
}
// ReadinessProbe
if src.Spec.ReadinessProbe != nil {
dst.Spec.ReadinessProbe = &Probe{}
dst.Spec.ReadinessProbe.Probe = src.Spec.ReadinessProbe.Probe
dst.Spec.ReadinessProbe = &corev1.Probe{}
dst.Spec.ReadinessProbe = src.Spec.ReadinessProbe
}
// LivenessProbe
if src.Spec.LivenessProbe != nil {
dst.Spec.LivenessProbe = &Probe{}
dst.Spec.LivenessProbe.Probe = src.Spec.LivenessProbe.Probe
dst.Spec.LivenessProbe = &corev1.Probe{}
dst.Spec.LivenessProbe = src.Spec.LivenessProbe
}
// Sidecars
if src.Spec.Sidecars != nil {
Expand Down
30 changes: 14 additions & 16 deletions api/v1beta1/redis_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,20 @@ import (

// RedisSpec defines the desired state of Redis
type RedisSpec struct {
KubernetesConfig KubernetesConfig `json:"kubernetesConfig"`
RedisExporter *RedisExporter `json:"redisExporter,omitempty"`
RedisConfig *RedisConfig `json:"redisConfig,omitempty"`
Storage *Storage `json:"storage,omitempty"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
SecurityContext *corev1.PodSecurityContext `json:"securityContext,omitempty"`
PriorityClassName string `json:"priorityClassName,omitempty"`
Affinity *corev1.Affinity `json:"affinity,omitempty"`
Tolerations *[]corev1.Toleration `json:"tolerations,omitempty"`
TLS *TLSConfig `json:"TLS,omitempty"`
// +kubebuilder:default:={initialDelaySeconds: 1, timeoutSeconds: 1, periodSeconds: 10, successThreshold: 1, failureThreshold:3}
ReadinessProbe *Probe `json:"readinessProbe,omitempty" protobuf:"bytes,11,opt,name=readinessProbe"`
// +kubebuilder:default:={initialDelaySeconds: 1, timeoutSeconds: 1, periodSeconds: 10, successThreshold: 1, failureThreshold:3}
LivenessProbe *Probe `json:"livenessProbe,omitempty" protobuf:"bytes,11,opt,name=livenessProbe"`
Sidecars *[]Sidecar `json:"sidecars,omitempty"`
ServiceAccountName *string `json:"serviceAccountName,omitempty"`
KubernetesConfig KubernetesConfig `json:"kubernetesConfig"`
RedisExporter *RedisExporter `json:"redisExporter,omitempty"`
RedisConfig *RedisConfig `json:"redisConfig,omitempty"`
Storage *Storage `json:"storage,omitempty"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
SecurityContext *corev1.PodSecurityContext `json:"securityContext,omitempty"`
PriorityClassName string `json:"priorityClassName,omitempty"`
Affinity *corev1.Affinity `json:"affinity,omitempty"`
Tolerations *[]corev1.Toleration `json:"tolerations,omitempty"`
TLS *TLSConfig `json:"TLS,omitempty"`
ReadinessProbe *corev1.Probe `json:"readinessProbe,omitempty" protobuf:"bytes,11,opt,name=readinessProbe"`
LivenessProbe *corev1.Probe `json:"livenessProbe,omitempty" protobuf:"bytes,12,opt,name=livenessProbe"`
Sidecars *[]Sidecar `json:"sidecars,omitempty"`
ServiceAccountName *string `json:"serviceAccountName,omitempty"`
}

// RedisStatus defines the observed state of Redis
Expand Down
6 changes: 2 additions & 4 deletions api/v1beta1/rediscluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ type RedisClusterSpec struct {
Size *int32 `json:"clusterSize"`
KubernetesConfig KubernetesConfig `json:"kubernetesConfig"`
// +kubebuilder:default:=v7
ClusterVersion *string `json:"clusterVersion,omitempty"`
// +kubebuilder:default:={livenessProbe:{initialDelaySeconds: 1, timeoutSeconds: 1, periodSeconds: 10, successThreshold: 1, failureThreshold:3}, readinessProbe:{initialDelaySeconds: 1, timeoutSeconds: 1, periodSeconds: 10, successThreshold: 1, failureThreshold:3}}
RedisLeader RedisLeader `json:"redisLeader,omitempty"`
// +kubebuilder:default:={livenessProbe:{initialDelaySeconds: 1, timeoutSeconds: 1, periodSeconds: 10, successThreshold: 1, failureThreshold:3}, readinessProbe:{initialDelaySeconds: 1, timeoutSeconds: 1, periodSeconds: 10, successThreshold: 1, failureThreshold:3}}
ClusterVersion *string `json:"clusterVersion,omitempty"`
RedisLeader RedisLeader `json:"redisLeader,omitempty"`
RedisFollower RedisFollower `json:"redisFollower,omitempty"`
RedisExporter *RedisExporter `json:"redisExporter,omitempty"`
Storage *Storage `json:"storage,omitempty"`
Expand Down
17 changes: 9 additions & 8 deletions api/v1beta1/redisreplication_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v1beta1

import (
redisv1beta2 "github.com/OT-CONTAINER-KIT/redis-operator/api/v1beta2"
corev1 "k8s.io/api/core/v1"
"sigs.k8s.io/controller-runtime/pkg/conversion"
)

Expand Down Expand Up @@ -59,13 +60,13 @@ func (src *RedisReplication) ConvertTo(dstRaw conversion.Hub) error {
}
// ReadinessProbe
if src.Spec.ReadinessProbe != nil {
dst.Spec.ReadinessProbe = &redisv1beta2.Probe{}
dst.Spec.ReadinessProbe.Probe = src.Spec.ReadinessProbe.Probe
dst.Spec.ReadinessProbe = &corev1.Probe{}
dst.Spec.ReadinessProbe = src.Spec.ReadinessProbe
}
// LivenessProbe
if src.Spec.LivenessProbe != nil {
dst.Spec.LivenessProbe = &redisv1beta2.Probe{}
dst.Spec.LivenessProbe.Probe = src.Spec.LivenessProbe.Probe
dst.Spec.LivenessProbe = &corev1.Probe{}
dst.Spec.LivenessProbe = src.Spec.LivenessProbe
}
// Sidecars
if src.Spec.Sidecars != nil {
Expand Down Expand Up @@ -138,13 +139,13 @@ func (dst *RedisReplication) ConvertFrom(srcRaw conversion.Hub) error {
}
// ReadinessProbe
if src.Spec.ReadinessProbe != nil {
dst.Spec.ReadinessProbe = &Probe{}
dst.Spec.ReadinessProbe.Probe = src.Spec.ReadinessProbe.Probe
dst.Spec.ReadinessProbe = &corev1.Probe{}
dst.Spec.ReadinessProbe = src.Spec.ReadinessProbe
}
// LivenessProbe
if src.Spec.LivenessProbe != nil {
dst.Spec.ReadinessProbe = &Probe{}
dst.Spec.LivenessProbe.Probe = src.Spec.LivenessProbe.Probe
dst.Spec.ReadinessProbe = &corev1.Probe{}
dst.Spec.LivenessProbe = src.Spec.LivenessProbe
}
// Sidecars
if src.Spec.Sidecars != nil {
Expand Down
32 changes: 15 additions & 17 deletions api/v1beta1/redisreplication_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,21 @@ import (
)

type RedisReplicationSpec struct {
Size *int32 `json:"clusterSize"`
KubernetesConfig KubernetesConfig `json:"kubernetesConfig"`
RedisExporter *RedisExporter `json:"redisExporter,omitempty"`
RedisConfig *RedisConfig `json:"redisConfig,omitempty"`
Storage *Storage `json:"storage,omitempty"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
SecurityContext *corev1.PodSecurityContext `json:"securityContext,omitempty"`
PriorityClassName string `json:"priorityClassName,omitempty"`
Affinity *corev1.Affinity `json:"affinity,omitempty"`
Tolerations *[]corev1.Toleration `json:"tolerations,omitempty"`
TLS *TLSConfig `json:"TLS,omitempty"`
// +kubebuilder:default:={initialDelaySeconds: 1, timeoutSeconds: 1, periodSeconds: 10, successThreshold: 1, failureThreshold:3}
ReadinessProbe *Probe `json:"readinessProbe,omitempty" protobuf:"bytes,11,opt,name=readinessProbe"`
// +kubebuilder:default:={initialDelaySeconds: 1, timeoutSeconds: 1, periodSeconds: 10, successThreshold: 1, failureThreshold:3}
LivenessProbe *Probe `json:"livenessProbe,omitempty" protobuf:"bytes,11,opt,name=livenessProbe"`
Sidecars *[]Sidecar `json:"sidecars,omitempty"`
ServiceAccountName *string `json:"serviceAccountName,omitempty"`
Size *int32 `json:"clusterSize"`
KubernetesConfig KubernetesConfig `json:"kubernetesConfig"`
RedisExporter *RedisExporter `json:"redisExporter,omitempty"`
RedisConfig *RedisConfig `json:"redisConfig,omitempty"`
Storage *Storage `json:"storage,omitempty"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
SecurityContext *corev1.PodSecurityContext `json:"securityContext,omitempty"`
PriorityClassName string `json:"priorityClassName,omitempty"`
Affinity *corev1.Affinity `json:"affinity,omitempty"`
Tolerations *[]corev1.Toleration `json:"tolerations,omitempty"`
TLS *TLSConfig `json:"TLS,omitempty"`
ReadinessProbe *corev1.Probe `json:"readinessProbe,omitempty" protobuf:"bytes,11,opt,name=readinessProbe"`
LivenessProbe *corev1.Probe `json:"livenessProbe,omitempty" protobuf:"bytes,12,opt,name=livenessProbe"`
Sidecars *[]Sidecar `json:"sidecars,omitempty"`
ServiceAccountName *string `json:"serviceAccountName,omitempty"`
}

func (cr *RedisReplicationSpec) GetReplicationCounts(t string) int32 {
Expand Down
17 changes: 9 additions & 8 deletions api/v1beta1/redissentinel_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v1beta1

import (
redisv1beta2 "github.com/OT-CONTAINER-KIT/redis-operator/api/v1beta2"
corev1 "k8s.io/api/core/v1"
"sigs.k8s.io/controller-runtime/pkg/conversion"
)

Expand Down Expand Up @@ -48,13 +49,13 @@ func (src *RedisSentinel) ConvertTo(dstRaw conversion.Hub) error {
}
// ReadinessProbe
if src.Spec.ReadinessProbe != nil {
dst.Spec.ReadinessProbe = &redisv1beta2.Probe{}
dst.Spec.ReadinessProbe.Probe = src.Spec.ReadinessProbe.Probe
dst.Spec.ReadinessProbe = &corev1.Probe{}
dst.Spec.ReadinessProbe = src.Spec.ReadinessProbe
}
// LivenessProbe
if src.Spec.LivenessProbe != nil {
dst.Spec.ReadinessProbe = &redisv1beta2.Probe{}
dst.Spec.LivenessProbe.Probe = src.Spec.LivenessProbe.Probe
dst.Spec.LivenessProbe = &corev1.Probe{}
dst.Spec.LivenessProbe = src.Spec.LivenessProbe
}
// Sidecars
if src.Spec.Sidecars != nil {
Expand Down Expand Up @@ -116,13 +117,13 @@ func (dst *RedisSentinel) ConvertFrom(srcRaw conversion.Hub) error {
}
// ReadinessProbe
if src.Spec.ReadinessProbe != nil {
dst.Spec.ReadinessProbe = &Probe{}
dst.Spec.ReadinessProbe.Probe = src.Spec.ReadinessProbe.Probe
dst.Spec.ReadinessProbe = &corev1.Probe{}
dst.Spec.ReadinessProbe = src.Spec.ReadinessProbe
}
// LivenessProbe
if src.Spec.LivenessProbe != nil {
dst.Spec.LivenessProbe = &Probe{}
dst.Spec.LivenessProbe.Probe = src.Spec.LivenessProbe.Probe
dst.Spec.LivenessProbe = &corev1.Probe{}
dst.Spec.LivenessProbe = src.Spec.LivenessProbe
}
// Sidecars
if src.Spec.Sidecars != nil {
Expand Down
10 changes: 4 additions & 6 deletions api/v1beta1/redissentinel_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@ type RedisSentinelSpec struct {
Tolerations *[]corev1.Toleration `json:"tolerations,omitempty"`
TLS *TLSConfig `json:"TLS,omitempty"`
PodDisruptionBudget *common.RedisPodDisruptionBudget `json:"pdb,omitempty"`
// +kubebuilder:default:={initialDelaySeconds: 1, timeoutSeconds: 1, periodSeconds: 10, successThreshold: 1, failureThreshold:3}
ReadinessProbe *Probe `json:"readinessProbe,omitempty" protobuf:"bytes,11,opt,name=readinessProbe"`
// +kubebuilder:default:={initialDelaySeconds: 1, timeoutSeconds: 1, periodSeconds: 10, successThreshold: 1, failureThreshold:3}
LivenessProbe *Probe `json:"livenessProbe,omitempty" protobuf:"bytes,11,opt,name=livenessProbe"`
Sidecars *[]Sidecar `json:"sidecars,omitempty"`
ServiceAccountName *string `json:"serviceAccountName,omitempty"`
ReadinessProbe *corev1.Probe `json:"readinessProbe,omitempty" protobuf:"bytes,11,opt,name=readinessProbe"`
LivenessProbe *corev1.Probe `json:"livenessProbe,omitempty" protobuf:"bytes,12,opt,name=livenessProbe"`
Sidecars *[]Sidecar `json:"sidecars,omitempty"`
ServiceAccountName *string `json:"serviceAccountName,omitempty"`
}

func (cr *RedisSentinelSpec) GetSentinelCounts(t string) int32 {
Expand Down
40 changes: 12 additions & 28 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions api/v1beta2/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,6 @@ type ACLConfig struct {
Secret *corev1.SecretVolumeSource `json:"secret,omitempty"`
}

// Probe is a interface for ReadinessProbe and LivenessProbe
type Probe struct {
common.Probe `json:",inline"`
}

// Sidecar for each Redis pods
type Sidecar struct {
common.Sidecar `json:",inline"`
Expand Down
Loading

0 comments on commit 02a84ba

Please sign in to comment.