Browse Source

use EmptyDir if no volume size set

master
Vladimir Smagin 1 month ago
parent
commit
eded64053a
Signed by: Vladimir Smagin <21h@blindage.org> GPG Key ID: 13BCE12E5618F071

+ 33
- 4
README.md View File

@@ -15,13 +15,36 @@ You can find images here https://hub.docker.com/r/iam21h/redis-operator

## Deploy operator

### Namespace-scoped installation

```
kubectl -n operators -f deploy/service_account.yaml
kubectl -n operators -f deploy/role.yaml
kubectl -n operators -f deploy/role_binding.yaml
kubectl -n operators -f deploy/operator.yaml
```

Edit `operator.yaml` to set `WATCH_NAMESPACE`, may be you want set it to namespace of pod:

```
kubectl -f deploy/service_account.yaml
kubectl -f deploy/role.yaml
kubectl -f deploy/role_binding.yaml
kubectl -f deploy/operator.yaml
env:
- name: WATCH_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
```

### Cluster-scoped installation

```
kubectl -f deploy/clusterrole.yaml
kubectl -f deploy/clusterrole_binding.yaml
kubectl -n operators -f deploy/service_account.yaml
kubectl -n operators -f deploy/operator.yaml
```

Edit `clusterrole_binding.yaml`, set namespace for service account.

## Your first Redis deployment

This resource can help you run your first Redis instance
@@ -40,8 +63,14 @@ spec:
haproxyTimeoutServer: 30
haproxyTimeoutClient: 30
haproxyBackendCheckInterval: 1
# set size if you want make persistent volume
persistentVolumeSize: 1Gi
persistentVolumeClass: "gluster"
persistentVolumePurge: true
```

Open file `pkg/apis/blindage/v1alpha1/redis_types.go` to know more about options.

---
Copyright by Vladimir Smagin (21h) 2019
http://blindage.org email: 21h@blindage.org

+ 16
- 12
pkg/apis/blindage/v1alpha1/redis_types.go View File

@@ -9,24 +9,28 @@ import (
// RedisSpec defines the desired state of Redis
// +k8s:openapi-gen=true
type RedisSpec struct {
Image string `json:"image,omitempty"` // default redis:latest
PullPolicy *v1.PullPolicy `json:"pullPolicy,omitempty"` // default "if not exists"
SentinelReplicas *int32 `json:"sentinelReplicas"` // default 3
RedisReplicas *int32 `json:"redisReplicas"` // default 3`
Quorum int32 `json:"quorum"` // default 2`
PersistentVolumeSize resource.Quantity `json:"persistentVolumeSize,omitempty"` // default 1Gi
PersistentVolumeClass string `json:"persistentVolumeClass,omitempty"` // default empty
PersistentVolumePurge bool `json:"persistentVolumePurge,omitempty"` // default false (save PVC afrer CR was deleted)
Image string `json:"image,omitempty"` // default redis:latest
PullPolicy *v1.PullPolicy `json:"pullPolicy,omitempty"` // default "if not exists"
SentinelReplicas *int32 `json:"sentinelReplicas"` // default 3
RedisReplicas *int32 `json:"redisReplicas"` // default 3
Quorum int32 `json:"quorum"` // default 2

// haproxy
// Persistence options
// Set volume size if you want persistence or EmptyDir will be used
PersistentVolumeSize *resource.Quantity `json:"persistentVolumeSize,omitempty"` // default empty
PersistentVolumeClass string `json:"persistentVolumeClass,omitempty"` // default empty
// This option purges PVC afrer CR was deleted. Mostly used for development deployments.
PersistentVolumePurge bool `json:"persistentVolumePurge,omitempty"` // default false

// Haproxy to make Redis more stable when new master elected
UseHAProxy bool `json:"useHAProxy,omitempty"` // set true to activate HAProxy deployment
HAProxyImage string `json:"haproxyImage,omitempty"` // override default haproxy:1.9.4-alpine
HAProxyReplicas *int32 `json:"haproxyReplicas,omitempty"` // override default 1
HAProxyImage string `json:"haproxyImage,omitempty"` // default haproxy:alpine
HAProxyReplicas *int32 `json:"haproxyReplicas,omitempty"` // default 1
HAProxyTimeoutServer int `json:"haproxyTimeoutServer,omitempty"` // default 30 (seconds)
HAProxyTimeoutClient int `json:"haproxyTimeoutClient,omitempty"` // default 30 (seconds)
HAProxyBackendCheckInterval int `json:"haproxyBackendCheckInterval,omitempty"` // default 1 (seconds)

// manage resources for Sentinel and Redis
// Manage resources for Sentinel and Redis, use standart Kubernetes specs, default is empty.
SentinelPodRequests *v1.ResourceList `json:"sentinelPodRequests,omitempty"`
SentinelPodLimits *v1.ResourceList `json:"sentinelPodLimits,omitempty"`
SentinelAffinity *v1.Affinity `json:"sentinelAffinity,omitempty"`

+ 5
- 1
pkg/apis/blindage/v1alpha1/zz_generated.deepcopy.go View File

@@ -89,7 +89,11 @@ func (in *RedisSpec) DeepCopyInto(out *RedisSpec) {
*out = new(int32)
**out = **in
}
out.PersistentVolumeSize = in.PersistentVolumeSize.DeepCopy()
if in.PersistentVolumeSize != nil {
in, out := &in.PersistentVolumeSize, &out.PersistentVolumeSize
x := (*in).DeepCopy()
*out = &x
}
if in.HAProxyReplicas != nil {
in, out := &in.HAProxyReplicas, &out.HAProxyReplicas
*out = new(int32)

+ 1
- 1
pkg/controller/manifests/manifest_haproxy.go View File

@@ -9,7 +9,7 @@ import (
)

func GenerateHaproxyDeployment(cr *blindagev1alpha1.Redis) v1.Deployment {
image := "haproxy:1.9.4-alpine"
image := "haproxy:alpine"
if cr.Spec.HAProxyImage != "" {
image = cr.Spec.Image
}

+ 31
- 20
pkg/controller/manifests/manifest_statefulset.go View File

@@ -140,25 +140,6 @@ func GenerateStatefulSet(cr *blindagev1alpha1.Redis) v1.StatefulSet {
replicas = *cr.Spec.RedisReplicas
}

PVCTemplate := corev1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{
Name: "data",
// Finalizers: cr.ObjectMeta.Finalizers,
},
Spec: corev1.PersistentVolumeClaimSpec{
AccessModes: []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce},
Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceStorage: cr.Spec.PersistentVolumeSize,
},
},
},
}

if cr.Spec.PersistentVolumeClass != "" {
PVCTemplate.Spec.StorageClassName = &cr.Spec.PersistentVolumeClass
}

sts := v1.StatefulSet{
ObjectMeta: metav1.ObjectMeta{
Name: cr.Name + "-redis",
@@ -176,10 +157,40 @@ func GenerateStatefulSet(cr *blindagev1alpha1.Redis) v1.StatefulSet {
UpdateStrategy: v1.StatefulSetUpdateStrategy{
Type: v1.RollingUpdateStatefulSetStrategyType,
},
VolumeClaimTemplates: []corev1.PersistentVolumeClaim{PVCTemplate},
},
}

// if set volume size then create PVC
if cr.Spec.PersistentVolumeSize != nil {
PVCTemplate := corev1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{
Name: "data",
// Finalizers: cr.ObjectMeta.Finalizers,
},
Spec: corev1.PersistentVolumeClaimSpec{
AccessModes: []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce},
Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceStorage: *cr.Spec.PersistentVolumeSize,
},
},
},
}
if cr.Spec.PersistentVolumeClass != "" {
PVCTemplate.Spec.StorageClassName = &cr.Spec.PersistentVolumeClass
}
sts.Spec.VolumeClaimTemplates = []corev1.PersistentVolumeClaim{PVCTemplate}
} else {
// using EmptyDir
volumeData := corev1.Volume{
Name: "data",
VolumeSource: corev1.VolumeSource{
EmptyDir: &corev1.EmptyDirVolumeSource{},
},
}
sts.Spec.Template.Spec.Volumes = append(sts.Spec.Template.Spec.Volumes, volumeData)
}

if cr.Spec.RedisNodeSelector != nil {
sts.Spec.Template.Spec.NodeSelector = *cr.Spec.RedisNodeSelector
}

Loading…
Cancel
Save