From 26f9c0be576c6fbcd263f322ac7bd38478aa8e5e Mon Sep 17 00:00:00 2001 From: Shubham Gupta <69793468+shubham-cmyk@users.noreply.github.com> Date: Sun, 24 Sep 2023 13:33:06 +0530 Subject: [PATCH] Fix nil ptr for the redis-sentinel. (#642) Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com> --- api/v1beta1/redissentinel_conversion.go | 2 +- example/v1beta2/redis-cluster.yaml | 5 ----- k8sutils/redis-sentinel.go | 6 +++++- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/api/v1beta1/redissentinel_conversion.go b/api/v1beta1/redissentinel_conversion.go index 479f76ca..a069e167 100644 --- a/api/v1beta1/redissentinel_conversion.go +++ b/api/v1beta1/redissentinel_conversion.go @@ -5,7 +5,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/conversion" ) -// ConvertTo converts this RedisSentinel to the Hub version (vbeta2). +// ConvertTo converts this RedisSentinel to the Hub version (v1beta2). func (src *RedisSentinel) ConvertTo(dstRaw conversion.Hub) error { dst := dstRaw.(*redisv1beta2.RedisSentinel) diff --git a/example/v1beta2/redis-cluster.yaml b/example/v1beta2/redis-cluster.yaml index 5690c20f..87b308e3 100644 --- a/example/v1beta2/redis-cluster.yaml +++ b/example/v1beta2/redis-cluster.yaml @@ -20,11 +20,6 @@ spec: limits: cpu: 101m memory: 128Mi - env: - - name: CUSTOM_ENV_VAR_1 - value: "custom_value_1" - - name: CUSTOM_ENV_VAR_2 - value: "custom_value_2" # redisSecret: # name: redis-secret # key: password diff --git a/k8sutils/redis-sentinel.go b/k8sutils/redis-sentinel.go index f05aea39..d1636400 100644 --- a/k8sutils/redis-sentinel.go +++ b/k8sutils/redis-sentinel.go @@ -41,7 +41,7 @@ func CreateRedisSentinel(cr *redisv1beta2.RedisSentinel) error { TerminationGracePeriodSeconds: cr.Spec.TerminationGracePeriodSeconds, } - if cr.Spec.RedisSentinelConfig.AdditionalSentinelConfig != nil { + if cr.Spec.RedisSentinelConfig != nil && cr.Spec.RedisSentinelConfig.AdditionalSentinelConfig != nil { prop.ExternalConfig = cr.Spec.RedisSentinelConfig.AdditionalSentinelConfig } @@ -242,6 +242,10 @@ func (service RedisSentinelService) CreateRedisSentinelService(cr *redisv1beta2. func getSentinelEnvVariable(cr *redisv1beta2.RedisSentinel) *[]corev1.EnvVar { + if cr.Spec.RedisSentinelConfig == nil { + return &[]corev1.EnvVar{} + } + envVar := &[]corev1.EnvVar{ { Name: "MASTER_GROUP_NAME", -- GitLab