Skip to content

Commit

Permalink
fix: disable save break process in custom config
Browse files Browse the repository at this point in the history
  • Loading branch information
drivebyer committed Sep 18, 2022
1 parent b8a671c commit efdcf02
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
3 changes: 3 additions & 0 deletions service/redis/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,9 @@ func (c *client) getConfigParameters(config string) (parameter string, value str
if len(s) < 2 {
return "", "", fmt.Errorf("configuration '%s' malformed", config)
}
if len(s) == 2 && s[1] == `""` {
return s[0], "", nil
}
return s[0], strings.Join(s[1:], " "), nil
}

Expand Down
36 changes: 36 additions & 0 deletions test/integration/redisfailover/creation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ package redisfailover_test
import (
"context"
"fmt"
"net"
"path/filepath"
"testing"
"time"

rediscli "github.com/go-redis/redis/v8"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -137,6 +140,9 @@ func TestRedisFailover(t *testing.T) {
// Verify that auth is set and actually working
t.Run("Check that auth is set in sentinel and redis configs", clients.testAuth)

// Check custom config is set
t.Run("Check that custom config is behave expected", clients.testCustomConfig)

// Check that a Redis Statefulset is created and the size of it is the one defined by the
// Redis Failover definition created before.
t.Run("Check Redis Statefulset existing and size", clients.testRedisStatefulSet)
Expand Down Expand Up @@ -168,6 +174,7 @@ func (c *clients) testCRCreation(t *testing.T) {
Exporter: redisfailoverv1.Exporter{
Enabled: true,
},
CustomConfig: []string{`save ""`},
},
Sentinel: redisfailoverv1.SentinelSettings{
Replicas: sentinelSize,
Expand Down Expand Up @@ -274,3 +281,32 @@ func (c *clients) testAuth(t *testing.T) {
assert.Equal(redisSS.Spec.Template.Spec.Containers[1].Env[4].ValueFrom.SecretKeyRef.Key, "password")
assert.Equal(redisSS.Spec.Template.Spec.Containers[1].Env[4].ValueFrom.SecretKeyRef.LocalObjectReference.Name, authSecretPath)
}

func (c *clients) testCustomConfig(t *testing.T) {
assert := assert.New(t)

redisSS, err := c.k8sClient.AppsV1().StatefulSets(namespace).Get(context.Background(), fmt.Sprintf("rfr-%s", name), metav1.GetOptions{})
assert.NoError(err)

listOptions := metav1.ListOptions{
LabelSelector: labels.FormatLabels(redisSS.Spec.Selector.MatchLabels),
}
redisPodList, err := c.k8sClient.CoreV1().Pods(namespace).List(context.Background(), listOptions)
assert.NoError(err)

rClient := rediscli.NewClient(&rediscli.Options{
Addr: net.JoinHostPort(redisPodList.Items[0].Status.PodIP, "6379"),
Password: testPass,
DB: 0,
})
defer rClient.Close()

result := rClient.ConfigGet(context.TODO(), "save")
assert.NoError(result.Err())

values, err := result.Result()
assert.NoError(err)

assert.Len(values, 2)
assert.Empty(values[1])
}

0 comments on commit efdcf02

Please sign in to comment.