Skip to content

Commit

Permalink
feat: add support for extra volume mounts for redis sentinel (#994)
Browse files Browse the repository at this point in the history
* feat: add support for extra volume mounts for redis sentinel

Signed-off-by: laurentiusoica <[email protected]>

* fix: add tests

Signed-off-by: laurentiusoica <[email protected]>

* fix: yaml lint

Signed-off-by: laurentiusoica <[email protected]>

* fix: docs

Signed-off-by: laurentiusoica <[email protected]>

---------

Signed-off-by: laurentiusoica <[email protected]>
Co-authored-by: laurentiusoica <[email protected]>
  • Loading branch information
lsoica and laurentiusoica authored Jun 19, 2024
1 parent 6794133 commit 909d9e4
Show file tree
Hide file tree
Showing 8 changed files with 3,560 additions and 0 deletions.
1 change: 1 addition & 0 deletions api/v1beta2/redissentinel_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type RedisSentinelSpec struct {
ServiceAccountName *string `json:"serviceAccountName,omitempty"`
TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty" protobuf:"varint,4,opt,name=terminationGracePeriodSeconds"`
EnvVars *[]corev1.EnvVar `json:"env,omitempty"`
VolumeMount *common.AdditionalVolume `json:"volumeMount,omitempty"`
}

func (cr *RedisSentinelSpec) GetSentinelCounts(t string) int32 {
Expand Down
5 changes: 5 additions & 0 deletions api/v1beta2/zz_generated.deepcopy.go

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

1,745 changes: 1,745 additions & 0 deletions charts/redis-operator/crds/redis-sentinel.yaml

Large diffs are not rendered by default.

1,745 changes: 1,745 additions & 0 deletions config/crd/bases/redis.redis.opstreelabs.in_redissentinels.yaml

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions docs/content/en/docs/CRD Reference/Redis API/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ _Appears in:_
| `imagePullSecrets` _[LocalObjectReference](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.30/#localobjectreference-v1-core)_ | |
| `updateStrategy` _[StatefulSetUpdateStrategy](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.30/#statefulsetupdatestrategy-v1-apps)_ | |

#### VolumeMount

Mount External Volumes

_Appears in:_

- [RedisSentinel](#redissentinelspec)

| Field | Description |
| --- | --- |
| `volume` _[Volume Array](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.30/#volume-v1-core)_ | |
| `mountPath` _[VolumeMount Array](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.30/#volumemount-v1-core)_ | |

#### Redis

Redis is the Schema for the redis API
Expand Down Expand Up @@ -202,6 +215,7 @@ _Appears in:_
| `livenessProbe` _[Probe](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.30/#probe-v1-core)_ | |
| `sidecars` _[Sidecar](#sidecar)_ | |
| `serviceAccountName` _string_ | |
| `volumeMount` _[VolumeMount](#volumemount)_ | |

#### RedisConfig

Expand Down
8 changes: 8 additions & 0 deletions k8sutils/redis-sentinel.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ func generateRedisSentinelInitContainerParams(cr *redisv1beta2.RedisSentinel) in
Arguments: initContainer.Args,
SecurityContext: initContainer.SecurityContext,
}
if cr.Spec.VolumeMount != nil {
initcontainerProp.AdditionalVolume = cr.Spec.VolumeMount.Volume
initcontainerProp.AdditionalMountPath = cr.Spec.VolumeMount.MountPath
}
}
return initcontainerProp
}
Expand All @@ -153,6 +157,10 @@ func generateRedisSentinelContainerParams(ctx context.Context, client kubernetes
if cr.Spec.EnvVars != nil {
containerProp.EnvVars = cr.Spec.EnvVars
}
if cr.Spec.VolumeMount != nil {
containerProp.AdditionalVolume = cr.Spec.VolumeMount.Volume
containerProp.AdditionalMountPath = cr.Spec.VolumeMount.MountPath
}
if cr.Spec.KubernetesConfig.ExistingPasswordSecret != nil {
containerProp.EnabledPassword = &trueProperty
containerProp.SecretName = cr.Spec.KubernetesConfig.ExistingPasswordSecret.Name
Expand Down
35 changes: 35 additions & 0 deletions k8sutils/redis-sentinel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/go-logr/logr"
"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/yaml"
Expand Down Expand Up @@ -175,6 +176,23 @@ func Test_generateRedisSentinelContainerParams(t *testing.T) {
Value: "custom_value_2",
},
},
AdditionalVolume: []v1.Volume{
{
Name: "redis-config",
VolumeSource: corev1.VolumeSource{
EmptyDir: &v1.EmptyDirVolumeSource{},
},
},
},
AdditionalMountPath: []v1.VolumeMount{
{
Name: "redis-config",
ReadOnly: false,
MountPath: "/etc/redis",
SubPath: "",
SubPathExpr: "",
},
},
}

data, err := os.ReadFile(path)
Expand Down Expand Up @@ -235,6 +253,23 @@ func Test_generateRedisSentinelInitContainerParams(t *testing.T) {
},
},
},
AdditionalVolume: []v1.Volume{
{
Name: "redis-config",
VolumeSource: corev1.VolumeSource{
EmptyDir: &v1.EmptyDirVolumeSource{},
},
},
},
AdditionalMountPath: []v1.VolumeMount{
{
Name: "redis-config",
ReadOnly: false,
MountPath: "/etc/redis",
SubPath: "",
SubPathExpr: "",
},
},
}

data, err := os.ReadFile(path)
Expand Down
7 changes: 7 additions & 0 deletions tests/testdata/redis-sentinel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,10 @@ spec:
secretKeyRef:
name: env-secrets
key: CLUSTER_NAMESPACE
volumeMount:
mountPath:
- mountPath: /etc/redis
name: redis-config
volume:
- emptyDir: {}
name: redis-config

0 comments on commit 909d9e4

Please sign in to comment.