Skip to content

Commit

Permalink
Merge pull request #14 from OT-CONTAINER-KIT/0.2
Browse files Browse the repository at this point in the history
[Development][Update] Updated redis exporter and redis definitions and fixed failover issue
  • Loading branch information
iamabhishek-dubey authored Jul 31, 2020
2 parents a8dd6cd + 3e6a77d commit a7ee6c7
Show file tree
Hide file tree
Showing 13 changed files with 386 additions and 132 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ vet:
VET_OUTPUT="$(shell go list ./...)"; GO111MODULE=on go vet $$VET_OUTPUT

build-image:
docker build -t quay.io/opstree/redis-operator:latest -f build/Dockerfile .
docker build -t quay.io/opstree/redis-operator:v0.2 -f build/Dockerfile .
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,9 @@ Please see our [GETTING_STARTED.md](./GETTING_STARTED.md) for details.
- Add unit test cases
- Logging needs to be structured
- Fix permissions in role and rolebindings
- Add resources in redis exporter
- Add service type option
- Structure yaml file
- Add YAML validation
- Add docs for different scenarios
- Update helm chart with all the latest information
7 changes: 7 additions & 0 deletions _config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
title: Redis Operator
lang: en-US
description: A golang based Redis Operator


# theme: null # disable pages default theme
remote_theme: rundocs/jekyll-rtd-theme
105 changes: 104 additions & 1 deletion deploy/crds/redis.opstreelabs.in_redis_crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,110 @@ spec:
type: object
spec:
description: RedisSpec defines the desired state of Redis
type: object
# type: object
properties:
mode:
type: string
description: Redis setup mode standalone or cluster
pattern: "cluster|standalone"
size:
type: integer
description: Size of the redis cluster
minimum: 3
global:
properties:
image:
type: string
description: Name of the image for redis
imagePullPolicy:
type: string
description: Image Pull Policy for pulling the images
pattern: "IfNotPresent|Always"
password:
type: string
description: Password of the redis server
resources:
properties:
requests:
properties:
cpu:
type: string
description: CPU request for the redis pods
memory:
type: string
description: Memory request for the redis pods
limits:
properties:
cpu:
type: string
description: CPU limit for the redis pods
memory:
type: string
description: Memory limit for the redis pods
service:
properties:
type:
type: string
description: Service type of redis standalone server
master:
properties:
service:
properties:
type:
type: string
description: Service type of redis standalone server
slave:
properties:
service:
properties:
type:
type: string
description: Service type of redis standalone server
redisExporter:
properties:
enabled:
type: boolean
description: Redis exporter is enabled or not
image:
type: string
description: Name of the image for redis
imagePullPolicy:
type: string
description: Image Pull Policy for pulling the images
pattern: "IfNotPresent|Always"
resources:
properties:
requests:
properties:
cpu:
type: string
description: CPU request for the redis exporter
memory:
type: string
description: Memory request for the redis exporter
limits:
properties:
cpu:
type: string
description: CPU limit for the redis exporter
memory:
type: string
description: Memory limit for the redis exporter
priorityClassName:
type: string
description: Name of the priority class which redis setup should use
storage:
type: object
description: Storage definition of the redis nodes
nodeSelector:
type: object
description: Node selector to determine the pods scheduling nodes
securityContext:
type: object
description: Security context for pods of redis
affinity:
type: object
description: Affinity to control pod scheduling
status:
description: RedisStatus defines the observed state of Redis
type: object
Expand Down
28 changes: 14 additions & 14 deletions deploy/operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ spec:
spec:
serviceAccountName: redis-operator
containers:
- name: redis-operator
image: quay.io/opstree/redis-operator
imagePullPolicy: Always
env:
- name: WATCH_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: OPERATOR_NAME
value: "redis-operator"
- name: redis-operator
image: quay.io/opstree/redis-operator:v0.2
imagePullPolicy: Always
env:
- name: WATCH_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: OPERATOR_NAME
value: "redis-operator"
45 changes: 28 additions & 17 deletions example/redis-cluster-example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,42 @@
apiVersion: redis.opstreelabs.in/v1alpha1
kind: Redis
metadata:
name: opstree-redis
name: redis
spec:
mode: cluster
exporter: true
size: 3
imageName: "quay.io/opstree/redis:2.0"
redisExporterImage: "quay.io/opstree/redis-exporter:1.0"
imagePullPolicy: IfNotPresent
global:
image: opstree/redis:v2.0
imagePullPolicy: IfNotPresent
password: "Opstree@1234"
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 100m
memory: 128Mi
master:
service:
type: ClusterIP
slave:
redisConfig:
timeout: "0"
tcp-keepalive: "300"
redisPassword: "Opstree@12345"
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 100m
memory: 128Mi
service:
type: ClusterIP
redisExporter:
enabled: true
image: quay.io/opstree/redis-exporter:1.0
imagePullPolicy: Always
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 100m
memory: 128Mi
storage:
volumeClaimTemplate:
spec:
storageClassName: standard
storageClassName: csi-cephfs-sc
accessModes: ["ReadWriteOnce"]
resources:
requests:
Expand Down
45 changes: 27 additions & 18 deletions example/redis-standalone-example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,38 @@ metadata:
name: opstree-redis
spec:
mode: standalone
exporter: true
imageName: "quay.io/opstree/redis:2.0"
redisExporterImage: "quay.io/opstree/redis-exporter:1.0"
imagePullPolicy: IfNotPresent
redisConfig:
timeout: "0"
tcp-keepalive: "300"
redisPassword: "Opstree@1234"
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 100m
memory: 128Mi
global:
image: opstree/redis:v2.0
imagePullPolicy: IfNotPresent
password: "Opstree@1234"
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 100m
memory: 128Mi
service:
type: LoadBalancer
redisExporter:
enabled: true
image: quay.io/opstree/redis-exporter:1.0
imagePullPolicy: Always
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 100m
memory: 128Mi
storage:
volumeClaimTemplate:
spec:
storageClassName: standard
storageClassName: csi-cephfs-sc
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 1Gi
selector: {}
nodeSelector:
kubernetes.io/hostname: minikube
# nodeSelector:
# kubernetes.io/hostname: minikube
53 changes: 37 additions & 16 deletions pkg/apis/redis/v1alpha1/redis_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,20 @@ import (

// RedisSpec will define the interface for Redis Configuration Input Values
type RedisSpec struct {
Mode string `json:"mode"`
ImageName string `json:"imageName,omitempty"`
Size *int32 `json:"size,omitempty"`
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
Master RedisMaster `json:"master,omitempty"`
Slave RedisSlave `json:"slave,omitempty"`
RedisPassword *string `json:"redisPassword,omitempty"`
RedisExporter bool `json:"exporter"`
RedisExporterImage string `json:"redisExporterImage"`
RedisConfig map[string]string `json:"redisConfig"`
Resources *Resources `json:"resources,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"`
Mode string `json:"mode"`
Size *int32 `json:"size,omitempty"`
GlobalConfig GlobalConfig `json:"global"`
Service Service `json:"service"`
Master RedisMaster `json:"master,omitempty"`
Slave RedisSlave `json:"slave,omitempty"`
RedisExporter *RedisExporter `json:"redisExporter,omitempty"`
RedisConfig map[string]string `json:"redisConfig"`
Resources *Resources `json:"resources,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"`
}

// Storage is the inteface to add pvc and pv support in redis
Expand All @@ -34,12 +32,30 @@ type Storage struct {
type RedisMaster struct {
Resources Resources `json:"resources,omitempty"`
RedisConfig map[string]string `json:"redisConfig"`
Service Service `json:"service"`
}

// RedisExporter interface will have the information for redis exporter related stuff
type RedisExporter struct {
Enabled bool `json:"enabled,omitempty"`
Image string `json:"image"`
Resources *Resources `json:"resources,omitempty"`
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
}

// GlobalConfig will be the JSON struct for Basic Redis Config
type GlobalConfig struct {
Image string `json:"image"`
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
Password *string `json:"password,omitempty"`
Resources *Resources `json:"resources,omitempty"`
}

// RedisSlave interface will have the redis slave configuration
type RedisSlave struct {
Resources Resources `json:"resources,omitempty"`
RedisConfig map[string]string `json:"redisConfig"`
Service Service `json:"service"`
}

// ResourceDescription describes CPU and memory resources defined for a cluster.
Expand All @@ -48,6 +64,11 @@ type ResourceDescription struct {
Memory string `json:"memory"`
}

// Service is the struct for service definition
type Service struct {
Type string `json:"type"`
}

// Resources describes requests and limits for the cluster resouces.
type Resources struct {
ResourceRequests ResourceDescription `json:"requests,omitempty"`
Expand Down
6 changes: 5 additions & 1 deletion pkg/controller/redis/redis_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ func (r *ReconcileRedis) Reconcile(request reconcile.Request) (reconcile.Result,
found := &appsv1.StatefulSet{}
err = r.client.Get(context.TODO(), types.NamespacedName{Name: instance.Name, Namespace: instance.Namespace}, found)
if err != nil && errors.IsNotFound(err) {
otmachinery.CreateRedisSecret(instance)
if instance.Spec.GlobalConfig.Password != nil {
otmachinery.CreateRedisSecret(instance)
}
if instance.Spec.Mode == "cluster" {
otmachinery.CreateRedisMaster(instance)
otmachinery.CreateMasterService(instance)
Expand All @@ -119,10 +121,12 @@ func (r *ReconcileRedis) Reconcile(request reconcile.Request) (reconcile.Result,
otmachinery.ExecuteRedisReplicationCommand(instance)
} else {
reqLogger.Info("Redis master count is desired")
return reconcile.Result{RequeueAfter: time.Second * 120}, nil
}
} else if instance.Spec.Mode == "standalone" {
otmachinery.CreateRedisStandalone(instance)
otmachinery.CreateStandaloneService(instance)
otmachinery.CreateStandaloneHeadlessService(instance)
}
} else if err != nil {
return reconcile.Result{}, err
Expand Down
Loading

0 comments on commit a7ee6c7

Please sign in to comment.