Skip to content

Commit 4e48108

Browse files
shubham-cmykdrivebyerwilsonwu
authored
[Feature] : Add support for multiple versions (#592)
* Add : v1beta2 from the current version Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com> * Add : kubebuilder storage tag Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com> * fix : PROJECT Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com> * getRedisReplicationMasterIP according to v1beta2 Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com> * update : crds Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com> * fix: /config/samples/ Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com> * apis redis rediscluster redisreplication, sentinel Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com> * Add: rbac tags in rbac.go Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com> * Add : scaffhold webhook and conversion files Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com> * Add and Fix : common.go for common fields Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com> * Add : redis_conversion.go Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com> * fix: minor bugs in redis conversion Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com> * Add : Redis cluster conversion Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com> * Fix : bugs for the redis cluster conversion Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com> * Add : redisreplication conversion Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com> * fix : redis standlone Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com> * Add : sentinel conversion Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com> * Add : deepcopy Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com> * Auto recreate redis replication statefulset when update failed (#586) Signed-off-by: drivebyer <wuyangmuc@gmail.com> * Add redis replication yaml example (#587) Signed-off-by: drivebyer <yang.wu@daocloud.io> * [Add] : Write the docs for the restore and backup (#588) * Write the docs for the restore and backup Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com> * add Prerequisites Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com> * typo Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com> --------- Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com> * [Enhancement]- Fix log pollution (#585) * Add param to set operator log verbosity Signed-off-by: drivebyer <wuyangmuc@gmail.com> * Level down some logger Signed-off-by: drivebyer <wuyangmuc@gmail.com> * Remove unnecessary flag, `opts.BindFlags(flag.CommandLine)` already add flag `zap-log-level` Signed-off-by: drivebyer <yang.wu@daocloud.io> * Level up every info, not logger Signed-off-by: drivebyer <wuyangmuc@gmail.com> --------- Signed-off-by: drivebyer <wuyangmuc@gmail.com> Signed-off-by: drivebyer <yang.wu@daocloud.io> * [Add]- Support redis sentinel pdb (#589) * Support redis sentinel pdb Signed-off-by: drivebyer <yang.wu@daocloud.io> * Adjust example minAvailable Signed-off-by: drivebyer <yang.wu@daocloud.io> --------- Signed-off-by: drivebyer <yang.wu@daocloud.io> * Fix image path (#591) Signed-off-by: Wilson Wu <iwilsonwu@gmail.com> * Fix: bugs sentinel Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com> * fix : pretty Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com> * convert i to index Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com> * remove index Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com> --------- Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com> Signed-off-by: drivebyer <wuyangmuc@gmail.com> Signed-off-by: drivebyer <yang.wu@daocloud.io> Signed-off-by: Wilson Wu <iwilsonwu@gmail.com> Co-authored-by: Yang Wu <wuyangmuc@gmail.com> Co-authored-by: Yang Wu <yang.wu@daocloud.io> Co-authored-by: Wilson Wu <iwilsonwu@gmail.com>
1 parent 6b03437 commit 4e48108

File tree

71 files changed

+16929
-833
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+16929
-833
lines changed

PROJECT

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Code generated by tool. DO NOT EDIT.
2+
# This file is used to track the info used to scaffold your project
3+
# and allow the plugins properly work.
4+
# More info: https://book.kubebuilder.io/reference/project-config.html
15
domain: redis.opstreelabs.in
26
layout:
37
- go.kubebuilder.io/v3
@@ -13,15 +17,75 @@ resources:
1317
domain: redis.opstreelabs.in
1418
group: redis
1519
kind: Redis
20+
path: redis-operator/api/v1beta2
21+
version: v1beta2
22+
webhooks:
23+
conversion: true
24+
webhookVersion: v1
25+
- api:
26+
crdVersion: v1
27+
namespaced: true
28+
controller: true
29+
domain: redis.opstreelabs.in
30+
group: redis
31+
kind: RedisCluster
32+
path: redis-operator/api/v1beta2
33+
version: v1beta2
34+
webhooks:
35+
conversion: true
36+
webhookVersion: v1
37+
- api:
38+
crdVersion: v1
39+
controller: true
40+
domain: redis.opstreelabs.in
41+
group: redis
42+
kind: RedisReplication
43+
path: redis-operator/api/v1beta2
44+
version: v1beta2
45+
webhooks:
46+
conversion: true
47+
webhookVersion: v1
48+
- api:
49+
crdVersion: v1
50+
controller: true
51+
domain: redis.opstreelabs.in
52+
group: redis
53+
kind: RedisSentinel
54+
path: redis-operator/api/v1beta2
55+
version: v1beta2
56+
webhooks:
57+
conversion: true
58+
webhookVersion: v1
59+
- api:
60+
crdVersion: v1
61+
namespaced: true
62+
domain: redis.opstreelabs.in
63+
group: redis
64+
kind: Redis
1665
path: redis-operator/api/v1beta1
1766
version: v1beta1
1867
- api:
1968
crdVersion: v1
2069
namespaced: true
21-
controller: true
2270
domain: redis.opstreelabs.in
2371
group: redis
2472
kind: RedisCluster
2573
path: redis-operator/api/v1beta1
2674
version: v1beta1
75+
- api:
76+
crdVersion: v1
77+
namespaced: true
78+
domain: redis.opstreelabs.in
79+
group: redis
80+
kind: RedisReplication
81+
path: redis-operator/api/v1beta1
82+
version: v1beta1
83+
- api:
84+
crdVersion: v1
85+
namespaced: true
86+
domain: redis.opstreelabs.in
87+
group: redis
88+
kind: RedisSentinel
89+
path: redis-operator/api/v1beta1
90+
version: v1beta1
2791
version: "3"

api/common_types.go

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
package api
2+
3+
import (
4+
appsv1 "k8s.io/api/apps/v1"
5+
corev1 "k8s.io/api/core/v1"
6+
)
7+
8+
// KubernetesConfig will be the JSON struct for Basic Redis Config
9+
// +k8s:deepcopy-gen=true
10+
type KubernetesConfig struct {
11+
Image string `json:"image"`
12+
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
13+
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
14+
ExistingPasswordSecret *ExistingPasswordSecret `json:"redisSecret,omitempty"`
15+
ImagePullSecrets *[]corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
16+
UpdateStrategy appsv1.StatefulSetUpdateStrategy `json:"updateStrategy,omitempty"`
17+
Service *ServiceConfig `json:"service,omitempty"`
18+
}
19+
20+
// ServiceConfig define the type of service to be created and its annotations
21+
// +k8s:deepcopy-gen=true
22+
type ServiceConfig struct {
23+
// +kubebuilder:validation:Enum=LoadBalancer;NodePort;ClusterIP
24+
ServiceType string `json:"serviceType,omitempty"`
25+
ServiceAnnotations map[string]string `json:"annotations,omitempty"`
26+
}
27+
28+
// ExistingPasswordSecret is the struct to access the existing secret
29+
// +k8s:deepcopy-gen=true
30+
type ExistingPasswordSecret struct {
31+
Name *string `json:"name,omitempty"`
32+
Key *string `json:"key,omitempty"`
33+
}
34+
35+
// RedisExporter interface will have the information for redis exporter related stuff
36+
// +k8s:deepcopy-gen=true
37+
type RedisExporter struct {
38+
Enabled bool `json:"enabled,omitempty"`
39+
Image string `json:"image"`
40+
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
41+
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
42+
EnvVars *[]corev1.EnvVar `json:"env,omitempty"`
43+
}
44+
45+
// RedisConfig defines the external configuration of Redis
46+
// +k8s:deepcopy-gen=true
47+
type RedisConfig struct {
48+
AdditionalRedisConfig *string `json:"additionalRedisConfig,omitempty"`
49+
}
50+
51+
// Storage is the inteface to add pvc and pv support in redis
52+
// +k8s:deepcopy-gen=true
53+
type Storage struct {
54+
VolumeClaimTemplate corev1.PersistentVolumeClaim `json:"volumeClaimTemplate,omitempty"`
55+
VolumeMount AdditionalVolume `json:"volumeMount,omitempty"`
56+
}
57+
58+
// Additional Volume is provided by user that is mounted on the pods
59+
// +k8s:deepcopy-gen=true
60+
type AdditionalVolume struct {
61+
Volume []corev1.Volume `json:"volume,omitempty"`
62+
MountPath []corev1.VolumeMount `json:"mountPath,omitempty"`
63+
}
64+
65+
// TLS Configuration for redis instances
66+
// +k8s:deepcopy-gen=true
67+
type TLSConfig struct {
68+
CaKeyFile string `json:"ca,omitempty"`
69+
CertKeyFile string `json:"cert,omitempty"`
70+
KeyFile string `json:"key,omitempty"`
71+
// Reference to secret which contains the certificates
72+
Secret corev1.SecretVolumeSource `json:"secret"`
73+
}
74+
75+
// Probe is a interface for ReadinessProbe and LivenessProbe
76+
// +k8s:deepcopy-gen=true
77+
type Probe struct {
78+
// +kubebuilder:validation:Minimum=1
79+
// +kubebuilder:default=1
80+
InitialDelaySeconds int32 `json:"initialDelaySeconds,omitempty" protobuf:"varint,2,opt,name=initialDelaySeconds"`
81+
// +kubebuilder:validation:Minimum=1
82+
// +kubebuilder:default=1
83+
TimeoutSeconds int32 `json:"timeoutSeconds,omitempty" protobuf:"varint,3,opt,name=timeoutSeconds"`
84+
// +kubebuilder:validation:Minimum=1
85+
// +kubebuilder:default=10
86+
PeriodSeconds int32 `json:"periodSeconds,omitempty" protobuf:"varint,4,opt,name=periodSeconds"`
87+
// +kubebuilder:validation:Minimum=1
88+
// +kubebuilder:default=1
89+
SuccessThreshold int32 `json:"successThreshold,omitempty" protobuf:"varint,5,opt,name=successThreshold"`
90+
// +kubebuilder:validation:Minimum=1
91+
// +kubebuilder:default=3
92+
FailureThreshold int32 `json:"failureThreshold,omitempty" protobuf:"varint,6,opt,name=failureThreshold"`
93+
}
94+
95+
// Sidecar for each Redis pods
96+
// +k8s:deepcopy-gen=true
97+
type Sidecar struct {
98+
Name string `json:"name"`
99+
Image string `json:"image"`
100+
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
101+
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
102+
EnvVars *[]corev1.EnvVar `json:"env,omitempty"`
103+
}
104+
105+
// RedisLeader interface will have the redis leader configuration
106+
// +k8s:deepcopy-gen=true
107+
type RedisLeader struct {
108+
Replicas *int32 `json:"replicas,omitempty"`
109+
RedisConfig *RedisConfig `json:"redisConfig,omitempty"`
110+
Affinity *corev1.Affinity `json:"affinity,omitempty"`
111+
PodDisruptionBudget *RedisPodDisruptionBudget `json:"pdb,omitempty"`
112+
// +kubebuilder:default:={initialDelaySeconds: 1, timeoutSeconds: 1, periodSeconds: 10, successThreshold: 1, failureThreshold:3}
113+
ReadinessProbe *Probe `json:"readinessProbe,omitempty" protobuf:"bytes,11,opt,name=readinessProbe"`
114+
// +kubebuilder:default:={initialDelaySeconds: 1, timeoutSeconds: 1, periodSeconds: 10, successThreshold: 1, failureThreshold:3}
115+
LivenessProbe *Probe `json:"livenessProbe,omitempty" protobuf:"bytes,11,opt,name=livenessProbe"`
116+
Tolerations *[]corev1.Toleration `json:"tolerations,omitempty"`
117+
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
118+
}
119+
120+
// RedisFollower interface will have the redis follower configuration
121+
// +k8s:deepcopy-gen=true
122+
type RedisFollower struct {
123+
Replicas *int32 `json:"replicas,omitempty"`
124+
RedisConfig *RedisConfig `json:"redisConfig,omitempty"`
125+
Affinity *corev1.Affinity `json:"affinity,omitempty"`
126+
PodDisruptionBudget *RedisPodDisruptionBudget `json:"pdb,omitempty"`
127+
// +kubebuilder:default:={initialDelaySeconds: 1, timeoutSeconds: 1, periodSeconds: 10, successThreshold: 1, failureThreshold:3}
128+
ReadinessProbe *Probe `json:"readinessProbe,omitempty" protobuf:"bytes,11,opt,name=readinessProbe"`
129+
// +kubebuilder:default:={initialDelaySeconds: 1, timeoutSeconds: 1, periodSeconds: 10, successThreshold: 1, failureThreshold:3}
130+
LivenessProbe *Probe `json:"livenessProbe,omitempty" protobuf:"bytes,11,opt,name=livenessProbe"`
131+
Tolerations *[]corev1.Toleration `json:"tolerations,omitempty"`
132+
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
133+
}
134+
135+
// RedisPodDisruptionBudget configure a PodDisruptionBudget on the resource (leader/follower)
136+
// +k8s:deepcopy-gen=true
137+
type RedisPodDisruptionBudget struct {
138+
Enabled bool `json:"enabled,omitempty"`
139+
MinAvailable *int32 `json:"minAvailable,omitempty"`
140+
MaxUnavailable *int32 `json:"maxUnavailable,omitempty"`
141+
}
142+
143+
// +k8s:deepcopy-gen=true
144+
type RedisSentinelConfig struct {
145+
AdditionalSentinelConfig *string `json:"additionalSentinelConfig,omitempty"`
146+
RedisReplicationName string `json:"redisReplicationName"`
147+
// +kubebuilder:default:=myMaster
148+
MasterGroupName string `json:"masterGroupName,omitempty"`
149+
// +kubebuilder:default:="6379"
150+
RedisPort string `json:"redisPort,omitempty"`
151+
// +kubebuilder:default:="2"
152+
Quorum string `json:"quorum,omitempty"`
153+
// +kubebuilder:default:="1"
154+
ParallelSyncs string `json:"parallelSyncs,omitempty"`
155+
// +kubebuilder:default:="180000"
156+
FailoverTimeout string `json:"failoverTimeout,omitempty"`
157+
// +kubebuilder:default:="30000"
158+
DownAfterMilliseconds string `json:"downAfterMilliseconds,omitempty"`
159+
}

api/v1beta1/common_types.go

Lines changed: 8 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,12 @@ limitations under the License.
1717
package v1beta1
1818

1919
import (
20-
appsv1 "k8s.io/api/apps/v1"
21-
corev1 "k8s.io/api/core/v1"
20+
common "github.com/OT-CONTAINER-KIT/redis-operator/api"
2221
)
2322

2423
// KubernetesConfig will be the JSON struct for Basic Redis Config
2524
type KubernetesConfig struct {
26-
Image string `json:"image"`
27-
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
28-
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
29-
ExistingPasswordSecret *ExistingPasswordSecret `json:"redisSecret,omitempty"`
30-
ImagePullSecrets *[]corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
31-
UpdateStrategy appsv1.StatefulSetUpdateStrategy `json:"updateStrategy,omitempty"`
32-
Service *ServiceConfig `json:"service,omitempty"`
25+
common.KubernetesConfig `json:",inline"`
3326
}
3427

3528
// ServiceConfig define the type of service to be created and its annotations
@@ -41,7 +34,7 @@ type ServiceConfig struct {
4134

4235
// RedisConfig defines the external configuration of Redis
4336
type RedisConfig struct {
44-
AdditionalRedisConfig *string `json:"additionalRedisConfig,omitempty"`
37+
common.RedisConfig `json:",inline"`
4538
}
4639

4740
// ExistingPasswordSecret is the struct to access the existing secret
@@ -52,83 +45,25 @@ type ExistingPasswordSecret struct {
5245

5346
// Storage is the inteface to add pvc and pv support in redis
5447
type Storage struct {
55-
VolumeClaimTemplate corev1.PersistentVolumeClaim `json:"volumeClaimTemplate,omitempty"`
56-
VolumeMount AdditionalVolume `json:"volumeMount,omitempty"`
57-
}
58-
59-
// Node-conf needs to be added only in redis cluster
60-
type ClusterStorage struct {
61-
VolumeClaimTemplate corev1.PersistentVolumeClaim `json:"volumeClaimTemplate,omitempty"`
62-
NodeConfVolumeClaimTemplate corev1.PersistentVolumeClaim `json:"nodeConfVolumeClaimTemplate,omitempty"`
63-
VolumeMount AdditionalVolume `json:"volumeMount,omitempty"`
64-
}
65-
66-
// Additional Volume is provided by user that is mounted on the pods
67-
type AdditionalVolume struct {
68-
Volume []corev1.Volume `json:"volume,omitempty"`
69-
MountPath []corev1.VolumeMount `json:"mountPath,omitempty"`
48+
CommonAttributes common.Storage `json:",inline"`
7049
}
7150

7251
// RedisExporter interface will have the information for redis exporter related stuff
7352
type RedisExporter struct {
74-
Enabled bool `json:"enabled,omitempty"`
75-
Image string `json:"image"`
76-
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
77-
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
78-
EnvVars *[]corev1.EnvVar `json:"env,omitempty"`
53+
common.RedisExporter `json:",inline"`
7954
}
8055

8156
// TLS Configuration for redis instances
8257
type TLSConfig struct {
83-
CaKeyFile string `json:"ca,omitempty"`
84-
CertKeyFile string `json:"cert,omitempty"`
85-
KeyFile string `json:"key,omitempty"`
86-
// Reference to secret which contains the certificates
87-
Secret corev1.SecretVolumeSource `json:"secret"`
88-
}
89-
90-
type ACLConfig struct {
91-
Secret *corev1.SecretVolumeSource `json:"secret,omitempty"`
58+
common.TLSConfig `json:",inline"`
9259
}
9360

9461
// Probe is a interface for ReadinessProbe and LivenessProbe
9562
type Probe struct {
96-
// +kubebuilder:validation:Minimum=1
97-
// +kubebuilder:default=1
98-
InitialDelaySeconds int32 `json:"initialDelaySeconds,omitempty" protobuf:"varint,2,opt,name=initialDelaySeconds"`
99-
// +kubebuilder:validation:Minimum=1
100-
// +kubebuilder:default=1
101-
TimeoutSeconds int32 `json:"timeoutSeconds,omitempty" protobuf:"varint,3,opt,name=timeoutSeconds"`
102-
// +kubebuilder:validation:Minimum=1
103-
// +kubebuilder:default=10
104-
PeriodSeconds int32 `json:"periodSeconds,omitempty" protobuf:"varint,4,opt,name=periodSeconds"`
105-
// +kubebuilder:validation:Minimum=1
106-
// +kubebuilder:default=1
107-
SuccessThreshold int32 `json:"successThreshold,omitempty" protobuf:"varint,5,opt,name=successThreshold"`
108-
// +kubebuilder:validation:Minimum=1
109-
// +kubebuilder:default=3
110-
FailureThreshold int32 `json:"failureThreshold,omitempty" protobuf:"varint,6,opt,name=failureThreshold"`
63+
common.Probe `json:",inline"`
11164
}
11265

11366
// Sidecar for each Redis pods
11467
type Sidecar struct {
115-
Name string `json:"name"`
116-
Image string `json:"image"`
117-
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
118-
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
119-
EnvVars *[]corev1.EnvVar `json:"env,omitempty"`
120-
Volumes *[]corev1.VolumeMount `json:"mountPath,omitempty"`
121-
Command []string `json:"command,omitempty" protobuf:"bytes,3,rep,name=command"`
122-
Ports *[]corev1.ContainerPort `json:"ports,omitempty" patchStrategy:"merge" patchMergeKey:"containerPort" protobuf:"bytes,6,rep,name=ports"`
123-
}
124-
125-
// InitContainer for each Redis pods
126-
type InitContainer struct {
127-
Enabled *bool `json:"enabled,omitempty"`
128-
Image string `json:"image"`
129-
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
130-
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
131-
EnvVars *[]corev1.EnvVar `json:"env,omitempty"`
132-
Command []string `json:"command,omitempty"`
133-
Args []string `json:"args,omitempty"`
68+
common.Sidecar `json:",inline"`
13469
}

0 commit comments

Comments
 (0)