From b9298c405754788aafe0ed6a179908cb4f982f9f Mon Sep 17 00:00:00 2001 From: M Samuel Vijaykumar Date: Fri, 30 Aug 2024 14:38:27 +0530 Subject: [PATCH 01/14] Make mymaster initial changes --- api/redisfailover/v1/master.go | 9 +++++ api/redisfailover/v1/master_test.go | 52 +++++++++++++++++++++++++ api/redisfailover/v1/types.go | 1 + operator/redisfailover/checker.go | 4 +- operator/redisfailover/service/check.go | 8 ++-- operator/redisfailover/service/heal.go | 6 +-- service/redis/client.go | 27 +++++++------ 7 files changed, 84 insertions(+), 23 deletions(-) create mode 100644 api/redisfailover/v1/master.go create mode 100644 api/redisfailover/v1/master_test.go diff --git a/api/redisfailover/v1/master.go b/api/redisfailover/v1/master.go new file mode 100644 index 000000000..17db0c194 --- /dev/null +++ b/api/redisfailover/v1/master.go @@ -0,0 +1,9 @@ +package v1 + +func (r *RedisFailover) MasterName() string { + if r.Spec.Sentinel.DisableMyMaster { + return r.Name + } else { + return "mymaster" + } +} diff --git a/api/redisfailover/v1/master_test.go b/api/redisfailover/v1/master_test.go new file mode 100644 index 000000000..93549b0b6 --- /dev/null +++ b/api/redisfailover/v1/master_test.go @@ -0,0 +1,52 @@ +package v1 + +import ( + "testing" + + "github.com/stretchr/testify/assert" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +func generateRedisFailoverMasterName(name string, disableMyMaster bool) *RedisFailover { + return &RedisFailover{ + ObjectMeta: metav1.ObjectMeta{ + Name: name, + Namespace: "namespace", + }, + Spec: RedisFailoverSpec{ + Sentinel: SentinelSettings{ + DisableMyMaster: disableMyMaster, + }, + }, + } +} + +func TestMyMaster(t *testing.T) { + tests := []struct { + name string + expectation string + disableMyMaster bool + }{ + { + name: "use default mymaster", + expectation: "mymaster", + }, + { + name: "passing-false", + expectation: "mymaster", + disableMyMaster: false, + }, + { + name: "passing-true", + expectation: "passing-true", + disableMyMaster: true, + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + rf := generateRedisFailoverMasterName(test.name, test.disableMyMaster) + assert.Equal(t, test.expectation, rf.MasterName()) + }) + } +} diff --git a/api/redisfailover/v1/types.go b/api/redisfailover/v1/types.go index 45e801451..70276e9e4 100644 --- a/api/redisfailover/v1/types.go +++ b/api/redisfailover/v1/types.go @@ -105,6 +105,7 @@ type SentinelSettings struct { CustomReadinessProbe *corev1.Probe `json:"customReadinessProbe,omitempty"` CustomStartupProbe *corev1.Probe `json:"customStartupProbe,omitempty"` DisablePodDisruptionBudget bool `json:"disablePodDisruptionBudget,omitempty"` + DisableMyMaster bool `json:"disableMyMaster,omitempty"` } // AuthSettings contains settings about auth diff --git a/operator/redisfailover/checker.go b/operator/redisfailover/checker.go index 1671da74d..0038c8d87 100644 --- a/operator/redisfailover/checker.go +++ b/operator/redisfailover/checker.go @@ -218,7 +218,7 @@ func (r *RedisFailoverHandler) CheckAndHeal(rf *redisfailoverv1.RedisFailover) e port := getRedisPort(rf.Spec.Redis.Port) for _, sip := range sentinels { - err = r.rfChecker.CheckSentinelMonitor(sip, master, port) + err = r.rfChecker.CheckSentinelMonitor(sip, rf.MasterName(), master, port) setRedisCheckerMetrics(r.mClient, "sentinel", rf.Namespace, rf.Name, metrics.SENTINEL_WRONG_MASTER, sip, err) if err != nil { r.logger.WithField("redisfailover", rf.ObjectMeta.Name).WithField("namespace", rf.ObjectMeta.Namespace).Warningf("Fixing sentinel not monitoring expected master: %s", err.Error()) @@ -267,7 +267,7 @@ func (r *RedisFailoverHandler) checkAndHealBootstrapMode(rf *redisfailoverv1.Red return err } for _, sip := range sentinels { - err = r.rfChecker.CheckSentinelMonitor(sip, bootstrapSettings.Host, bootstrapSettings.Port) + err = r.rfChecker.CheckSentinelMonitor(sip, rf.MasterName(), bootstrapSettings.Host, bootstrapSettings.Port) setRedisCheckerMetrics(r.mClient, "sentinel", rf.Namespace, rf.Name, metrics.SENTINEL_WRONG_MASTER, sip, err) if err != nil { r.logger.WithField("redisfailover", rf.ObjectMeta.Name).WithField("namespace", rf.ObjectMeta.Namespace).Warningf("Fixing sentinel not monitoring expected master: %s", err.Error()) diff --git a/operator/redisfailover/service/check.go b/operator/redisfailover/service/check.go index 86401f0f9..7e041b61f 100644 --- a/operator/redisfailover/service/check.go +++ b/operator/redisfailover/service/check.go @@ -26,7 +26,7 @@ type RedisFailoverCheck interface { CheckSentinelSlavesNumberInMemory(sentinel string, rFailover *redisfailoverv1.RedisFailover) error CheckSentinelQuorum(rFailover *redisfailoverv1.RedisFailover) (int, error) CheckIfMasterLocalhost(rFailover *redisfailoverv1.RedisFailover) (bool, error) - CheckSentinelMonitor(sentinel string, monitor ...string) error + CheckSentinelMonitor(sentinel, masterName string, monitor ...string) error GetMasterIP(rFailover *redisfailoverv1.RedisFailover) (string, error) GetNumberMasters(rFailover *redisfailoverv1.RedisFailover) (int, error) GetRedisesIPs(rFailover *redisfailoverv1.RedisFailover) ([]string, error) @@ -211,7 +211,7 @@ func (r *RedisFailoverChecker) CheckSentinelQuorum(rFailover *redisfailoverv1.Re unhealthyCnt = 0 for _, sip := range sentinels { - err = r.redisClient.SentinelCheckQuorum(sip) + err = r.redisClient.SentinelCheckQuorum(sip, rFailover.MasterName()) if err != nil { unhealthyCnt += 1 } else { @@ -247,13 +247,13 @@ func (r *RedisFailoverChecker) CheckSentinelSlavesNumberInMemory(sentinel string } // CheckSentinelMonitor controls if the sentinels are monitoring the expected master -func (r *RedisFailoverChecker) CheckSentinelMonitor(sentinel string, monitor ...string) error { +func (r *RedisFailoverChecker) CheckSentinelMonitor(sentinel, masterName string, monitor ...string) error { monitorIP := monitor[0] monitorPort := "" if len(monitor) > 1 { monitorPort = monitor[1] } - actualMonitorIP, actualMonitorPort, err := r.redisClient.GetSentinelMonitor(sentinel) + actualMonitorIP, actualMonitorPort, err := r.redisClient.GetSentinelMonitor(sentinel, masterName) if err != nil { return err } diff --git a/operator/redisfailover/service/heal.go b/operator/redisfailover/service/heal.go index 390a6ac48..1a32bd83b 100644 --- a/operator/redisfailover/service/heal.go +++ b/operator/redisfailover/service/heal.go @@ -213,7 +213,7 @@ func (r *RedisFailoverHealer) NewSentinelMonitor(ip string, monitor string, rf * } port := getRedisPort(rf.Spec.Redis.Port) - return r.redisClient.MonitorRedisWithPort(ip, monitor, port, quorum, password) + return r.redisClient.MonitorRedisWithPort(ip, monitor, port, quorum, password, rf.MasterName()) } // NewSentinelMonitorWithPort changes the master that Sentinel has to monitor by the provided IP and Port @@ -225,7 +225,7 @@ func (r *RedisFailoverHealer) NewSentinelMonitorWithPort(ip string, monitor stri return err } - return r.redisClient.MonitorRedisWithPort(ip, monitor, monitorPort, quorum, password) + return r.redisClient.MonitorRedisWithPort(ip, monitor, monitorPort, quorum, password, rf.MasterName()) } // RestoreSentinel clear the number of sentinels on memory @@ -237,7 +237,7 @@ func (r *RedisFailoverHealer) RestoreSentinel(ip string) error { // SetSentinelCustomConfig will call sentinel to set the configuration given in config func (r *RedisFailoverHealer) SetSentinelCustomConfig(ip string, rf *redisfailoverv1.RedisFailover) error { r.logger.WithField("redisfailover", rf.ObjectMeta.Name).WithField("namespace", rf.ObjectMeta.Namespace).Debugf("Setting the custom config on sentinel %s...", ip) - return r.redisClient.SetCustomSentinelConfig(ip, rf.Spec.Sentinel.CustomConfig) + return r.redisClient.SetCustomSentinelConfig(ip, rf.MasterName(), rf.Spec.Sentinel.CustomConfig) } // SetRedisCustomConfig will call redis to set the configuration given in config diff --git a/service/redis/client.go b/service/redis/client.go index 3364de495..71707f88e 100644 --- a/service/redis/client.go +++ b/service/redis/client.go @@ -21,16 +21,16 @@ type Client interface { ResetSentinel(ip string) error GetSlaveOf(ip, port, password string) (string, error) IsMaster(ip, port, password string) (bool, error) - MonitorRedis(ip, monitor, quorum, password string) error - MonitorRedisWithPort(ip, monitor, port, quorum, password string) error + MonitorRedis(ip, monitor, quorum, password, masterName string) error + MonitorRedisWithPort(ip, monitor, port, quorum, password, masterName string) error MakeMaster(ip, port, password string) error MakeSlaveOf(ip, masterIP, password string) error MakeSlaveOfWithPort(ip, masterIP, masterPort, password string) error - GetSentinelMonitor(ip string) (string, string, error) - SetCustomSentinelConfig(ip string, configs []string) error + GetSentinelMonitor(ip, masterName string) (string, string, error) + SetCustomSentinelConfig(ip, masterName string, configs []string) error SetCustomRedisConfig(ip string, port string, configs []string, password string) error SlaveIsReady(ip, port, password string) (bool, error) - SentinelCheckQuorum(ip string) error + SentinelCheckQuorum(ip, masterName string) error } type client struct { @@ -55,7 +55,6 @@ const ( redisLinkUp = "master_link_status:up" redisPort = "6379" sentinelPort = "26379" - masterName = "mymaster" ) var ( @@ -203,11 +202,11 @@ func (c *client) IsMaster(ip, port, password string) (bool, error) { return strings.Contains(info, redisRoleMaster), nil } -func (c *client) MonitorRedis(ip, monitor, quorum, password string) error { - return c.MonitorRedisWithPort(ip, monitor, redisPort, quorum, password) +func (c *client) MonitorRedis(ip, monitor, quorum, password, masterName string) error { + return c.MonitorRedisWithPort(ip, monitor, redisPort, quorum, password, masterName) } -func (c *client) MonitorRedisWithPort(ip, monitor, port, quorum, password string) error { +func (c *client) MonitorRedisWithPort(ip, monitor, port, quorum, password, masterName string) error { options := &rediscli.Options{ Addr: net.JoinHostPort(ip, sentinelPort), Password: "", @@ -283,7 +282,7 @@ func (c *client) MakeSlaveOfWithPort(ip, masterIP, masterPort, password string) return nil } -func (c *client) GetSentinelMonitor(ip string) (string, string, error) { +func (c *client) GetSentinelMonitor(ip, masterName string) (string, string, error) { options := &rediscli.Options{ Addr: net.JoinHostPort(ip, sentinelPort), Password: "", @@ -308,7 +307,7 @@ func (c *client) GetSentinelMonitor(ip string) (string, string, error) { return masterIP, masterPort, nil } -func (c *client) SetCustomSentinelConfig(ip string, configs []string) error { +func (c *client) SetCustomSentinelConfig(ip, masterName string, configs []string) error { options := &rediscli.Options{ Addr: net.JoinHostPort(ip, sentinelPort), Password: "", @@ -322,14 +321,14 @@ func (c *client) SetCustomSentinelConfig(ip string, configs []string) error { if err != nil { return err } - if err := c.applySentinelConfig(param, value, rClient); err != nil { + if err := c.applySentinelConfig(param, masterName, value, rClient); err != nil { return err } } return nil } -func (c *client) SentinelCheckQuorum(ip string) error { +func (c *client) SentinelCheckQuorum(ip, masterName string) error { options := &rediscli.Options{ Addr: net.JoinHostPort(ip, sentinelPort), @@ -406,7 +405,7 @@ func (c *client) applyRedisConfig(parameter string, value string, rClient *redis return result.Err() } -func (c *client) applySentinelConfig(parameter string, value string, rClient *rediscli.Client) error { +func (c *client) applySentinelConfig(parameter, value, masterName string, rClient *rediscli.Client) error { cmd := rediscli.NewStatusCmd(context.TODO(), "SENTINEL", "set", masterName, parameter, value) err := rClient.Process(context.TODO(), cmd) if err != nil { From e9c9a6eb5c0cdd67f3729cb2f6a199230ad3e6b4 Mon Sep 17 00:00:00 2001 From: M Samuel Vijaykumar Date: Fri, 30 Aug 2024 18:52:04 +0530 Subject: [PATCH 02/14] Adding the named master support --- docker/development/Dockerfile | 4 +- ...atabases.spotahome.com_redisfailovers.yaml | 2 + ...atabases.spotahome.com_redisfailovers.yaml | 2 + mocks/log/Logger.go | 27 +- mocks/operator/redisfailover/RedisFailover.go | 19 +- .../service/RedisFailoverCheck.go | 105 ++++++- .../service/RedisFailoverClient.go | 55 +++- .../service/RedisFailoverHeal.go | 51 +++- mocks/service/k8s/Services.go | 215 +++++++++++++- mocks/service/redis/Client.go | 133 ++++++--- operator/redisfailover/checker_test.go | 268 +++++++++++++++++- operator/redisfailover/ensurer_test.go | 7 +- operator/redisfailover/service/check_test.go | 24 +- operator/redisfailover/service/heal_test.go | 8 +- .../redisfailover/creation_test.go | 2 +- 15 files changed, 813 insertions(+), 109 deletions(-) diff --git a/docker/development/Dockerfile b/docker/development/Dockerfile index 014aba86f..fee4d48a4 100644 --- a/docker/development/Dockerfile +++ b/docker/development/Dockerfile @@ -1,6 +1,6 @@ FROM golang:1.20-alpine -ENV CODEGEN_VERSION="1.11.9" +ENV CODEGEN_VERSION="1.27.16" RUN apk --no-cache add \ bash \ @@ -17,7 +17,7 @@ RUN wget http://github.com/kubernetes/code-generator/archive/kubernetes-${CODEGE touch /go/src/k8s.io/kubernetes/hack/boilerplate/boilerplate.go.txt # Mock creator -ARG MOCKERY_VERSION="2.9.6" +ARG MOCKERY_VERSION="2.45.0" RUN wget -c https://github.com/vektra/mockery/releases/download/v${MOCKERY_VERSION}/mockery_${MOCKERY_VERSION}_$(uname -o)_$(uname -m).tar.gz -O - | tar -xz -C /go/bin/ # Create user diff --git a/manifests/databases.spotahome.com_redisfailovers.yaml b/manifests/databases.spotahome.com_redisfailovers.yaml index 011476fa4..15e2960b1 100644 --- a/manifests/databases.spotahome.com_redisfailovers.yaml +++ b/manifests/databases.spotahome.com_redisfailovers.yaml @@ -8797,6 +8797,8 @@ spec: format: int32 type: integer type: object + disableMyMaster: + type: boolean disablePodDisruptionBudget: type: boolean dnsPolicy: diff --git a/manifests/kustomize/base/databases.spotahome.com_redisfailovers.yaml b/manifests/kustomize/base/databases.spotahome.com_redisfailovers.yaml index 011476fa4..15e2960b1 100644 --- a/manifests/kustomize/base/databases.spotahome.com_redisfailovers.yaml +++ b/manifests/kustomize/base/databases.spotahome.com_redisfailovers.yaml @@ -8797,6 +8797,8 @@ spec: format: int32 type: integer type: object + disableMyMaster: + type: boolean disablePodDisruptionBudget: type: boolean dnsPolicy: diff --git a/mocks/log/Logger.go b/mocks/log/Logger.go index 2ae79dfa6..2097f9421 100644 --- a/mocks/log/Logger.go +++ b/mocks/log/Logger.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.20.0. DO NOT EDIT. +// Code generated by mockery v2.45.0. DO NOT EDIT. package mocks @@ -126,6 +126,10 @@ func (_m *Logger) Panicln(_a0 ...interface{}) { func (_m *Logger) Set(level log.Level) error { ret := _m.Called(level) + if len(ret) == 0 { + panic("no return value specified for Set") + } + var r0 error if rf, ok := ret.Get(0).(func(log.Level) error); ok { r0 = rf(level) @@ -170,6 +174,10 @@ func (_m *Logger) Warnln(_a0 ...interface{}) { func (_m *Logger) With(key string, value interface{}) log.Logger { ret := _m.Called(key, value) + if len(ret) == 0 { + panic("no return value specified for With") + } + var r0 log.Logger if rf, ok := ret.Get(0).(func(string, interface{}) log.Logger); ok { r0 = rf(key, value) @@ -186,6 +194,10 @@ func (_m *Logger) With(key string, value interface{}) log.Logger { func (_m *Logger) WithField(key string, value interface{}) log.Logger { ret := _m.Called(key, value) + if len(ret) == 0 { + panic("no return value specified for WithField") + } + var r0 log.Logger if rf, ok := ret.Get(0).(func(string, interface{}) log.Logger); ok { r0 = rf(key, value) @@ -202,6 +214,10 @@ func (_m *Logger) WithField(key string, value interface{}) log.Logger { func (_m *Logger) WithFields(values map[string]interface{}) log.Logger { ret := _m.Called(values) + if len(ret) == 0 { + panic("no return value specified for WithFields") + } + var r0 log.Logger if rf, ok := ret.Get(0).(func(map[string]interface{}) log.Logger); ok { r0 = rf(values) @@ -214,13 +230,12 @@ func (_m *Logger) WithFields(values map[string]interface{}) log.Logger { return r0 } -type mockConstructorTestingTNewLogger interface { +// NewLogger creates a new instance of Logger. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewLogger(t interface { mock.TestingT Cleanup(func()) -} - -// NewLogger creates a new instance of Logger. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewLogger(t mockConstructorTestingTNewLogger) *Logger { +}) *Logger { mock := &Logger{} mock.Mock.Test(t) diff --git a/mocks/operator/redisfailover/RedisFailover.go b/mocks/operator/redisfailover/RedisFailover.go index 33c086c26..15baa9350 100644 --- a/mocks/operator/redisfailover/RedisFailover.go +++ b/mocks/operator/redisfailover/RedisFailover.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.20.0. DO NOT EDIT. +// Code generated by mockery v2.45.0. DO NOT EDIT. package mocks @@ -23,6 +23,10 @@ type RedisFailover struct { func (_m *RedisFailover) ListRedisFailovers(ctx context.Context, namespace string, opts v1.ListOptions) (*redisfailoverv1.RedisFailoverList, error) { ret := _m.Called(ctx, namespace, opts) + if len(ret) == 0 { + panic("no return value specified for ListRedisFailovers") + } + var r0 *redisfailoverv1.RedisFailoverList var r1 error if rf, ok := ret.Get(0).(func(context.Context, string, v1.ListOptions) (*redisfailoverv1.RedisFailoverList, error)); ok { @@ -49,6 +53,10 @@ func (_m *RedisFailover) ListRedisFailovers(ctx context.Context, namespace strin func (_m *RedisFailover) WatchRedisFailovers(ctx context.Context, namespace string, opts v1.ListOptions) (watch.Interface, error) { ret := _m.Called(ctx, namespace, opts) + if len(ret) == 0 { + panic("no return value specified for WatchRedisFailovers") + } + var r0 watch.Interface var r1 error if rf, ok := ret.Get(0).(func(context.Context, string, v1.ListOptions) (watch.Interface, error)); ok { @@ -71,13 +79,12 @@ func (_m *RedisFailover) WatchRedisFailovers(ctx context.Context, namespace stri return r0, r1 } -type mockConstructorTestingTNewRedisFailover interface { +// NewRedisFailover creates a new instance of RedisFailover. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewRedisFailover(t interface { mock.TestingT Cleanup(func()) -} - -// NewRedisFailover creates a new instance of RedisFailover. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewRedisFailover(t mockConstructorTestingTNewRedisFailover) *RedisFailover { +}) *RedisFailover { mock := &RedisFailover{} mock.Mock.Test(t) diff --git a/mocks/operator/redisfailover/service/RedisFailoverCheck.go b/mocks/operator/redisfailover/service/RedisFailoverCheck.go index 02c2ee339..6a487d55b 100644 --- a/mocks/operator/redisfailover/service/RedisFailoverCheck.go +++ b/mocks/operator/redisfailover/service/RedisFailoverCheck.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.20.0. DO NOT EDIT. +// Code generated by mockery v2.45.0. DO NOT EDIT. package mocks @@ -19,6 +19,10 @@ type RedisFailoverCheck struct { func (_m *RedisFailoverCheck) CheckAllSlavesFromMaster(master string, rFailover *v1.RedisFailover) error { ret := _m.Called(master, rFailover) + if len(ret) == 0 { + panic("no return value specified for CheckAllSlavesFromMaster") + } + var r0 error if rf, ok := ret.Get(0).(func(string, *v1.RedisFailover) error); ok { r0 = rf(master, rFailover) @@ -33,6 +37,10 @@ func (_m *RedisFailoverCheck) CheckAllSlavesFromMaster(master string, rFailover func (_m *RedisFailoverCheck) CheckIfMasterLocalhost(rFailover *v1.RedisFailover) (bool, error) { ret := _m.Called(rFailover) + if len(ret) == 0 { + panic("no return value specified for CheckIfMasterLocalhost") + } + var r0 bool var r1 error if rf, ok := ret.Get(0).(func(*v1.RedisFailover) (bool, error)); ok { @@ -57,6 +65,10 @@ func (_m *RedisFailoverCheck) CheckIfMasterLocalhost(rFailover *v1.RedisFailover func (_m *RedisFailoverCheck) CheckRedisNumber(rFailover *v1.RedisFailover) error { ret := _m.Called(rFailover) + if len(ret) == 0 { + panic("no return value specified for CheckRedisNumber") + } + var r0 error if rf, ok := ret.Get(0).(func(*v1.RedisFailover) error); ok { r0 = rf(rFailover) @@ -71,6 +83,10 @@ func (_m *RedisFailoverCheck) CheckRedisNumber(rFailover *v1.RedisFailover) erro func (_m *RedisFailoverCheck) CheckRedisSlavesReady(slaveIP string, rFailover *v1.RedisFailover) (bool, error) { ret := _m.Called(slaveIP, rFailover) + if len(ret) == 0 { + panic("no return value specified for CheckRedisSlavesReady") + } + var r0 bool var r1 error if rf, ok := ret.Get(0).(func(string, *v1.RedisFailover) (bool, error)); ok { @@ -91,20 +107,24 @@ func (_m *RedisFailoverCheck) CheckRedisSlavesReady(slaveIP string, rFailover *v return r0, r1 } -// CheckSentinelMonitor provides a mock function with given fields: sentinel, monitor -func (_m *RedisFailoverCheck) CheckSentinelMonitor(sentinel string, monitor ...string) error { +// CheckSentinelMonitor provides a mock function with given fields: sentinel, masterName, monitor +func (_m *RedisFailoverCheck) CheckSentinelMonitor(sentinel string, masterName string, monitor ...string) error { _va := make([]interface{}, len(monitor)) for _i := range monitor { _va[_i] = monitor[_i] } var _ca []interface{} - _ca = append(_ca, sentinel) + _ca = append(_ca, sentinel, masterName) _ca = append(_ca, _va...) ret := _m.Called(_ca...) + if len(ret) == 0 { + panic("no return value specified for CheckSentinelMonitor") + } + var r0 error - if rf, ok := ret.Get(0).(func(string, ...string) error); ok { - r0 = rf(sentinel, monitor...) + if rf, ok := ret.Get(0).(func(string, string, ...string) error); ok { + r0 = rf(sentinel, masterName, monitor...) } else { r0 = ret.Error(0) } @@ -116,6 +136,10 @@ func (_m *RedisFailoverCheck) CheckSentinelMonitor(sentinel string, monitor ...s func (_m *RedisFailoverCheck) CheckSentinelNumber(rFailover *v1.RedisFailover) error { ret := _m.Called(rFailover) + if len(ret) == 0 { + panic("no return value specified for CheckSentinelNumber") + } + var r0 error if rf, ok := ret.Get(0).(func(*v1.RedisFailover) error); ok { r0 = rf(rFailover) @@ -130,6 +154,10 @@ func (_m *RedisFailoverCheck) CheckSentinelNumber(rFailover *v1.RedisFailover) e func (_m *RedisFailoverCheck) CheckSentinelNumberInMemory(sentinel string, rFailover *v1.RedisFailover) error { ret := _m.Called(sentinel, rFailover) + if len(ret) == 0 { + panic("no return value specified for CheckSentinelNumberInMemory") + } + var r0 error if rf, ok := ret.Get(0).(func(string, *v1.RedisFailover) error); ok { r0 = rf(sentinel, rFailover) @@ -144,6 +172,10 @@ func (_m *RedisFailoverCheck) CheckSentinelNumberInMemory(sentinel string, rFail func (_m *RedisFailoverCheck) CheckSentinelQuorum(rFailover *v1.RedisFailover) (int, error) { ret := _m.Called(rFailover) + if len(ret) == 0 { + panic("no return value specified for CheckSentinelQuorum") + } + var r0 int var r1 error if rf, ok := ret.Get(0).(func(*v1.RedisFailover) (int, error)); ok { @@ -168,6 +200,10 @@ func (_m *RedisFailoverCheck) CheckSentinelQuorum(rFailover *v1.RedisFailover) ( func (_m *RedisFailoverCheck) CheckSentinelSlavesNumberInMemory(sentinel string, rFailover *v1.RedisFailover) error { ret := _m.Called(sentinel, rFailover) + if len(ret) == 0 { + panic("no return value specified for CheckSentinelSlavesNumberInMemory") + } + var r0 error if rf, ok := ret.Get(0).(func(string, *v1.RedisFailover) error); ok { r0 = rf(sentinel, rFailover) @@ -182,6 +218,10 @@ func (_m *RedisFailoverCheck) CheckSentinelSlavesNumberInMemory(sentinel string, func (_m *RedisFailoverCheck) GetMasterIP(rFailover *v1.RedisFailover) (string, error) { ret := _m.Called(rFailover) + if len(ret) == 0 { + panic("no return value specified for GetMasterIP") + } + var r0 string var r1 error if rf, ok := ret.Get(0).(func(*v1.RedisFailover) (string, error)); ok { @@ -206,6 +246,10 @@ func (_m *RedisFailoverCheck) GetMasterIP(rFailover *v1.RedisFailover) (string, func (_m *RedisFailoverCheck) GetMaxRedisPodTime(rFailover *v1.RedisFailover) (time.Duration, error) { ret := _m.Called(rFailover) + if len(ret) == 0 { + panic("no return value specified for GetMaxRedisPodTime") + } + var r0 time.Duration var r1 error if rf, ok := ret.Get(0).(func(*v1.RedisFailover) (time.Duration, error)); ok { @@ -230,6 +274,10 @@ func (_m *RedisFailoverCheck) GetMaxRedisPodTime(rFailover *v1.RedisFailover) (t func (_m *RedisFailoverCheck) GetNumberMasters(rFailover *v1.RedisFailover) (int, error) { ret := _m.Called(rFailover) + if len(ret) == 0 { + panic("no return value specified for GetNumberMasters") + } + var r0 int var r1 error if rf, ok := ret.Get(0).(func(*v1.RedisFailover) (int, error)); ok { @@ -254,6 +302,10 @@ func (_m *RedisFailoverCheck) GetNumberMasters(rFailover *v1.RedisFailover) (int func (_m *RedisFailoverCheck) GetRedisRevisionHash(podName string, rFailover *v1.RedisFailover) (string, error) { ret := _m.Called(podName, rFailover) + if len(ret) == 0 { + panic("no return value specified for GetRedisRevisionHash") + } + var r0 string var r1 error if rf, ok := ret.Get(0).(func(string, *v1.RedisFailover) (string, error)); ok { @@ -278,6 +330,10 @@ func (_m *RedisFailoverCheck) GetRedisRevisionHash(podName string, rFailover *v1 func (_m *RedisFailoverCheck) GetRedisesIPs(rFailover *v1.RedisFailover) ([]string, error) { ret := _m.Called(rFailover) + if len(ret) == 0 { + panic("no return value specified for GetRedisesIPs") + } + var r0 []string var r1 error if rf, ok := ret.Get(0).(func(*v1.RedisFailover) ([]string, error)); ok { @@ -304,6 +360,10 @@ func (_m *RedisFailoverCheck) GetRedisesIPs(rFailover *v1.RedisFailover) ([]stri func (_m *RedisFailoverCheck) GetRedisesMasterPod(rFailover *v1.RedisFailover) (string, error) { ret := _m.Called(rFailover) + if len(ret) == 0 { + panic("no return value specified for GetRedisesMasterPod") + } + var r0 string var r1 error if rf, ok := ret.Get(0).(func(*v1.RedisFailover) (string, error)); ok { @@ -328,6 +388,10 @@ func (_m *RedisFailoverCheck) GetRedisesMasterPod(rFailover *v1.RedisFailover) ( func (_m *RedisFailoverCheck) GetRedisesSlavesPods(rFailover *v1.RedisFailover) ([]string, error) { ret := _m.Called(rFailover) + if len(ret) == 0 { + panic("no return value specified for GetRedisesSlavesPods") + } + var r0 []string var r1 error if rf, ok := ret.Get(0).(func(*v1.RedisFailover) ([]string, error)); ok { @@ -354,6 +418,10 @@ func (_m *RedisFailoverCheck) GetRedisesSlavesPods(rFailover *v1.RedisFailover) func (_m *RedisFailoverCheck) GetSentinelsIPs(rFailover *v1.RedisFailover) ([]string, error) { ret := _m.Called(rFailover) + if len(ret) == 0 { + panic("no return value specified for GetSentinelsIPs") + } + var r0 []string var r1 error if rf, ok := ret.Get(0).(func(*v1.RedisFailover) ([]string, error)); ok { @@ -380,6 +448,10 @@ func (_m *RedisFailoverCheck) GetSentinelsIPs(rFailover *v1.RedisFailover) ([]st func (_m *RedisFailoverCheck) GetStatefulSetUpdateRevision(rFailover *v1.RedisFailover) (string, error) { ret := _m.Called(rFailover) + if len(ret) == 0 { + panic("no return value specified for GetStatefulSetUpdateRevision") + } + var r0 string var r1 error if rf, ok := ret.Get(0).(func(*v1.RedisFailover) (string, error)); ok { @@ -404,6 +476,10 @@ func (_m *RedisFailoverCheck) GetStatefulSetUpdateRevision(rFailover *v1.RedisFa func (_m *RedisFailoverCheck) IsClusterRunning(rFailover *v1.RedisFailover) bool { ret := _m.Called(rFailover) + if len(ret) == 0 { + panic("no return value specified for IsClusterRunning") + } + var r0 bool if rf, ok := ret.Get(0).(func(*v1.RedisFailover) bool); ok { r0 = rf(rFailover) @@ -418,6 +494,10 @@ func (_m *RedisFailoverCheck) IsClusterRunning(rFailover *v1.RedisFailover) bool func (_m *RedisFailoverCheck) IsRedisRunning(rFailover *v1.RedisFailover) bool { ret := _m.Called(rFailover) + if len(ret) == 0 { + panic("no return value specified for IsRedisRunning") + } + var r0 bool if rf, ok := ret.Get(0).(func(*v1.RedisFailover) bool); ok { r0 = rf(rFailover) @@ -432,6 +512,10 @@ func (_m *RedisFailoverCheck) IsRedisRunning(rFailover *v1.RedisFailover) bool { func (_m *RedisFailoverCheck) IsSentinelRunning(rFailover *v1.RedisFailover) bool { ret := _m.Called(rFailover) + if len(ret) == 0 { + panic("no return value specified for IsSentinelRunning") + } + var r0 bool if rf, ok := ret.Get(0).(func(*v1.RedisFailover) bool); ok { r0 = rf(rFailover) @@ -442,13 +526,12 @@ func (_m *RedisFailoverCheck) IsSentinelRunning(rFailover *v1.RedisFailover) boo return r0 } -type mockConstructorTestingTNewRedisFailoverCheck interface { +// NewRedisFailoverCheck creates a new instance of RedisFailoverCheck. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewRedisFailoverCheck(t interface { mock.TestingT Cleanup(func()) -} - -// NewRedisFailoverCheck creates a new instance of RedisFailoverCheck. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewRedisFailoverCheck(t mockConstructorTestingTNewRedisFailoverCheck) *RedisFailoverCheck { +}) *RedisFailoverCheck { mock := &RedisFailoverCheck{} mock.Mock.Test(t) diff --git a/mocks/operator/redisfailover/service/RedisFailoverClient.go b/mocks/operator/redisfailover/service/RedisFailoverClient.go index 61b7c96e2..074efa55e 100644 --- a/mocks/operator/redisfailover/service/RedisFailoverClient.go +++ b/mocks/operator/redisfailover/service/RedisFailoverClient.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.20.0. DO NOT EDIT. +// Code generated by mockery v2.45.0. DO NOT EDIT. package mocks @@ -18,6 +18,10 @@ type RedisFailoverClient struct { func (_m *RedisFailoverClient) EnsureNotPresentRedisService(rFailover *v1.RedisFailover) error { ret := _m.Called(rFailover) + if len(ret) == 0 { + panic("no return value specified for EnsureNotPresentRedisService") + } + var r0 error if rf, ok := ret.Get(0).(func(*v1.RedisFailover) error); ok { r0 = rf(rFailover) @@ -32,6 +36,10 @@ func (_m *RedisFailoverClient) EnsureNotPresentRedisService(rFailover *v1.RedisF func (_m *RedisFailoverClient) EnsureRedisConfigMap(rFailover *v1.RedisFailover, labels map[string]string, ownerRefs []metav1.OwnerReference) error { ret := _m.Called(rFailover, labels, ownerRefs) + if len(ret) == 0 { + panic("no return value specified for EnsureRedisConfigMap") + } + var r0 error if rf, ok := ret.Get(0).(func(*v1.RedisFailover, map[string]string, []metav1.OwnerReference) error); ok { r0 = rf(rFailover, labels, ownerRefs) @@ -46,6 +54,10 @@ func (_m *RedisFailoverClient) EnsureRedisConfigMap(rFailover *v1.RedisFailover, func (_m *RedisFailoverClient) EnsureRedisMasterService(rFailover *v1.RedisFailover, labels map[string]string, ownerRefs []metav1.OwnerReference) error { ret := _m.Called(rFailover, labels, ownerRefs) + if len(ret) == 0 { + panic("no return value specified for EnsureRedisMasterService") + } + var r0 error if rf, ok := ret.Get(0).(func(*v1.RedisFailover, map[string]string, []metav1.OwnerReference) error); ok { r0 = rf(rFailover, labels, ownerRefs) @@ -60,6 +72,10 @@ func (_m *RedisFailoverClient) EnsureRedisMasterService(rFailover *v1.RedisFailo func (_m *RedisFailoverClient) EnsureRedisReadinessConfigMap(rFailover *v1.RedisFailover, labels map[string]string, ownerRefs []metav1.OwnerReference) error { ret := _m.Called(rFailover, labels, ownerRefs) + if len(ret) == 0 { + panic("no return value specified for EnsureRedisReadinessConfigMap") + } + var r0 error if rf, ok := ret.Get(0).(func(*v1.RedisFailover, map[string]string, []metav1.OwnerReference) error); ok { r0 = rf(rFailover, labels, ownerRefs) @@ -74,6 +90,10 @@ func (_m *RedisFailoverClient) EnsureRedisReadinessConfigMap(rFailover *v1.Redis func (_m *RedisFailoverClient) EnsureRedisService(rFailover *v1.RedisFailover, labels map[string]string, ownerRefs []metav1.OwnerReference) error { ret := _m.Called(rFailover, labels, ownerRefs) + if len(ret) == 0 { + panic("no return value specified for EnsureRedisService") + } + var r0 error if rf, ok := ret.Get(0).(func(*v1.RedisFailover, map[string]string, []metav1.OwnerReference) error); ok { r0 = rf(rFailover, labels, ownerRefs) @@ -88,6 +108,10 @@ func (_m *RedisFailoverClient) EnsureRedisService(rFailover *v1.RedisFailover, l func (_m *RedisFailoverClient) EnsureRedisShutdownConfigMap(rFailover *v1.RedisFailover, labels map[string]string, ownerRefs []metav1.OwnerReference) error { ret := _m.Called(rFailover, labels, ownerRefs) + if len(ret) == 0 { + panic("no return value specified for EnsureRedisShutdownConfigMap") + } + var r0 error if rf, ok := ret.Get(0).(func(*v1.RedisFailover, map[string]string, []metav1.OwnerReference) error); ok { r0 = rf(rFailover, labels, ownerRefs) @@ -102,6 +126,10 @@ func (_m *RedisFailoverClient) EnsureRedisShutdownConfigMap(rFailover *v1.RedisF func (_m *RedisFailoverClient) EnsureRedisSlaveService(rFailover *v1.RedisFailover, labels map[string]string, ownerRefs []metav1.OwnerReference) error { ret := _m.Called(rFailover, labels, ownerRefs) + if len(ret) == 0 { + panic("no return value specified for EnsureRedisSlaveService") + } + var r0 error if rf, ok := ret.Get(0).(func(*v1.RedisFailover, map[string]string, []metav1.OwnerReference) error); ok { r0 = rf(rFailover, labels, ownerRefs) @@ -116,6 +144,10 @@ func (_m *RedisFailoverClient) EnsureRedisSlaveService(rFailover *v1.RedisFailov func (_m *RedisFailoverClient) EnsureRedisStatefulset(rFailover *v1.RedisFailover, labels map[string]string, ownerRefs []metav1.OwnerReference) error { ret := _m.Called(rFailover, labels, ownerRefs) + if len(ret) == 0 { + panic("no return value specified for EnsureRedisStatefulset") + } + var r0 error if rf, ok := ret.Get(0).(func(*v1.RedisFailover, map[string]string, []metav1.OwnerReference) error); ok { r0 = rf(rFailover, labels, ownerRefs) @@ -130,6 +162,10 @@ func (_m *RedisFailoverClient) EnsureRedisStatefulset(rFailover *v1.RedisFailove func (_m *RedisFailoverClient) EnsureSentinelConfigMap(rFailover *v1.RedisFailover, labels map[string]string, ownerRefs []metav1.OwnerReference) error { ret := _m.Called(rFailover, labels, ownerRefs) + if len(ret) == 0 { + panic("no return value specified for EnsureSentinelConfigMap") + } + var r0 error if rf, ok := ret.Get(0).(func(*v1.RedisFailover, map[string]string, []metav1.OwnerReference) error); ok { r0 = rf(rFailover, labels, ownerRefs) @@ -144,6 +180,10 @@ func (_m *RedisFailoverClient) EnsureSentinelConfigMap(rFailover *v1.RedisFailov func (_m *RedisFailoverClient) EnsureSentinelDeployment(rFailover *v1.RedisFailover, labels map[string]string, ownerRefs []metav1.OwnerReference) error { ret := _m.Called(rFailover, labels, ownerRefs) + if len(ret) == 0 { + panic("no return value specified for EnsureSentinelDeployment") + } + var r0 error if rf, ok := ret.Get(0).(func(*v1.RedisFailover, map[string]string, []metav1.OwnerReference) error); ok { r0 = rf(rFailover, labels, ownerRefs) @@ -158,6 +198,10 @@ func (_m *RedisFailoverClient) EnsureSentinelDeployment(rFailover *v1.RedisFailo func (_m *RedisFailoverClient) EnsureSentinelService(rFailover *v1.RedisFailover, labels map[string]string, ownerRefs []metav1.OwnerReference) error { ret := _m.Called(rFailover, labels, ownerRefs) + if len(ret) == 0 { + panic("no return value specified for EnsureSentinelService") + } + var r0 error if rf, ok := ret.Get(0).(func(*v1.RedisFailover, map[string]string, []metav1.OwnerReference) error); ok { r0 = rf(rFailover, labels, ownerRefs) @@ -168,13 +212,12 @@ func (_m *RedisFailoverClient) EnsureSentinelService(rFailover *v1.RedisFailover return r0 } -type mockConstructorTestingTNewRedisFailoverClient interface { +// NewRedisFailoverClient creates a new instance of RedisFailoverClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewRedisFailoverClient(t interface { mock.TestingT Cleanup(func()) -} - -// NewRedisFailoverClient creates a new instance of RedisFailoverClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewRedisFailoverClient(t mockConstructorTestingTNewRedisFailoverClient) *RedisFailoverClient { +}) *RedisFailoverClient { mock := &RedisFailoverClient{} mock.Mock.Test(t) diff --git a/mocks/operator/redisfailover/service/RedisFailoverHeal.go b/mocks/operator/redisfailover/service/RedisFailoverHeal.go index f7d1202c3..fba24a9d5 100644 --- a/mocks/operator/redisfailover/service/RedisFailoverHeal.go +++ b/mocks/operator/redisfailover/service/RedisFailoverHeal.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.20.0. DO NOT EDIT. +// Code generated by mockery v2.45.0. DO NOT EDIT. package mocks @@ -17,6 +17,10 @@ type RedisFailoverHeal struct { func (_m *RedisFailoverHeal) DeletePod(podName string, rFailover *v1.RedisFailover) error { ret := _m.Called(podName, rFailover) + if len(ret) == 0 { + panic("no return value specified for DeletePod") + } + var r0 error if rf, ok := ret.Get(0).(func(string, *v1.RedisFailover) error); ok { r0 = rf(podName, rFailover) @@ -31,6 +35,10 @@ func (_m *RedisFailoverHeal) DeletePod(podName string, rFailover *v1.RedisFailov func (_m *RedisFailoverHeal) MakeMaster(ip string, rFailover *v1.RedisFailover) error { ret := _m.Called(ip, rFailover) + if len(ret) == 0 { + panic("no return value specified for MakeMaster") + } + var r0 error if rf, ok := ret.Get(0).(func(string, *v1.RedisFailover) error); ok { r0 = rf(ip, rFailover) @@ -45,6 +53,10 @@ func (_m *RedisFailoverHeal) MakeMaster(ip string, rFailover *v1.RedisFailover) func (_m *RedisFailoverHeal) NewSentinelMonitor(ip string, monitor string, rFailover *v1.RedisFailover) error { ret := _m.Called(ip, monitor, rFailover) + if len(ret) == 0 { + panic("no return value specified for NewSentinelMonitor") + } + var r0 error if rf, ok := ret.Get(0).(func(string, string, *v1.RedisFailover) error); ok { r0 = rf(ip, monitor, rFailover) @@ -59,6 +71,10 @@ func (_m *RedisFailoverHeal) NewSentinelMonitor(ip string, monitor string, rFail func (_m *RedisFailoverHeal) NewSentinelMonitorWithPort(ip string, monitor string, port string, rFailover *v1.RedisFailover) error { ret := _m.Called(ip, monitor, port, rFailover) + if len(ret) == 0 { + panic("no return value specified for NewSentinelMonitorWithPort") + } + var r0 error if rf, ok := ret.Get(0).(func(string, string, string, *v1.RedisFailover) error); ok { r0 = rf(ip, monitor, port, rFailover) @@ -73,6 +89,10 @@ func (_m *RedisFailoverHeal) NewSentinelMonitorWithPort(ip string, monitor strin func (_m *RedisFailoverHeal) RestoreSentinel(ip string) error { ret := _m.Called(ip) + if len(ret) == 0 { + panic("no return value specified for RestoreSentinel") + } + var r0 error if rf, ok := ret.Get(0).(func(string) error); ok { r0 = rf(ip) @@ -87,6 +107,10 @@ func (_m *RedisFailoverHeal) RestoreSentinel(ip string) error { func (_m *RedisFailoverHeal) SetExternalMasterOnAll(masterIP string, masterPort string, rFailover *v1.RedisFailover) error { ret := _m.Called(masterIP, masterPort, rFailover) + if len(ret) == 0 { + panic("no return value specified for SetExternalMasterOnAll") + } + var r0 error if rf, ok := ret.Get(0).(func(string, string, *v1.RedisFailover) error); ok { r0 = rf(masterIP, masterPort, rFailover) @@ -101,6 +125,10 @@ func (_m *RedisFailoverHeal) SetExternalMasterOnAll(masterIP string, masterPort func (_m *RedisFailoverHeal) SetMasterOnAll(masterIP string, rFailover *v1.RedisFailover) error { ret := _m.Called(masterIP, rFailover) + if len(ret) == 0 { + panic("no return value specified for SetMasterOnAll") + } + var r0 error if rf, ok := ret.Get(0).(func(string, *v1.RedisFailover) error); ok { r0 = rf(masterIP, rFailover) @@ -115,6 +143,10 @@ func (_m *RedisFailoverHeal) SetMasterOnAll(masterIP string, rFailover *v1.Redis func (_m *RedisFailoverHeal) SetOldestAsMaster(rFailover *v1.RedisFailover) error { ret := _m.Called(rFailover) + if len(ret) == 0 { + panic("no return value specified for SetOldestAsMaster") + } + var r0 error if rf, ok := ret.Get(0).(func(*v1.RedisFailover) error); ok { r0 = rf(rFailover) @@ -129,6 +161,10 @@ func (_m *RedisFailoverHeal) SetOldestAsMaster(rFailover *v1.RedisFailover) erro func (_m *RedisFailoverHeal) SetRedisCustomConfig(ip string, rFailover *v1.RedisFailover) error { ret := _m.Called(ip, rFailover) + if len(ret) == 0 { + panic("no return value specified for SetRedisCustomConfig") + } + var r0 error if rf, ok := ret.Get(0).(func(string, *v1.RedisFailover) error); ok { r0 = rf(ip, rFailover) @@ -143,6 +179,10 @@ func (_m *RedisFailoverHeal) SetRedisCustomConfig(ip string, rFailover *v1.Redis func (_m *RedisFailoverHeal) SetSentinelCustomConfig(ip string, rFailover *v1.RedisFailover) error { ret := _m.Called(ip, rFailover) + if len(ret) == 0 { + panic("no return value specified for SetSentinelCustomConfig") + } + var r0 error if rf, ok := ret.Get(0).(func(string, *v1.RedisFailover) error); ok { r0 = rf(ip, rFailover) @@ -153,13 +193,12 @@ func (_m *RedisFailoverHeal) SetSentinelCustomConfig(ip string, rFailover *v1.Re return r0 } -type mockConstructorTestingTNewRedisFailoverHeal interface { +// NewRedisFailoverHeal creates a new instance of RedisFailoverHeal. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewRedisFailoverHeal(t interface { mock.TestingT Cleanup(func()) -} - -// NewRedisFailoverHeal creates a new instance of RedisFailoverHeal. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewRedisFailoverHeal(t mockConstructorTestingTNewRedisFailoverHeal) *RedisFailoverHeal { +}) *RedisFailoverHeal { mock := &RedisFailoverHeal{} mock.Mock.Test(t) diff --git a/mocks/service/k8s/Services.go b/mocks/service/k8s/Services.go index e734f6f47..2183ed723 100644 --- a/mocks/service/k8s/Services.go +++ b/mocks/service/k8s/Services.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.20.0. DO NOT EDIT. +// Code generated by mockery v2.45.0. DO NOT EDIT. package mocks @@ -31,6 +31,10 @@ type Services struct { func (_m *Services) CreateConfigMap(namespace string, configMap *v1.ConfigMap) error { ret := _m.Called(namespace, configMap) + if len(ret) == 0 { + panic("no return value specified for CreateConfigMap") + } + var r0 error if rf, ok := ret.Get(0).(func(string, *v1.ConfigMap) error); ok { r0 = rf(namespace, configMap) @@ -45,6 +49,10 @@ func (_m *Services) CreateConfigMap(namespace string, configMap *v1.ConfigMap) e func (_m *Services) CreateDeployment(namespace string, deployment *appsv1.Deployment) error { ret := _m.Called(namespace, deployment) + if len(ret) == 0 { + panic("no return value specified for CreateDeployment") + } + var r0 error if rf, ok := ret.Get(0).(func(string, *appsv1.Deployment) error); ok { r0 = rf(namespace, deployment) @@ -59,6 +67,10 @@ func (_m *Services) CreateDeployment(namespace string, deployment *appsv1.Deploy func (_m *Services) CreateIfNotExistsService(namespace string, service *v1.Service) error { ret := _m.Called(namespace, service) + if len(ret) == 0 { + panic("no return value specified for CreateIfNotExistsService") + } + var r0 error if rf, ok := ret.Get(0).(func(string, *v1.Service) error); ok { r0 = rf(namespace, service) @@ -73,6 +85,10 @@ func (_m *Services) CreateIfNotExistsService(namespace string, service *v1.Servi func (_m *Services) CreateOrUpdateConfigMap(namespace string, np *v1.ConfigMap) error { ret := _m.Called(namespace, np) + if len(ret) == 0 { + panic("no return value specified for CreateOrUpdateConfigMap") + } + var r0 error if rf, ok := ret.Get(0).(func(string, *v1.ConfigMap) error); ok { r0 = rf(namespace, np) @@ -87,6 +103,10 @@ func (_m *Services) CreateOrUpdateConfigMap(namespace string, np *v1.ConfigMap) func (_m *Services) CreateOrUpdateDeployment(namespace string, deployment *appsv1.Deployment) error { ret := _m.Called(namespace, deployment) + if len(ret) == 0 { + panic("no return value specified for CreateOrUpdateDeployment") + } + var r0 error if rf, ok := ret.Get(0).(func(string, *appsv1.Deployment) error); ok { r0 = rf(namespace, deployment) @@ -101,6 +121,10 @@ func (_m *Services) CreateOrUpdateDeployment(namespace string, deployment *appsv func (_m *Services) CreateOrUpdatePod(namespace string, pod *v1.Pod) error { ret := _m.Called(namespace, pod) + if len(ret) == 0 { + panic("no return value specified for CreateOrUpdatePod") + } + var r0 error if rf, ok := ret.Get(0).(func(string, *v1.Pod) error); ok { r0 = rf(namespace, pod) @@ -115,6 +139,10 @@ func (_m *Services) CreateOrUpdatePod(namespace string, pod *v1.Pod) error { func (_m *Services) CreateOrUpdatePodDisruptionBudget(namespace string, podDisruptionBudget *policyv1.PodDisruptionBudget) error { ret := _m.Called(namespace, podDisruptionBudget) + if len(ret) == 0 { + panic("no return value specified for CreateOrUpdatePodDisruptionBudget") + } + var r0 error if rf, ok := ret.Get(0).(func(string, *policyv1.PodDisruptionBudget) error); ok { r0 = rf(namespace, podDisruptionBudget) @@ -129,6 +157,10 @@ func (_m *Services) CreateOrUpdatePodDisruptionBudget(namespace string, podDisru func (_m *Services) CreateOrUpdateRole(namespace string, binding *rbacv1.Role) error { ret := _m.Called(namespace, binding) + if len(ret) == 0 { + panic("no return value specified for CreateOrUpdateRole") + } + var r0 error if rf, ok := ret.Get(0).(func(string, *rbacv1.Role) error); ok { r0 = rf(namespace, binding) @@ -143,6 +175,10 @@ func (_m *Services) CreateOrUpdateRole(namespace string, binding *rbacv1.Role) e func (_m *Services) CreateOrUpdateRoleBinding(namespace string, binding *rbacv1.RoleBinding) error { ret := _m.Called(namespace, binding) + if len(ret) == 0 { + panic("no return value specified for CreateOrUpdateRoleBinding") + } + var r0 error if rf, ok := ret.Get(0).(func(string, *rbacv1.RoleBinding) error); ok { r0 = rf(namespace, binding) @@ -157,6 +193,10 @@ func (_m *Services) CreateOrUpdateRoleBinding(namespace string, binding *rbacv1. func (_m *Services) CreateOrUpdateService(namespace string, service *v1.Service) error { ret := _m.Called(namespace, service) + if len(ret) == 0 { + panic("no return value specified for CreateOrUpdateService") + } + var r0 error if rf, ok := ret.Get(0).(func(string, *v1.Service) error); ok { r0 = rf(namespace, service) @@ -171,6 +211,10 @@ func (_m *Services) CreateOrUpdateService(namespace string, service *v1.Service) func (_m *Services) CreateOrUpdateStatefulSet(namespace string, statefulSet *appsv1.StatefulSet) error { ret := _m.Called(namespace, statefulSet) + if len(ret) == 0 { + panic("no return value specified for CreateOrUpdateStatefulSet") + } + var r0 error if rf, ok := ret.Get(0).(func(string, *appsv1.StatefulSet) error); ok { r0 = rf(namespace, statefulSet) @@ -185,6 +229,10 @@ func (_m *Services) CreateOrUpdateStatefulSet(namespace string, statefulSet *app func (_m *Services) CreatePod(namespace string, pod *v1.Pod) error { ret := _m.Called(namespace, pod) + if len(ret) == 0 { + panic("no return value specified for CreatePod") + } + var r0 error if rf, ok := ret.Get(0).(func(string, *v1.Pod) error); ok { r0 = rf(namespace, pod) @@ -199,6 +247,10 @@ func (_m *Services) CreatePod(namespace string, pod *v1.Pod) error { func (_m *Services) CreatePodDisruptionBudget(namespace string, podDisruptionBudget *policyv1.PodDisruptionBudget) error { ret := _m.Called(namespace, podDisruptionBudget) + if len(ret) == 0 { + panic("no return value specified for CreatePodDisruptionBudget") + } + var r0 error if rf, ok := ret.Get(0).(func(string, *policyv1.PodDisruptionBudget) error); ok { r0 = rf(namespace, podDisruptionBudget) @@ -213,6 +265,10 @@ func (_m *Services) CreatePodDisruptionBudget(namespace string, podDisruptionBud func (_m *Services) CreateRole(namespace string, role *rbacv1.Role) error { ret := _m.Called(namespace, role) + if len(ret) == 0 { + panic("no return value specified for CreateRole") + } + var r0 error if rf, ok := ret.Get(0).(func(string, *rbacv1.Role) error); ok { r0 = rf(namespace, role) @@ -227,6 +283,10 @@ func (_m *Services) CreateRole(namespace string, role *rbacv1.Role) error { func (_m *Services) CreateRoleBinding(namespace string, binding *rbacv1.RoleBinding) error { ret := _m.Called(namespace, binding) + if len(ret) == 0 { + panic("no return value specified for CreateRoleBinding") + } + var r0 error if rf, ok := ret.Get(0).(func(string, *rbacv1.RoleBinding) error); ok { r0 = rf(namespace, binding) @@ -241,6 +301,10 @@ func (_m *Services) CreateRoleBinding(namespace string, binding *rbacv1.RoleBind func (_m *Services) CreateService(namespace string, service *v1.Service) error { ret := _m.Called(namespace, service) + if len(ret) == 0 { + panic("no return value specified for CreateService") + } + var r0 error if rf, ok := ret.Get(0).(func(string, *v1.Service) error); ok { r0 = rf(namespace, service) @@ -255,6 +319,10 @@ func (_m *Services) CreateService(namespace string, service *v1.Service) error { func (_m *Services) CreateStatefulSet(namespace string, statefulSet *appsv1.StatefulSet) error { ret := _m.Called(namespace, statefulSet) + if len(ret) == 0 { + panic("no return value specified for CreateStatefulSet") + } + var r0 error if rf, ok := ret.Get(0).(func(string, *appsv1.StatefulSet) error); ok { r0 = rf(namespace, statefulSet) @@ -269,6 +337,10 @@ func (_m *Services) CreateStatefulSet(namespace string, statefulSet *appsv1.Stat func (_m *Services) DeleteConfigMap(namespace string, name string) error { ret := _m.Called(namespace, name) + if len(ret) == 0 { + panic("no return value specified for DeleteConfigMap") + } + var r0 error if rf, ok := ret.Get(0).(func(string, string) error); ok { r0 = rf(namespace, name) @@ -283,6 +355,10 @@ func (_m *Services) DeleteConfigMap(namespace string, name string) error { func (_m *Services) DeleteDeployment(namespace string, name string) error { ret := _m.Called(namespace, name) + if len(ret) == 0 { + panic("no return value specified for DeleteDeployment") + } + var r0 error if rf, ok := ret.Get(0).(func(string, string) error); ok { r0 = rf(namespace, name) @@ -297,6 +373,10 @@ func (_m *Services) DeleteDeployment(namespace string, name string) error { func (_m *Services) DeletePod(namespace string, name string) error { ret := _m.Called(namespace, name) + if len(ret) == 0 { + panic("no return value specified for DeletePod") + } + var r0 error if rf, ok := ret.Get(0).(func(string, string) error); ok { r0 = rf(namespace, name) @@ -311,6 +391,10 @@ func (_m *Services) DeletePod(namespace string, name string) error { func (_m *Services) DeletePodDisruptionBudget(namespace string, name string) error { ret := _m.Called(namespace, name) + if len(ret) == 0 { + panic("no return value specified for DeletePodDisruptionBudget") + } + var r0 error if rf, ok := ret.Get(0).(func(string, string) error); ok { r0 = rf(namespace, name) @@ -325,6 +409,10 @@ func (_m *Services) DeletePodDisruptionBudget(namespace string, name string) err func (_m *Services) DeleteService(namespace string, name string) error { ret := _m.Called(namespace, name) + if len(ret) == 0 { + panic("no return value specified for DeleteService") + } + var r0 error if rf, ok := ret.Get(0).(func(string, string) error); ok { r0 = rf(namespace, name) @@ -339,6 +427,10 @@ func (_m *Services) DeleteService(namespace string, name string) error { func (_m *Services) DeleteStatefulSet(namespace string, name string) error { ret := _m.Called(namespace, name) + if len(ret) == 0 { + panic("no return value specified for DeleteStatefulSet") + } + var r0 error if rf, ok := ret.Get(0).(func(string, string) error); ok { r0 = rf(namespace, name) @@ -353,6 +445,10 @@ func (_m *Services) DeleteStatefulSet(namespace string, name string) error { func (_m *Services) GetClusterRole(name string) (*rbacv1.ClusterRole, error) { ret := _m.Called(name) + if len(ret) == 0 { + panic("no return value specified for GetClusterRole") + } + var r0 *rbacv1.ClusterRole var r1 error if rf, ok := ret.Get(0).(func(string) (*rbacv1.ClusterRole, error)); ok { @@ -379,6 +475,10 @@ func (_m *Services) GetClusterRole(name string) (*rbacv1.ClusterRole, error) { func (_m *Services) GetConfigMap(namespace string, name string) (*v1.ConfigMap, error) { ret := _m.Called(namespace, name) + if len(ret) == 0 { + panic("no return value specified for GetConfigMap") + } + var r0 *v1.ConfigMap var r1 error if rf, ok := ret.Get(0).(func(string, string) (*v1.ConfigMap, error)); ok { @@ -405,6 +505,10 @@ func (_m *Services) GetConfigMap(namespace string, name string) (*v1.ConfigMap, func (_m *Services) GetDeployment(namespace string, name string) (*appsv1.Deployment, error) { ret := _m.Called(namespace, name) + if len(ret) == 0 { + panic("no return value specified for GetDeployment") + } + var r0 *appsv1.Deployment var r1 error if rf, ok := ret.Get(0).(func(string, string) (*appsv1.Deployment, error)); ok { @@ -431,6 +535,10 @@ func (_m *Services) GetDeployment(namespace string, name string) (*appsv1.Deploy func (_m *Services) GetDeploymentPods(namespace string, name string) (*v1.PodList, error) { ret := _m.Called(namespace, name) + if len(ret) == 0 { + panic("no return value specified for GetDeploymentPods") + } + var r0 *v1.PodList var r1 error if rf, ok := ret.Get(0).(func(string, string) (*v1.PodList, error)); ok { @@ -457,6 +565,10 @@ func (_m *Services) GetDeploymentPods(namespace string, name string) (*v1.PodLis func (_m *Services) GetPod(namespace string, name string) (*v1.Pod, error) { ret := _m.Called(namespace, name) + if len(ret) == 0 { + panic("no return value specified for GetPod") + } + var r0 *v1.Pod var r1 error if rf, ok := ret.Get(0).(func(string, string) (*v1.Pod, error)); ok { @@ -483,6 +595,10 @@ func (_m *Services) GetPod(namespace string, name string) (*v1.Pod, error) { func (_m *Services) GetPodDisruptionBudget(namespace string, name string) (*policyv1.PodDisruptionBudget, error) { ret := _m.Called(namespace, name) + if len(ret) == 0 { + panic("no return value specified for GetPodDisruptionBudget") + } + var r0 *policyv1.PodDisruptionBudget var r1 error if rf, ok := ret.Get(0).(func(string, string) (*policyv1.PodDisruptionBudget, error)); ok { @@ -509,6 +625,10 @@ func (_m *Services) GetPodDisruptionBudget(namespace string, name string) (*poli func (_m *Services) GetRole(namespace string, name string) (*rbacv1.Role, error) { ret := _m.Called(namespace, name) + if len(ret) == 0 { + panic("no return value specified for GetRole") + } + var r0 *rbacv1.Role var r1 error if rf, ok := ret.Get(0).(func(string, string) (*rbacv1.Role, error)); ok { @@ -535,6 +655,10 @@ func (_m *Services) GetRole(namespace string, name string) (*rbacv1.Role, error) func (_m *Services) GetRoleBinding(namespace string, name string) (*rbacv1.RoleBinding, error) { ret := _m.Called(namespace, name) + if len(ret) == 0 { + panic("no return value specified for GetRoleBinding") + } + var r0 *rbacv1.RoleBinding var r1 error if rf, ok := ret.Get(0).(func(string, string) (*rbacv1.RoleBinding, error)); ok { @@ -561,6 +685,10 @@ func (_m *Services) GetRoleBinding(namespace string, name string) (*rbacv1.RoleB func (_m *Services) GetSecret(namespace string, name string) (*v1.Secret, error) { ret := _m.Called(namespace, name) + if len(ret) == 0 { + panic("no return value specified for GetSecret") + } + var r0 *v1.Secret var r1 error if rf, ok := ret.Get(0).(func(string, string) (*v1.Secret, error)); ok { @@ -587,6 +715,10 @@ func (_m *Services) GetSecret(namespace string, name string) (*v1.Secret, error) func (_m *Services) GetService(namespace string, name string) (*v1.Service, error) { ret := _m.Called(namespace, name) + if len(ret) == 0 { + panic("no return value specified for GetService") + } + var r0 *v1.Service var r1 error if rf, ok := ret.Get(0).(func(string, string) (*v1.Service, error)); ok { @@ -613,6 +745,10 @@ func (_m *Services) GetService(namespace string, name string) (*v1.Service, erro func (_m *Services) GetStatefulSet(namespace string, name string) (*appsv1.StatefulSet, error) { ret := _m.Called(namespace, name) + if len(ret) == 0 { + panic("no return value specified for GetStatefulSet") + } + var r0 *appsv1.StatefulSet var r1 error if rf, ok := ret.Get(0).(func(string, string) (*appsv1.StatefulSet, error)); ok { @@ -639,6 +775,10 @@ func (_m *Services) GetStatefulSet(namespace string, name string) (*appsv1.State func (_m *Services) GetStatefulSetPods(namespace string, name string) (*v1.PodList, error) { ret := _m.Called(namespace, name) + if len(ret) == 0 { + panic("no return value specified for GetStatefulSetPods") + } + var r0 *v1.PodList var r1 error if rf, ok := ret.Get(0).(func(string, string) (*v1.PodList, error)); ok { @@ -665,6 +805,10 @@ func (_m *Services) GetStatefulSetPods(namespace string, name string) (*v1.PodLi func (_m *Services) ListConfigMaps(namespace string) (*v1.ConfigMapList, error) { ret := _m.Called(namespace) + if len(ret) == 0 { + panic("no return value specified for ListConfigMaps") + } + var r0 *v1.ConfigMapList var r1 error if rf, ok := ret.Get(0).(func(string) (*v1.ConfigMapList, error)); ok { @@ -691,6 +835,10 @@ func (_m *Services) ListConfigMaps(namespace string) (*v1.ConfigMapList, error) func (_m *Services) ListDeployments(namespace string) (*appsv1.DeploymentList, error) { ret := _m.Called(namespace) + if len(ret) == 0 { + panic("no return value specified for ListDeployments") + } + var r0 *appsv1.DeploymentList var r1 error if rf, ok := ret.Get(0).(func(string) (*appsv1.DeploymentList, error)); ok { @@ -717,6 +865,10 @@ func (_m *Services) ListDeployments(namespace string) (*appsv1.DeploymentList, e func (_m *Services) ListPods(namespace string) (*v1.PodList, error) { ret := _m.Called(namespace) + if len(ret) == 0 { + panic("no return value specified for ListPods") + } + var r0 *v1.PodList var r1 error if rf, ok := ret.Get(0).(func(string) (*v1.PodList, error)); ok { @@ -743,6 +895,10 @@ func (_m *Services) ListPods(namespace string) (*v1.PodList, error) { func (_m *Services) ListRedisFailovers(ctx context.Context, namespace string, opts metav1.ListOptions) (*redisfailoverv1.RedisFailoverList, error) { ret := _m.Called(ctx, namespace, opts) + if len(ret) == 0 { + panic("no return value specified for ListRedisFailovers") + } + var r0 *redisfailoverv1.RedisFailoverList var r1 error if rf, ok := ret.Get(0).(func(context.Context, string, metav1.ListOptions) (*redisfailoverv1.RedisFailoverList, error)); ok { @@ -769,6 +925,10 @@ func (_m *Services) ListRedisFailovers(ctx context.Context, namespace string, op func (_m *Services) ListServices(namespace string) (*v1.ServiceList, error) { ret := _m.Called(namespace) + if len(ret) == 0 { + panic("no return value specified for ListServices") + } + var r0 *v1.ServiceList var r1 error if rf, ok := ret.Get(0).(func(string) (*v1.ServiceList, error)); ok { @@ -795,6 +955,10 @@ func (_m *Services) ListServices(namespace string) (*v1.ServiceList, error) { func (_m *Services) ListStatefulSets(namespace string) (*appsv1.StatefulSetList, error) { ret := _m.Called(namespace) + if len(ret) == 0 { + panic("no return value specified for ListStatefulSets") + } + var r0 *appsv1.StatefulSetList var r1 error if rf, ok := ret.Get(0).(func(string) (*appsv1.StatefulSetList, error)); ok { @@ -821,6 +985,10 @@ func (_m *Services) ListStatefulSets(namespace string) (*appsv1.StatefulSetList, func (_m *Services) UpdateConfigMap(namespace string, configMap *v1.ConfigMap) error { ret := _m.Called(namespace, configMap) + if len(ret) == 0 { + panic("no return value specified for UpdateConfigMap") + } + var r0 error if rf, ok := ret.Get(0).(func(string, *v1.ConfigMap) error); ok { r0 = rf(namespace, configMap) @@ -835,6 +1003,10 @@ func (_m *Services) UpdateConfigMap(namespace string, configMap *v1.ConfigMap) e func (_m *Services) UpdateDeployment(namespace string, deployment *appsv1.Deployment) error { ret := _m.Called(namespace, deployment) + if len(ret) == 0 { + panic("no return value specified for UpdateDeployment") + } + var r0 error if rf, ok := ret.Get(0).(func(string, *appsv1.Deployment) error); ok { r0 = rf(namespace, deployment) @@ -849,6 +1021,10 @@ func (_m *Services) UpdateDeployment(namespace string, deployment *appsv1.Deploy func (_m *Services) UpdatePod(namespace string, pod *v1.Pod) error { ret := _m.Called(namespace, pod) + if len(ret) == 0 { + panic("no return value specified for UpdatePod") + } + var r0 error if rf, ok := ret.Get(0).(func(string, *v1.Pod) error); ok { r0 = rf(namespace, pod) @@ -863,6 +1039,10 @@ func (_m *Services) UpdatePod(namespace string, pod *v1.Pod) error { func (_m *Services) UpdatePodDisruptionBudget(namespace string, podDisruptionBudget *policyv1.PodDisruptionBudget) error { ret := _m.Called(namespace, podDisruptionBudget) + if len(ret) == 0 { + panic("no return value specified for UpdatePodDisruptionBudget") + } + var r0 error if rf, ok := ret.Get(0).(func(string, *policyv1.PodDisruptionBudget) error); ok { r0 = rf(namespace, podDisruptionBudget) @@ -877,6 +1057,10 @@ func (_m *Services) UpdatePodDisruptionBudget(namespace string, podDisruptionBud func (_m *Services) UpdatePodLabels(namespace string, podName string, labels map[string]string) error { ret := _m.Called(namespace, podName, labels) + if len(ret) == 0 { + panic("no return value specified for UpdatePodLabels") + } + var r0 error if rf, ok := ret.Get(0).(func(string, string, map[string]string) error); ok { r0 = rf(namespace, podName, labels) @@ -891,6 +1075,10 @@ func (_m *Services) UpdatePodLabels(namespace string, podName string, labels map func (_m *Services) UpdateRole(namespace string, role *rbacv1.Role) error { ret := _m.Called(namespace, role) + if len(ret) == 0 { + panic("no return value specified for UpdateRole") + } + var r0 error if rf, ok := ret.Get(0).(func(string, *rbacv1.Role) error); ok { r0 = rf(namespace, role) @@ -905,6 +1093,10 @@ func (_m *Services) UpdateRole(namespace string, role *rbacv1.Role) error { func (_m *Services) UpdateRoleBinding(namespace string, binding *rbacv1.RoleBinding) error { ret := _m.Called(namespace, binding) + if len(ret) == 0 { + panic("no return value specified for UpdateRoleBinding") + } + var r0 error if rf, ok := ret.Get(0).(func(string, *rbacv1.RoleBinding) error); ok { r0 = rf(namespace, binding) @@ -919,6 +1111,10 @@ func (_m *Services) UpdateRoleBinding(namespace string, binding *rbacv1.RoleBind func (_m *Services) UpdateService(namespace string, service *v1.Service) error { ret := _m.Called(namespace, service) + if len(ret) == 0 { + panic("no return value specified for UpdateService") + } + var r0 error if rf, ok := ret.Get(0).(func(string, *v1.Service) error); ok { r0 = rf(namespace, service) @@ -933,6 +1129,10 @@ func (_m *Services) UpdateService(namespace string, service *v1.Service) error { func (_m *Services) UpdateStatefulSet(namespace string, statefulSet *appsv1.StatefulSet) error { ret := _m.Called(namespace, statefulSet) + if len(ret) == 0 { + panic("no return value specified for UpdateStatefulSet") + } + var r0 error if rf, ok := ret.Get(0).(func(string, *appsv1.StatefulSet) error); ok { r0 = rf(namespace, statefulSet) @@ -947,6 +1147,10 @@ func (_m *Services) UpdateStatefulSet(namespace string, statefulSet *appsv1.Stat func (_m *Services) WatchRedisFailovers(ctx context.Context, namespace string, opts metav1.ListOptions) (watch.Interface, error) { ret := _m.Called(ctx, namespace, opts) + if len(ret) == 0 { + panic("no return value specified for WatchRedisFailovers") + } + var r0 watch.Interface var r1 error if rf, ok := ret.Get(0).(func(context.Context, string, metav1.ListOptions) (watch.Interface, error)); ok { @@ -969,13 +1173,12 @@ func (_m *Services) WatchRedisFailovers(ctx context.Context, namespace string, o return r0, r1 } -type mockConstructorTestingTNewServices interface { +// NewServices creates a new instance of Services. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewServices(t interface { mock.TestingT Cleanup(func()) -} - -// NewServices creates a new instance of Services. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewServices(t mockConstructorTestingTNewServices) *Services { +}) *Services { mock := &Services{} mock.Mock.Test(t) diff --git a/mocks/service/redis/Client.go b/mocks/service/redis/Client.go index 6950584ee..075093a60 100644 --- a/mocks/service/redis/Client.go +++ b/mocks/service/redis/Client.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.20.0. DO NOT EDIT. +// Code generated by mockery v2.45.0. DO NOT EDIT. package mocks @@ -13,6 +13,10 @@ type Client struct { func (_m *Client) GetNumberSentinelSlavesInMemory(ip string) (int32, error) { ret := _m.Called(ip) + if len(ret) == 0 { + panic("no return value specified for GetNumberSentinelSlavesInMemory") + } + var r0 int32 var r1 error if rf, ok := ret.Get(0).(func(string) (int32, error)); ok { @@ -37,6 +41,10 @@ func (_m *Client) GetNumberSentinelSlavesInMemory(ip string) (int32, error) { func (_m *Client) GetNumberSentinelsInMemory(ip string) (int32, error) { ret := _m.Called(ip) + if len(ret) == 0 { + panic("no return value specified for GetNumberSentinelsInMemory") + } + var r0 int32 var r1 error if rf, ok := ret.Get(0).(func(string) (int32, error)); ok { @@ -57,30 +65,34 @@ func (_m *Client) GetNumberSentinelsInMemory(ip string) (int32, error) { return r0, r1 } -// GetSentinelMonitor provides a mock function with given fields: ip -func (_m *Client) GetSentinelMonitor(ip string) (string, string, error) { - ret := _m.Called(ip) +// GetSentinelMonitor provides a mock function with given fields: ip, masterName +func (_m *Client) GetSentinelMonitor(ip string, masterName string) (string, string, error) { + ret := _m.Called(ip, masterName) + + if len(ret) == 0 { + panic("no return value specified for GetSentinelMonitor") + } var r0 string var r1 string var r2 error - if rf, ok := ret.Get(0).(func(string) (string, string, error)); ok { - return rf(ip) + if rf, ok := ret.Get(0).(func(string, string) (string, string, error)); ok { + return rf(ip, masterName) } - if rf, ok := ret.Get(0).(func(string) string); ok { - r0 = rf(ip) + if rf, ok := ret.Get(0).(func(string, string) string); ok { + r0 = rf(ip, masterName) } else { r0 = ret.Get(0).(string) } - if rf, ok := ret.Get(1).(func(string) string); ok { - r1 = rf(ip) + if rf, ok := ret.Get(1).(func(string, string) string); ok { + r1 = rf(ip, masterName) } else { r1 = ret.Get(1).(string) } - if rf, ok := ret.Get(2).(func(string) error); ok { - r2 = rf(ip) + if rf, ok := ret.Get(2).(func(string, string) error); ok { + r2 = rf(ip, masterName) } else { r2 = ret.Error(2) } @@ -92,6 +104,10 @@ func (_m *Client) GetSentinelMonitor(ip string) (string, string, error) { func (_m *Client) GetSlaveOf(ip string, port string, password string) (string, error) { ret := _m.Called(ip, port, password) + if len(ret) == 0 { + panic("no return value specified for GetSlaveOf") + } + var r0 string var r1 error if rf, ok := ret.Get(0).(func(string, string, string) (string, error)); ok { @@ -116,6 +132,10 @@ func (_m *Client) GetSlaveOf(ip string, port string, password string) (string, e func (_m *Client) IsMaster(ip string, port string, password string) (bool, error) { ret := _m.Called(ip, port, password) + if len(ret) == 0 { + panic("no return value specified for IsMaster") + } + var r0 bool var r1 error if rf, ok := ret.Get(0).(func(string, string, string) (bool, error)); ok { @@ -140,6 +160,10 @@ func (_m *Client) IsMaster(ip string, port string, password string) (bool, error func (_m *Client) MakeMaster(ip string, port string, password string) error { ret := _m.Called(ip, port, password) + if len(ret) == 0 { + panic("no return value specified for MakeMaster") + } + var r0 error if rf, ok := ret.Get(0).(func(string, string, string) error); ok { r0 = rf(ip, port, password) @@ -154,6 +178,10 @@ func (_m *Client) MakeMaster(ip string, port string, password string) error { func (_m *Client) MakeSlaveOf(ip string, masterIP string, password string) error { ret := _m.Called(ip, masterIP, password) + if len(ret) == 0 { + panic("no return value specified for MakeSlaveOf") + } + var r0 error if rf, ok := ret.Get(0).(func(string, string, string) error); ok { r0 = rf(ip, masterIP, password) @@ -168,6 +196,10 @@ func (_m *Client) MakeSlaveOf(ip string, masterIP string, password string) error func (_m *Client) MakeSlaveOfWithPort(ip string, masterIP string, masterPort string, password string) error { ret := _m.Called(ip, masterIP, masterPort, password) + if len(ret) == 0 { + panic("no return value specified for MakeSlaveOfWithPort") + } + var r0 error if rf, ok := ret.Get(0).(func(string, string, string, string) error); ok { r0 = rf(ip, masterIP, masterPort, password) @@ -178,13 +210,17 @@ func (_m *Client) MakeSlaveOfWithPort(ip string, masterIP string, masterPort str return r0 } -// MonitorRedis provides a mock function with given fields: ip, monitor, quorum, password -func (_m *Client) MonitorRedis(ip string, monitor string, quorum string, password string) error { - ret := _m.Called(ip, monitor, quorum, password) +// MonitorRedis provides a mock function with given fields: ip, monitor, quorum, password, masterName +func (_m *Client) MonitorRedis(ip string, monitor string, quorum string, password string, masterName string) error { + ret := _m.Called(ip, monitor, quorum, password, masterName) + + if len(ret) == 0 { + panic("no return value specified for MonitorRedis") + } var r0 error - if rf, ok := ret.Get(0).(func(string, string, string, string) error); ok { - r0 = rf(ip, monitor, quorum, password) + if rf, ok := ret.Get(0).(func(string, string, string, string, string) error); ok { + r0 = rf(ip, monitor, quorum, password, masterName) } else { r0 = ret.Error(0) } @@ -192,13 +228,17 @@ func (_m *Client) MonitorRedis(ip string, monitor string, quorum string, passwor return r0 } -// MonitorRedisWithPort provides a mock function with given fields: ip, monitor, port, quorum, password -func (_m *Client) MonitorRedisWithPort(ip string, monitor string, port string, quorum string, password string) error { - ret := _m.Called(ip, monitor, port, quorum, password) +// MonitorRedisWithPort provides a mock function with given fields: ip, monitor, port, quorum, password, masterName +func (_m *Client) MonitorRedisWithPort(ip string, monitor string, port string, quorum string, password string, masterName string) error { + ret := _m.Called(ip, monitor, port, quorum, password, masterName) + + if len(ret) == 0 { + panic("no return value specified for MonitorRedisWithPort") + } var r0 error - if rf, ok := ret.Get(0).(func(string, string, string, string, string) error); ok { - r0 = rf(ip, monitor, port, quorum, password) + if rf, ok := ret.Get(0).(func(string, string, string, string, string, string) error); ok { + r0 = rf(ip, monitor, port, quorum, password, masterName) } else { r0 = ret.Error(0) } @@ -210,6 +250,10 @@ func (_m *Client) MonitorRedisWithPort(ip string, monitor string, port string, q func (_m *Client) ResetSentinel(ip string) error { ret := _m.Called(ip) + if len(ret) == 0 { + panic("no return value specified for ResetSentinel") + } + var r0 error if rf, ok := ret.Get(0).(func(string) error); ok { r0 = rf(ip) @@ -220,13 +264,17 @@ func (_m *Client) ResetSentinel(ip string) error { return r0 } -// SentinelCheckQuorum provides a mock function with given fields: ip -func (_m *Client) SentinelCheckQuorum(ip string) error { - ret := _m.Called(ip) +// SentinelCheckQuorum provides a mock function with given fields: ip, masterName +func (_m *Client) SentinelCheckQuorum(ip string, masterName string) error { + ret := _m.Called(ip, masterName) + + if len(ret) == 0 { + panic("no return value specified for SentinelCheckQuorum") + } var r0 error - if rf, ok := ret.Get(0).(func(string) error); ok { - r0 = rf(ip) + if rf, ok := ret.Get(0).(func(string, string) error); ok { + r0 = rf(ip, masterName) } else { r0 = ret.Error(0) } @@ -238,6 +286,10 @@ func (_m *Client) SentinelCheckQuorum(ip string) error { func (_m *Client) SetCustomRedisConfig(ip string, port string, configs []string, password string) error { ret := _m.Called(ip, port, configs, password) + if len(ret) == 0 { + panic("no return value specified for SetCustomRedisConfig") + } + var r0 error if rf, ok := ret.Get(0).(func(string, string, []string, string) error); ok { r0 = rf(ip, port, configs, password) @@ -248,13 +300,17 @@ func (_m *Client) SetCustomRedisConfig(ip string, port string, configs []string, return r0 } -// SetCustomSentinelConfig provides a mock function with given fields: ip, configs -func (_m *Client) SetCustomSentinelConfig(ip string, configs []string) error { - ret := _m.Called(ip, configs) +// SetCustomSentinelConfig provides a mock function with given fields: ip, masterName, configs +func (_m *Client) SetCustomSentinelConfig(ip string, masterName string, configs []string) error { + ret := _m.Called(ip, masterName, configs) + + if len(ret) == 0 { + panic("no return value specified for SetCustomSentinelConfig") + } var r0 error - if rf, ok := ret.Get(0).(func(string, []string) error); ok { - r0 = rf(ip, configs) + if rf, ok := ret.Get(0).(func(string, string, []string) error); ok { + r0 = rf(ip, masterName, configs) } else { r0 = ret.Error(0) } @@ -266,6 +322,10 @@ func (_m *Client) SetCustomSentinelConfig(ip string, configs []string) error { func (_m *Client) SlaveIsReady(ip string, port string, password string) (bool, error) { ret := _m.Called(ip, port, password) + if len(ret) == 0 { + panic("no return value specified for SlaveIsReady") + } + var r0 bool var r1 error if rf, ok := ret.Get(0).(func(string, string, string) (bool, error)); ok { @@ -286,13 +346,12 @@ func (_m *Client) SlaveIsReady(ip string, port string, password string) (bool, e return r0, r1 } -type mockConstructorTestingTNewClient interface { +// NewClient creates a new instance of Client. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewClient(t interface { mock.TestingT Cleanup(func()) -} - -// NewClient creates a new instance of Client. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewClient(t mockConstructorTestingTNewClient) *Client { +}) *Client { mock := &Client{} mock.Mock.Test(t) diff --git a/operator/redisfailover/checker_test.go b/operator/redisfailover/checker_test.go index 2e83a47b4..60ed70f5b 100644 --- a/operator/redisfailover/checker_test.go +++ b/operator/redisfailover/checker_test.go @@ -35,6 +35,7 @@ func TestCheckAndHeal(t *testing.T) { redisSetMasterOnAllOK bool bootstrapping bool allowSentinels bool + disableMyMaster bool }{ { name: "Everything ok, no need to heal", @@ -52,6 +53,23 @@ func TestCheckAndHeal(t *testing.T) { bootstrapping: false, allowSentinels: false, }, + { + name: "Everything ok, no need to heal w/ master name", + nMasters: 1, + nRedis: 3, + singleMasterTest: false, + forceNewMasterNoQrm: false, + forceNewMasterFirstBoot: false, + slavesOK: true, + sentinelMonitorOK: true, + sentinelNumberInMemoryOK: true, + sentinelSlavesNumberInMemoryOK: true, + redisCheckNumberOK: true, + redisSetMasterOnAllOK: true, + bootstrapping: false, + allowSentinels: false, + disableMyMaster: true, + }, { name: "Multiple masters", nMasters: 2, @@ -68,6 +86,23 @@ func TestCheckAndHeal(t *testing.T) { bootstrapping: false, allowSentinels: false, }, + { + name: "Multiple masters w/ master name", + nMasters: 2, + nRedis: 3, + singleMasterTest: false, + forceNewMasterNoQrm: false, + forceNewMasterFirstBoot: false, + slavesOK: true, + sentinelMonitorOK: true, + sentinelNumberInMemoryOK: true, + sentinelSlavesNumberInMemoryOK: true, + redisCheckNumberOK: true, + redisSetMasterOnAllOK: true, + bootstrapping: false, + allowSentinels: false, + disableMyMaster: true, + }, { name: "No masters but wait", nMasters: 0, @@ -84,6 +119,23 @@ func TestCheckAndHeal(t *testing.T) { bootstrapping: false, allowSentinels: false, }, + { + name: "No masters but wait w/ master name", + nMasters: 0, + nRedis: 3, + singleMasterTest: false, + forceNewMasterNoQrm: false, + forceNewMasterFirstBoot: false, + slavesOK: true, + sentinelMonitorOK: true, + sentinelNumberInMemoryOK: true, + sentinelSlavesNumberInMemoryOK: true, + redisCheckNumberOK: true, + redisSetMasterOnAllOK: true, + bootstrapping: false, + allowSentinels: false, + disableMyMaster: true, + }, { name: "No masters, only one redis available, make master", nMasters: 0, @@ -100,6 +152,23 @@ func TestCheckAndHeal(t *testing.T) { bootstrapping: false, allowSentinels: false, }, + { + name: "No masters, only one redis available, make master w/ master name", + nMasters: 0, + nRedis: 1, + singleMasterTest: true, + forceNewMasterNoQrm: false, + forceNewMasterFirstBoot: false, + slavesOK: true, + sentinelMonitorOK: true, + sentinelNumberInMemoryOK: true, + sentinelSlavesNumberInMemoryOK: true, + redisCheckNumberOK: true, + redisSetMasterOnAllOK: true, + bootstrapping: false, + allowSentinels: false, + disableMyMaster: true, + }, { name: "No masters,No sentinel quorum set random", nMasters: 0, @@ -116,12 +185,28 @@ func TestCheckAndHeal(t *testing.T) { allowSentinels: false, }, { - name: "No masters,Sentinel Quorum but slave of local host set random", + name: "No masters,No sentinel quorum set random w/ master name", nMasters: 0, nRedis: 3, singleMasterTest: false, - forceNewMasterNoQrm: false, - forceNewMasterFirstBoot: true, + forceNewMasterNoQrm: true, + forceNewMasterFirstBoot: false, + slavesOK: true, + sentinelMonitorOK: true, + sentinelNumberInMemoryOK: true, + redisCheckNumberOK: true, + redisSetMasterOnAllOK: true, + sentinelSlavesNumberInMemoryOK: true, + allowSentinels: false, + disableMyMaster: true, + }, + { + name: "No masters,No sentinel quorum set random", + nMasters: 0, + nRedis: 3, + singleMasterTest: false, + forceNewMasterNoQrm: true, + forceNewMasterFirstBoot: false, slavesOK: true, sentinelMonitorOK: true, sentinelNumberInMemoryOK: true, @@ -130,6 +215,22 @@ func TestCheckAndHeal(t *testing.T) { sentinelSlavesNumberInMemoryOK: true, allowSentinels: false, }, + { + name: "No masters,No sentinel quorum set random w/ master name", + nMasters: 0, + nRedis: 3, + singleMasterTest: false, + forceNewMasterNoQrm: true, + forceNewMasterFirstBoot: false, + slavesOK: true, + sentinelMonitorOK: true, + sentinelNumberInMemoryOK: true, + redisCheckNumberOK: true, + redisSetMasterOnAllOK: true, + sentinelSlavesNumberInMemoryOK: true, + allowSentinels: false, + disableMyMaster: true, + }, { name: "Slaves from master wrong", nMasters: 1, @@ -146,6 +247,23 @@ func TestCheckAndHeal(t *testing.T) { bootstrapping: false, allowSentinels: false, }, + { + name: "Slaves from master wrong w/ master name", + nMasters: 1, + nRedis: 3, + singleMasterTest: false, + forceNewMasterNoQrm: false, + forceNewMasterFirstBoot: false, + slavesOK: false, + sentinelMonitorOK: true, + sentinelNumberInMemoryOK: true, + sentinelSlavesNumberInMemoryOK: true, + redisCheckNumberOK: true, + redisSetMasterOnAllOK: true, + bootstrapping: false, + allowSentinels: false, + disableMyMaster: true, + }, { name: "Sentinels not pointing correct monitor", nMasters: 1, @@ -162,6 +280,22 @@ func TestCheckAndHeal(t *testing.T) { bootstrapping: false, allowSentinels: false, }, + { + name: "Sentinels not pointing correct monitor w/ master name", + nMasters: 1, + nRedis: 3, + singleMasterTest: false, + forceNewMasterNoQrm: false, + forceNewMasterFirstBoot: false, + slavesOK: true, + sentinelMonitorOK: false, + sentinelNumberInMemoryOK: true, + sentinelSlavesNumberInMemoryOK: true, + redisCheckNumberOK: true, + redisSetMasterOnAllOK: true, + bootstrapping: false, + allowSentinels: false, + }, { name: "Sentinels with wrong number of sentinels", nMasters: 1, @@ -178,6 +312,23 @@ func TestCheckAndHeal(t *testing.T) { bootstrapping: false, allowSentinels: false, }, + { + name: "Sentinels with wrong number of sentinels w/ master name", + nMasters: 1, + nRedis: 3, + singleMasterTest: false, + forceNewMasterNoQrm: false, + forceNewMasterFirstBoot: false, + slavesOK: true, + sentinelMonitorOK: true, + sentinelNumberInMemoryOK: false, + sentinelSlavesNumberInMemoryOK: true, + redisCheckNumberOK: true, + redisSetMasterOnAllOK: true, + bootstrapping: false, + allowSentinels: false, + disableMyMaster: true, + }, { name: "Sentinels with wrong number of slaves", nMasters: 1, @@ -194,6 +345,23 @@ func TestCheckAndHeal(t *testing.T) { bootstrapping: false, allowSentinels: false, }, + { + name: "Sentinels with wrong number of slaves w/ master name", + nMasters: 1, + nRedis: 3, + singleMasterTest: false, + forceNewMasterNoQrm: false, + forceNewMasterFirstBoot: false, + slavesOK: true, + sentinelMonitorOK: true, + sentinelNumberInMemoryOK: true, + sentinelSlavesNumberInMemoryOK: false, + redisCheckNumberOK: true, + redisSetMasterOnAllOK: true, + bootstrapping: false, + allowSentinels: false, + disableMyMaster: true, + }, { name: "Bootstrapping Mode", nMasters: 1, @@ -203,6 +371,16 @@ func TestCheckAndHeal(t *testing.T) { bootstrapping: true, allowSentinels: false, }, + { + name: "Bootstrapping Mode w/ master name", + nMasters: 1, + nRedis: 3, + redisCheckNumberOK: true, + redisSetMasterOnAllOK: true, + bootstrapping: true, + allowSentinels: false, + disableMyMaster: true, + }, { name: "Bootstrapping Mode with failure to check redis number", nMasters: 1, @@ -212,6 +390,16 @@ func TestCheckAndHeal(t *testing.T) { bootstrapping: true, allowSentinels: false, }, + { + name: "Bootstrapping Mode with failure to check redis number w/ master name", + nMasters: 1, + nRedis: 3, + redisCheckNumberOK: false, + redisSetMasterOnAllOK: true, + bootstrapping: true, + allowSentinels: false, + disableMyMaster: true, + }, { name: "Bootstrapping Mode with failure to set master on all", nMasters: 1, @@ -221,6 +409,16 @@ func TestCheckAndHeal(t *testing.T) { bootstrapping: true, allowSentinels: false, }, + { + name: "Bootstrapping Mode with failure to set master on all w/ master name", + nMasters: 1, + nRedis: 3, + redisCheckNumberOK: true, + redisSetMasterOnAllOK: false, + bootstrapping: true, + allowSentinels: false, + disableMyMaster: true, + }, { name: "Bootstrapping Mode that allows sentinels", nMasters: 1, @@ -233,6 +431,19 @@ func TestCheckAndHeal(t *testing.T) { bootstrapping: true, allowSentinels: true, }, + { + name: "Bootstrapping Mode that allows sentinels w/ master name", + nMasters: 1, + nRedis: 3, + redisCheckNumberOK: true, + redisSetMasterOnAllOK: true, + sentinelMonitorOK: true, + sentinelNumberInMemoryOK: true, + sentinelSlavesNumberInMemoryOK: true, + bootstrapping: true, + allowSentinels: true, + disableMyMaster: true, + }, { name: "Bootstrapping Mode that allows sentinels sentinel monitor fails", nMasters: 1, @@ -245,6 +456,19 @@ func TestCheckAndHeal(t *testing.T) { bootstrapping: true, allowSentinels: true, }, + { + name: "Bootstrapping Mode that allows sentinels sentinel monitor fails w/ master name", + nMasters: 1, + nRedis: 3, + redisCheckNumberOK: true, + redisSetMasterOnAllOK: true, + sentinelMonitorOK: false, + sentinelNumberInMemoryOK: true, + sentinelSlavesNumberInMemoryOK: true, + bootstrapping: true, + allowSentinels: true, + disableMyMaster: true, + }, { name: "Bootstrapping Mode that allows sentinels sentinel with wrong number of sentinels", nMasters: 1, @@ -257,6 +481,19 @@ func TestCheckAndHeal(t *testing.T) { bootstrapping: true, allowSentinels: true, }, + { + name: "Bootstrapping Mode that allows sentinels sentinel with wrong number of sentinels w/ master name", + nMasters: 1, + nRedis: 3, + redisCheckNumberOK: true, + redisSetMasterOnAllOK: true, + sentinelMonitorOK: true, + sentinelNumberInMemoryOK: false, + sentinelSlavesNumberInMemoryOK: true, + bootstrapping: true, + allowSentinels: true, + disableMyMaster: true, + }, { name: "Bootstrapping Mode that allows sentinels sentinel with wrong number of slaves", nMasters: 1, @@ -269,6 +506,19 @@ func TestCheckAndHeal(t *testing.T) { bootstrapping: true, allowSentinels: true, }, + { + name: "Bootstrapping Mode that allows sentinels sentinel with wrong number of slaves w/ master name", + nMasters: 1, + nRedis: 3, + redisCheckNumberOK: true, + redisSetMasterOnAllOK: true, + sentinelMonitorOK: true, + sentinelNumberInMemoryOK: true, + sentinelSlavesNumberInMemoryOK: false, + bootstrapping: true, + allowSentinels: true, + disableMyMaster: true, + }, } for _, test := range tests { @@ -280,7 +530,7 @@ func TestCheckAndHeal(t *testing.T) { bootstrapMaster := "127.0.0.1" bootstrapMasterPort := "6379" - rf := generateRF(false, bootstrappingTests) + rf := generateRF(false, bootstrappingTests, test.disableMyMaster) if bootstrappingTests { allowSentinels = test.allowSentinels rf.Spec.BootstrapNode.AllowSentinels = allowSentinels @@ -387,16 +637,16 @@ func TestCheckAndHeal(t *testing.T) { mrfc.On("GetSentinelsIPs", rf).Once().Return([]string{sentinel}, nil) if test.sentinelMonitorOK { if test.bootstrapping { - mrfc.On("CheckSentinelMonitor", sentinel, bootstrapMaster, bootstrapMasterPort).Once().Return(nil) + mrfc.On("CheckSentinelMonitor", sentinel, rf.MasterName(), bootstrapMaster, bootstrapMasterPort).Once().Return(nil) } else { - mrfc.On("CheckSentinelMonitor", sentinel, master, "0").Once().Return(nil) + mrfc.On("CheckSentinelMonitor", sentinel, rf.MasterName(), master, "0").Once().Return(nil) } } else { if test.bootstrapping { - mrfc.On("CheckSentinelMonitor", sentinel, bootstrapMaster, bootstrapMasterPort).Once().Return(errors.New("")) + mrfc.On("CheckSentinelMonitor", sentinel, rf.MasterName(), bootstrapMaster, bootstrapMasterPort).Once().Return(errors.New("")) mrfh.On("NewSentinelMonitorWithPort", sentinel, bootstrapMaster, bootstrapMasterPort, rf).Once().Return(nil) } else { - mrfc.On("CheckSentinelMonitor", sentinel, master, "0").Once().Return(errors.New("")) + mrfc.On("CheckSentinelMonitor", sentinel, rf.MasterName(), master, "0").Once().Return(errors.New("")) mrfh.On("NewSentinelMonitor", sentinel, master, rf).Once().Return(nil) } } @@ -873,7 +1123,7 @@ func TestUpdate(t *testing.T) { t.Run(test.name, func(t *testing.T) { assert := assert.New(t) - rf := generateRF(false, test.bootstrapping) + rf := generateRF(false, test.bootstrapping, false) config := generateConfig() mrfs := &mRFService.RedisFailoverClient{} diff --git a/operator/redisfailover/ensurer_test.go b/operator/redisfailover/ensurer_test.go index 2b5bddc19..a4db6ae4d 100644 --- a/operator/redisfailover/ensurer_test.go +++ b/operator/redisfailover/ensurer_test.go @@ -27,7 +27,7 @@ func generateConfig() rfOperator.Config { } } -func generateRF(enableExporter bool, bootstrapping bool) *redisfailoverv1.RedisFailover { +func generateRF(enableExporter bool, bootstrapping bool, disableMyMaster bool) *redisfailoverv1.RedisFailover { return &redisfailoverv1.RedisFailover{ ObjectMeta: metav1.ObjectMeta{ Name: name, @@ -41,7 +41,8 @@ func generateRF(enableExporter bool, bootstrapping bool) *redisfailoverv1.RedisF }, }, Sentinel: redisfailoverv1.SentinelSettings{ - Replicas: int32(3), + Replicas: int32(3), + DisableMyMaster: disableMyMaster, }, BootstrapNode: generateRFBootstrappingNode(bootstrapping), }, @@ -95,7 +96,7 @@ func TestEnsure(t *testing.T) { t.Run(test.name, func(t *testing.T) { assert := assert.New(t) - rf := generateRF(test.exporter, test.bootstrapping) + rf := generateRF(test.exporter, test.bootstrapping, false) if test.bootstrapping { rf.Spec.BootstrapNode.AllowSentinels = test.bootstrappingAllowSentinels } diff --git a/operator/redisfailover/service/check_test.go b/operator/redisfailover/service/check_test.go index af64d7e13..e1957f5da 100644 --- a/operator/redisfailover/service/check_test.go +++ b/operator/redisfailover/service/check_test.go @@ -362,11 +362,11 @@ func TestCheckSentinelMonitorGetSentinelMonitorError(t *testing.T) { ms := &mK8SService.Services{} mr := &mRedisService.Client{} - mr.On("GetSentinelMonitor", "0.0.0.0").Once().Return("", "", errors.New("")) + mr.On("GetSentinelMonitor", "0.0.0.0", "mymaster").Once().Return("", "", errors.New("")) checker := rfservice.NewRedisFailoverChecker(ms, mr, log.DummyLogger{}, metrics.Dummy) - err := checker.CheckSentinelMonitor("0.0.0.0", "1.1.1.1") + err := checker.CheckSentinelMonitor("0.0.0.0", "mymaster", "1.1.1.1") assert.Error(err) } @@ -375,11 +375,11 @@ func TestCheckSentinelMonitorMismatch(t *testing.T) { ms := &mK8SService.Services{} mr := &mRedisService.Client{} - mr.On("GetSentinelMonitor", "0.0.0.0").Once().Return("2.2.2.2", "6379", nil) + mr.On("GetSentinelMonitor", "0.0.0.0", "mymaster").Once().Return("2.2.2.2", "6379", nil) checker := rfservice.NewRedisFailoverChecker(ms, mr, log.DummyLogger{}, metrics.Dummy) - err := checker.CheckSentinelMonitor("0.0.0.0", "1.1.1.1") + err := checker.CheckSentinelMonitor("0.0.0.0", "mymaster", "1.1.1.1") assert.Error(err) } @@ -388,11 +388,11 @@ func TestCheckSentinelMonitor(t *testing.T) { ms := &mK8SService.Services{} mr := &mRedisService.Client{} - mr.On("GetSentinelMonitor", "0.0.0.0").Once().Return("1.1.1.1", "6379", nil) + mr.On("GetSentinelMonitor", "0.0.0.0", "mymaster").Once().Return("1.1.1.1", "6379", nil) checker := rfservice.NewRedisFailoverChecker(ms, mr, log.DummyLogger{}, metrics.Dummy) - err := checker.CheckSentinelMonitor("0.0.0.0", "1.1.1.1") + err := checker.CheckSentinelMonitor("0.0.0.0", "mymaster", "1.1.1.1") assert.NoError(err) } @@ -401,11 +401,11 @@ func TestCheckSentinelMonitorWithPort(t *testing.T) { ms := &mK8SService.Services{} mr := &mRedisService.Client{} - mr.On("GetSentinelMonitor", "0.0.0.0").Once().Return("1.1.1.1", "6379", nil) + mr.On("GetSentinelMonitor", "0.0.0.0", "mymaster").Once().Return("1.1.1.1", "6379", nil) checker := rfservice.NewRedisFailoverChecker(ms, mr, log.DummyLogger{}, metrics.Dummy) - err := checker.CheckSentinelMonitor("0.0.0.0", "1.1.1.1", "6379") + err := checker.CheckSentinelMonitor("0.0.0.0", "mymaster", "1.1.1.1", "6379") assert.NoError(err) } @@ -414,11 +414,11 @@ func TestCheckSentinelMonitorWithPortMismatch(t *testing.T) { ms := &mK8SService.Services{} mr := &mRedisService.Client{} - mr.On("GetSentinelMonitor", "0.0.0.0").Once().Return("1.1.1.1", "6379", nil) + mr.On("GetSentinelMonitor", "0.0.0.0", "mymaster").Once().Return("1.1.1.1", "6379", nil) checker := rfservice.NewRedisFailoverChecker(ms, mr, log.DummyLogger{}, metrics.Dummy) - err := checker.CheckSentinelMonitor("0.0.0.0", "0.0.0.0", "6379") + err := checker.CheckSentinelMonitor("0.0.0.0", "mymaster", "0.0.0.0", "6379") assert.Error(err) } @@ -427,11 +427,11 @@ func TestCheckSentinelMonitorWithPortIPMismatch(t *testing.T) { ms := &mK8SService.Services{} mr := &mRedisService.Client{} - mr.On("GetSentinelMonitor", "0.0.0.0").Once().Return("1.1.1.1", "6379", nil) + mr.On("GetSentinelMonitor", "0.0.0.0", "mymaster").Once().Return("1.1.1.1", "6379", nil) checker := rfservice.NewRedisFailoverChecker(ms, mr, log.DummyLogger{}, metrics.Dummy) - err := checker.CheckSentinelMonitor("0.0.0.0", "1.1.1.1", "6380") + err := checker.CheckSentinelMonitor("0.0.0.0", "mymaster", "1.1.1.1", "6380") assert.Error(err) } diff --git a/operator/redisfailover/service/heal_test.go b/operator/redisfailover/service/heal_test.go index 27bd8cc11..e22821107 100644 --- a/operator/redisfailover/service/heal_test.go +++ b/operator/redisfailover/service/heal_test.go @@ -375,9 +375,9 @@ func TestNewSentinelMonitor(t *testing.T) { if test.errorOnMonitorRedis { errorExpected = true - mr.On("MonitorRedisWithPort", "0.0.0.0", "1.1.1.1", "0", "2", "").Once().Return(errors.New("")) + mr.On("MonitorRedisWithPort", "0.0.0.0", "1.1.1.1", "0", "2", "", "mymaster").Once().Return(errors.New("")) } else { - mr.On("MonitorRedisWithPort", "0.0.0.0", "1.1.1.1", "0", "2", "").Once().Return(nil) + mr.On("MonitorRedisWithPort", "0.0.0.0", "1.1.1.1", "0", "2", "", "mymaster").Once().Return(nil) } healer := rfservice.NewRedisFailoverHealer(ms, mr, log.DummyLogger{}) @@ -419,9 +419,9 @@ func TestNewSentinelMonitorWithPort(t *testing.T) { if test.errorOnMonitorRedis { errorExpected = true - mr.On("MonitorRedisWithPort", "0.0.0.0", "1.1.1.1", "6379", "2", "").Once().Return(errors.New("")) + mr.On("MonitorRedisWithPort", "0.0.0.0", "1.1.1.1", "6379", "2", "", "mymaster").Once().Return(errors.New("")) } else { - mr.On("MonitorRedisWithPort", "0.0.0.0", "1.1.1.1", "6379", "2", "").Once().Return(nil) + mr.On("MonitorRedisWithPort", "0.0.0.0", "1.1.1.1", "6379", "2", "", "mymaster").Once().Return(nil) } healer := rfservice.NewRedisFailoverHealer(ms, mr, log.DummyLogger{}) diff --git a/test/integration/redisfailover/creation_test.go b/test/integration/redisfailover/creation_test.go index 5458634ba..f68a07ead 100644 --- a/test/integration/redisfailover/creation_test.go +++ b/test/integration/redisfailover/creation_test.go @@ -246,7 +246,7 @@ func (c *clients) testSentinelMonitoring(t *testing.T) { for _, pod := range sentinelPodList.Items { ip := pod.Status.PodIP - master, _, _ := c.redisClient.GetSentinelMonitor(ip) + master, _, _ := c.redisClient.GetSentinelMonitor(ip, "mymaster") masters = append(masters, master) } From 5179d27769372e42a2c8f36f224a880152eac8aa Mon Sep 17 00:00:00 2001 From: M Samuel Vijaykumar Date: Sat, 31 Aug 2024 09:18:00 +0530 Subject: [PATCH 03/14] Adding changes where there are references to mymaster --- example/redisfailover/disable-mymaster.yaml | 23 ++++++++++++++++++++ operator/redisfailover/service/check_test.go | 12 ++++++++-- operator/redisfailover/service/generator.go | 16 +++++++++++--- 3 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 example/redisfailover/disable-mymaster.yaml diff --git a/example/redisfailover/disable-mymaster.yaml b/example/redisfailover/disable-mymaster.yaml new file mode 100644 index 000000000..1f913fbf7 --- /dev/null +++ b/example/redisfailover/disable-mymaster.yaml @@ -0,0 +1,23 @@ +apiVersion: databases.spotahome.com/v1 +kind: RedisFailover +metadata: + name: redisfailover + namespace: disable-mymaster +spec: + sentinel: + replicas: 3 + resources: + requests: + cpu: 100m + limits: + memory: 100Mi + disableMyMaster: true + redis: + replicas: 3 + resources: + requests: + cpu: 100m + memory: 100Mi + limits: + cpu: 400m + memory: 500Mi diff --git a/operator/redisfailover/service/check_test.go b/operator/redisfailover/service/check_test.go index e1957f5da..4ff62a636 100644 --- a/operator/redisfailover/service/check_test.go +++ b/operator/redisfailover/service/check_test.go @@ -20,7 +20,14 @@ import ( rfservice "github.com/spotahome/redis-operator/operator/redisfailover/service" ) -func generateRF() *redisfailoverv1.RedisFailover { +func generateRF(args ...bool) *redisfailoverv1.RedisFailover { + var disableMyMaster bool + if len(args) > 0 { + disableMyMaster = args[0] + } else { + disableMyMaster = false + } + return &redisfailoverv1.RedisFailover{ ObjectMeta: metav1.ObjectMeta{ Name: name, @@ -31,7 +38,8 @@ func generateRF() *redisfailoverv1.RedisFailover { Replicas: int32(3), }, Sentinel: redisfailoverv1.SentinelSettings{ - Replicas: int32(3), + Replicas: int32(3), + DisableMyMaster: disableMyMaster, }, }, } diff --git a/operator/redisfailover/service/generator.go b/operator/redisfailover/service/generator.go index f82eaab9a..f3dfa06d6 100644 --- a/operator/redisfailover/service/generator.go +++ b/operator/redisfailover/service/generator.go @@ -31,10 +31,19 @@ rename-command "{{.From}}" "{{.To}}" {{- end}} ` - sentinelConfigTemplate = `sentinel monitor mymaster 127.0.0.1 {{.Spec.Redis.Port}} 2 + sentinelConfigTemplate = ` +{{- if .Spec.Sentinel.DisableMyMaster -}} +sentinel monitor {{.Name}} 127.0.0.1 {{.Spec.Redis.Port}} 2 +sentinel down-after-milliseconds {{.Name}} 1000 +sentinel failover-timeout {{.Name}} 3000 +sentinel parallel-syncs {{.Name}} 2 +{{- else -}} +sentinel monitor mymaster 127.0.0.1 {{.Spec.Redis.Port}} 2 sentinel down-after-milliseconds mymaster 1000 sentinel failover-timeout mymaster 3000 -sentinel parallel-syncs mymaster 2` +sentinel parallel-syncs mymaster 2 +{{- end -}} +` redisShutdownConfigurationVolumeName = "redis-shutdown-config" redisStartupConfigurationVolumeName = "redis-startup-config" @@ -625,6 +634,7 @@ func generateSentinelDeployment(rf *redisfailoverv1.RedisFailover, labels map[st if rf.Spec.Sentinel.CustomReadinessProbe != nil { sd.Spec.Template.Spec.Containers[0].ReadinessProbe = rf.Spec.Sentinel.CustomReadinessProbe } else { + probeCommand := fmt.Sprintf("redis-cli -h $(hostname) -p 26379 sentinel get-master-addr-by-name %s | head -n 1 | grep -vq '127.0.0.1'", rf.MasterName()) sd.Spec.Template.Spec.Containers[0].ReadinessProbe = &corev1.Probe{ InitialDelaySeconds: graceTime, TimeoutSeconds: 5, @@ -633,7 +643,7 @@ func generateSentinelDeployment(rf *redisfailoverv1.RedisFailover, labels map[st Command: []string{ "sh", "-c", - "redis-cli -h $(hostname) -p 26379 sentinel get-master-addr-by-name mymaster | head -n 1 | grep -vq '127.0.0.1'", + probeCommand, }, }, }, From c44f4be4f1036fb8ffd71479b885a1dd903f05aa Mon Sep 17 00:00:00 2001 From: M Samuel Vijaykumar Date: Sat, 31 Aug 2024 09:34:06 +0530 Subject: [PATCH 04/14] Update README of this change. --- README.md | 32 ++++++++++++++++++++++++++++++++ example/redisfailover/basic.yaml | 1 + 2 files changed, 33 insertions(+) diff --git a/README.md b/README.md index 4ae79cbca..c4c1efc96 100644 --- a/README.md +++ b/README.md @@ -187,6 +187,38 @@ By default, no service annotations will be applied to the Redis nor Sentinel ser In order to apply custom service Annotations, you can provide the `serviceAnnotations` option inside redis/sentinel spec. An example can be found in the [custom annotations example file](example/redisfailover/custom-annotations.yaml). +### Disable `mymaster` in Sentinel Cluster Management + +By default the sentinel identifies the cluster with `mymaster`, due to the ephemeral nature of Kubernetes. There is a high likelihood of the colliding the sentinel across redisfailover deployments. To avoid this we can set the `disableMyMaster` to `false` under the `sentinel` specification. + +``` +apiVersion: databases.spotahome.com/v1 +kind: RedisFailover +metadata: + name: redisfailover + namespace: disable-mymaster +spec: + sentinel: + replicas: 3 + resources: + requests: + cpu: 100m + limits: + memory: 100Mi + disableMyMaster: true + redis: + replicas: 3 + resources: + requests: + cpu: 100m + memory: 100Mi + limits: + cpu: 400m + memory: 500Mi +``` + +So this will use the name of the redisfailover object and use that instead of `mymaster`. Yes, if you have multiple same redisfailover names across namesapces, you would still run into collision, so please ensure they are not. + ### Control of label propagation. By default the operator will propagate all labels on the CRD down to the resources that it creates. This can be problematic if the labels on the CRD are not fully under your own control (for example: being deployed by a gitops operator) diff --git a/example/redisfailover/basic.yaml b/example/redisfailover/basic.yaml index c3ebb1f3a..ccb3c6c9e 100644 --- a/example/redisfailover/basic.yaml +++ b/example/redisfailover/basic.yaml @@ -2,6 +2,7 @@ apiVersion: databases.spotahome.com/v1 kind: RedisFailover metadata: name: redisfailover + namespace: basic spec: sentinel: replicas: 3 From 370dae532f4b4b4fe94649bb4fe613c8a38b2cd2 Mon Sep 17 00:00:00 2001 From: M Samuel Vijaykumar Date: Mon, 2 Sep 2024 11:39:08 +0530 Subject: [PATCH 05/14] Missed to update the shutdowd.sh --- operator/redisfailover/service/generator.go | 37 +++++++++++++++------ 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/operator/redisfailover/service/generator.go b/operator/redisfailover/service/generator.go index f3dfa06d6..b811e97fa 100644 --- a/operator/redisfailover/service/generator.go +++ b/operator/redisfailover/service/generator.go @@ -251,23 +251,38 @@ func generateRedisConfigMap(rf *redisfailoverv1.RedisFailover, labels map[string } func generateRedisShutdownConfigMap(rf *redisfailoverv1.RedisFailover, labels map[string]string, ownerRefs []metav1.OwnerReference) *corev1.ConfigMap { + var shutdownContent string name := GetRedisShutdownConfigMapName(rf) port := rf.Spec.Redis.Port namespace := rf.Namespace rfName := strings.Replace(strings.ToUpper(rf.Name), "-", "_", -1) labels = util.MergeLabels(labels, generateSelectorLabels(redisRoleName, rf.Name)) - shutdownContent := fmt.Sprintf(`master=$(redis-cli -h ${RFS_%[1]v_SERVICE_HOST} -p ${RFS_%[1]v_SERVICE_PORT_SENTINEL} --csv SENTINEL get-master-addr-by-name mymaster | tr ',' ' ' | tr -d '\"' |cut -d' ' -f1) -if [ "$master" = "$(hostname -i)" ]; then - redis-cli -h ${RFS_%[1]v_SERVICE_HOST} -p ${RFS_%[1]v_SERVICE_PORT_SENTINEL} SENTINEL failover mymaster - sleep 31 -fi -cmd="redis-cli -p %[2]v" -if [ ! -z "${REDIS_PASSWORD}" ]; then - export REDISCLI_AUTH=${REDIS_PASSWORD} -fi -save_command="${cmd} save" -eval $save_command`, rfName, port) + if rf.Spec.Sentinel.DisableMyMaster { + shutdownContent = fmt.Sprintf(`master=$(redis-cli -h ${RFS_%[1]v_SERVICE_HOST} -p ${RFS_%[1]v_SERVICE_PORT_SENTINEL} --csv SENTINEL get-master-addr-by-name mymaster | tr ',' ' ' | tr -d '\"' |cut -d' ' -f1) + if [ "$master" = "$(hostname -i)" ]; then + redis-cli -h ${RFS_%[1]v_SERVICE_HOST} -p ${RFS_%[1]v_SERVICE_PORT_SENTINEL} SENTINEL failover mymaster + sleep 31 + fi + cmd="redis-cli -p %[2]v" + if [ ! -z "${REDIS_PASSWORD}" ]; then + export REDISCLI_AUTH=${REDIS_PASSWORD} + fi + save_command="${cmd} save" + eval $save_command`, rfName, port) + } else { + shutdownContent = fmt.Sprintf(`master=$(redis-cli -h ${RFS_%[1]v_SERVICE_HOST} -p ${RFS_%[1]v_SERVICE_PORT_SENTINEL} --csv SENTINEL get-master-addr-by-name %[1]v | tr ',' ' ' | tr -d '\"' |cut -d' ' -f1) + if [ "$master" = "$(hostname -i)" ]; then + redis-cli -h ${RFS_%[1]v_SERVICE_HOST} -p ${RFS_%[1]v_SERVICE_PORT_SENTINEL} SENTINEL failover %[1]v + sleep 31 + fi + cmd="redis-cli -p %[2]v" + if [ ! -z "${REDIS_PASSWORD}" ]; then + export REDISCLI_AUTH=${REDIS_PASSWORD} + fi + save_command="${cmd} save" + eval $save_command`, rfName, port) + } return &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ From f5bda6e90e3b28a6b95d66cdb8b150edd3cab22a Mon Sep 17 00:00:00 2001 From: M Samuel Vijaykumar Date: Mon, 2 Sep 2024 12:37:28 +0530 Subject: [PATCH 06/14] Remove if clause and use functions to get the master name --- operator/redisfailover/service/generator.go | 37 ++++++--------------- 1 file changed, 11 insertions(+), 26 deletions(-) diff --git a/operator/redisfailover/service/generator.go b/operator/redisfailover/service/generator.go index b811e97fa..b59c62a7d 100644 --- a/operator/redisfailover/service/generator.go +++ b/operator/redisfailover/service/generator.go @@ -251,38 +251,23 @@ func generateRedisConfigMap(rf *redisfailoverv1.RedisFailover, labels map[string } func generateRedisShutdownConfigMap(rf *redisfailoverv1.RedisFailover, labels map[string]string, ownerRefs []metav1.OwnerReference) *corev1.ConfigMap { - var shutdownContent string name := GetRedisShutdownConfigMapName(rf) port := rf.Spec.Redis.Port namespace := rf.Namespace rfName := strings.Replace(strings.ToUpper(rf.Name), "-", "_", -1) labels = util.MergeLabels(labels, generateSelectorLabels(redisRoleName, rf.Name)) - if rf.Spec.Sentinel.DisableMyMaster { - shutdownContent = fmt.Sprintf(`master=$(redis-cli -h ${RFS_%[1]v_SERVICE_HOST} -p ${RFS_%[1]v_SERVICE_PORT_SENTINEL} --csv SENTINEL get-master-addr-by-name mymaster | tr ',' ' ' | tr -d '\"' |cut -d' ' -f1) - if [ "$master" = "$(hostname -i)" ]; then - redis-cli -h ${RFS_%[1]v_SERVICE_HOST} -p ${RFS_%[1]v_SERVICE_PORT_SENTINEL} SENTINEL failover mymaster - sleep 31 - fi - cmd="redis-cli -p %[2]v" - if [ ! -z "${REDIS_PASSWORD}" ]; then - export REDISCLI_AUTH=${REDIS_PASSWORD} - fi - save_command="${cmd} save" - eval $save_command`, rfName, port) - } else { - shutdownContent = fmt.Sprintf(`master=$(redis-cli -h ${RFS_%[1]v_SERVICE_HOST} -p ${RFS_%[1]v_SERVICE_PORT_SENTINEL} --csv SENTINEL get-master-addr-by-name %[1]v | tr ',' ' ' | tr -d '\"' |cut -d' ' -f1) - if [ "$master" = "$(hostname -i)" ]; then - redis-cli -h ${RFS_%[1]v_SERVICE_HOST} -p ${RFS_%[1]v_SERVICE_PORT_SENTINEL} SENTINEL failover %[1]v - sleep 31 - fi - cmd="redis-cli -p %[2]v" - if [ ! -z "${REDIS_PASSWORD}" ]; then - export REDISCLI_AUTH=${REDIS_PASSWORD} - fi - save_command="${cmd} save" - eval $save_command`, rfName, port) - } + shutdownContent := fmt.Sprintf(`master=$(redis-cli -h ${RFS_%[1]v_SERVICE_HOST} -p ${RFS_%[1]v_SERVICE_PORT_SENTINEL} --csv SENTINEL get-master-addr-by-name %[3]v | tr ',' ' ' | tr -d '\"' |cut -d' ' -f1) +if [ "$master" = "$(hostname -i)" ]; then +redis-cli -h ${RFS_%[1]v_SERVICE_HOST} -p ${RFS_%[1]v_SERVICE_PORT_SENTINEL} SENTINEL failover %[3]v +sleep 31 +fi +cmd="redis-cli -p %[2]v" +if [ ! -z "${REDIS_PASSWORD}" ]; then + export REDISCLI_AUTH=${REDIS_PASSWORD} +fi +save_command="${cmd} save" +eval $save_command`, rfName, port, rf.MasterName()) return &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ From 8a6353c92080ac1b688b07a8e1c07af608d1eb40 Mon Sep 17 00:00:00 2001 From: M Samuel Vijaykumar Date: Tue, 3 Sep 2024 14:53:50 +0530 Subject: [PATCH 07/14] Adding tests --- api/redisfailover/v1/validate_test.go | 2 +- operator/redisfailover/service/check_test.go | 45 +++++--- .../redisfailover/service/generator_test.go | 106 ++++++++++++++++++ 3 files changed, 135 insertions(+), 18 deletions(-) diff --git a/api/redisfailover/v1/validate_test.go b/api/redisfailover/v1/validate_test.go index 30eede285..ac97f2ce6 100644 --- a/api/redisfailover/v1/validate_test.go +++ b/api/redisfailover/v1/validate_test.go @@ -38,7 +38,7 @@ func TestValidate(t *testing.T) { expectedError: "BootstrapNode must include a host when provided", }, { - name: "SentinelCustomConfig provided", + name: "SentinelCustomConfig not provided", rfName: "test", }, { diff --git a/operator/redisfailover/service/check_test.go b/operator/redisfailover/service/check_test.go index 4ff62a636..5c0bba581 100644 --- a/operator/redisfailover/service/check_test.go +++ b/operator/redisfailover/service/check_test.go @@ -21,28 +21,39 @@ import ( ) func generateRF(args ...bool) *redisfailoverv1.RedisFailover { - var disableMyMaster bool if len(args) > 0 { - disableMyMaster = args[0] + return &redisfailoverv1.RedisFailover{ + ObjectMeta: metav1.ObjectMeta{ + Name: name, + Namespace: namespace, + }, + Spec: redisfailoverv1.RedisFailoverSpec{ + Redis: redisfailoverv1.RedisSettings{ + Replicas: int32(3), + }, + Sentinel: redisfailoverv1.SentinelSettings{ + Replicas: int32(3), + DisableMyMaster: args[0], + }, + }, + } } else { - disableMyMaster = false - } - - return &redisfailoverv1.RedisFailover{ - ObjectMeta: metav1.ObjectMeta{ - Name: name, - Namespace: namespace, - }, - Spec: redisfailoverv1.RedisFailoverSpec{ - Redis: redisfailoverv1.RedisSettings{ - Replicas: int32(3), + return &redisfailoverv1.RedisFailover{ + ObjectMeta: metav1.ObjectMeta{ + Name: name, + Namespace: namespace, }, - Sentinel: redisfailoverv1.SentinelSettings{ - Replicas: int32(3), - DisableMyMaster: disableMyMaster, + Spec: redisfailoverv1.RedisFailoverSpec{ + Redis: redisfailoverv1.RedisSettings{ + Replicas: int32(3), + }, + Sentinel: redisfailoverv1.SentinelSettings{ + Replicas: int32(3), + }, }, - }, + } } + } func TestCheckRedisNumberError(t *testing.T) { diff --git a/operator/redisfailover/service/generator_test.go b/operator/redisfailover/service/generator_test.go index b14317072..a49f1f9cd 100644 --- a/operator/redisfailover/service/generator_test.go +++ b/operator/redisfailover/service/generator_test.go @@ -2792,3 +2792,109 @@ func TestSentinelCustomStartupProbe(t *testing.T) { assert.Equal(test.expectedStartupProbe, startupProbe) } } + +func TestDisableMyMaster(t *testing.T) { + tests := []struct { + name string + disableMyMaster bool + expectedSentinelReadinessProbe *corev1.Probe + redisShutdownSHScriptConfigMap *corev1.ConfigMap + sentinelConfConfigMap *corev1.ConfigMap + expectedSentinelConfConfigMap *corev1.ConfigMap + expectedRedisShutdownSHScriptConfigMap *corev1.ConfigMap + }{ + { + name: "disable_mymaster_false", + disableMyMaster: false, + expectedSentinelReadinessProbe: &corev1.Probe{ + InitialDelaySeconds: 30, + TimeoutSeconds: 5, + ProbeHandler: corev1.ProbeHandler{ + Exec: &corev1.ExecAction{ + Command: []string{ + "sh", + "-c", + "redis-cli -h $(hostname) -p 26379 sentinel get-master-addr-by-name mymaster | head -n 1 | grep -vq '127.0.0.1'", + }, + }, + }, + }, + expectedSentinelConfConfigMap: &corev1.ConfigMap{ + Data: map[string]string{ + "sentinel.conf": "sentinel monitor mymaster 127.0.0.1 0 2\nsentinel down-after-milliseconds mymaster 1000\nsentinel failover-timeout mymaster 3000\nsentinel parallel-syncs mymaster 2", + }, + }, + expectedRedisShutdownSHScriptConfigMap: &corev1.ConfigMap{ + Data: map[string]string{ + "shutdown.sh": "master=$(redis-cli -h ${RFS_TEST_SERVICE_HOST} -p ${RFS_TEST_SERVICE_PORT_SENTINEL} --csv SENTINEL get-master-addr-by-name mymaster | tr ',' ' ' | tr -d '\\\"' |cut -d' ' -f1)\nif [ \"$master\" = \"$(hostname -i)\" ]; then\nredis-cli -h ${RFS_TEST_SERVICE_HOST} -p ${RFS_TEST_SERVICE_PORT_SENTINEL} SENTINEL failover mymaster\nsleep 31\nfi\ncmd=\"redis-cli -p 0\"\nif [ ! -z \"${REDIS_PASSWORD}\" ]; then\n\texport REDISCLI_AUTH=${REDIS_PASSWORD}\nfi\nsave_command=\"${cmd} save\"\neval $save_command", + }, + }, + }, + { + name: "disable_mymaster_true", + disableMyMaster: true, + expectedSentinelReadinessProbe: &corev1.Probe{ + InitialDelaySeconds: 30, + TimeoutSeconds: 5, + ProbeHandler: corev1.ProbeHandler{ + Exec: &corev1.ExecAction{ + Command: []string{ + "sh", + "-c", + "redis-cli -h $(hostname) -p 26379 sentinel get-master-addr-by-name test | head -n 1 | grep -vq '127.0.0.1'", + }, + }, + }, + }, + expectedSentinelConfConfigMap: &corev1.ConfigMap{ + Data: map[string]string{ + "sentinel.conf": "sentinel monitor test 127.0.0.1 0 2\nsentinel down-after-milliseconds test 1000\nsentinel failover-timeout test 3000\nsentinel parallel-syncs test 2", + }, + }, + expectedRedisShutdownSHScriptConfigMap: &corev1.ConfigMap{ + Data: map[string]string{ + "shutdown.sh": "master=$(redis-cli -h ${RFS_TEST_SERVICE_HOST} -p ${RFS_TEST_SERVICE_PORT_SENTINEL} --csv SENTINEL get-master-addr-by-name test | tr ',' ' ' | tr -d '\\\"' |cut -d' ' -f1)\nif [ \"$master\" = \"$(hostname -i)\" ]; then\nredis-cli -h ${RFS_TEST_SERVICE_HOST} -p ${RFS_TEST_SERVICE_PORT_SENTINEL} SENTINEL failover test\nsleep 31\nfi\ncmd=\"redis-cli -p 0\"\nif [ ! -z \"${REDIS_PASSWORD}\" ]; then\n\texport REDISCLI_AUTH=${REDIS_PASSWORD}\nfi\nsave_command=\"${cmd} save\"\neval $save_command", + }, + }, + }, + } + for _, test := range tests { + assert := assert.New(t) + + var sentinelReadinessProbe *corev1.Probe + rf := generateRF(test.disableMyMaster) + // redisShutdownSHSriptConfigMap := rfservice.generateRedisShutdownConfigMap(rf) + + ms := &mK8SService.Services{} + ms.On("CreateOrUpdatePodDisruptionBudget", namespace, mock.Anything).Once().Return(nil, nil) + ms.On("CreateOrUpdateDeployment", namespace, mock.Anything).Once().Run(func(args mock.Arguments) { + d := args.Get(1).(*appsv1.Deployment) + sentinelReadinessProbe = d.Spec.Template.Spec.Containers[0].ReadinessProbe + }).Return(nil) + + client := rfservice.NewRedisFailoverKubeClient(ms, log.Dummy, metrics.Dummy) + err := client.EnsureSentinelDeployment(rf, nil, []metav1.OwnerReference{}) + assert.NoError(err) + assert.Equal(test.expectedSentinelReadinessProbe, sentinelReadinessProbe) + + generatedSentinelConfigMap := corev1.ConfigMap{} + ms.On("CreateOrUpdateConfigMap", namespace, mock.Anything).Once().Run(func(args mock.Arguments) { + cms := args.Get(1).(*corev1.ConfigMap) + generatedSentinelConfigMap = *cms + }).Return(nil) + + err = client.EnsureSentinelConfigMap(rf, nil, []metav1.OwnerReference{}) + assert.NoError(err) + assert.Equal(test.expectedSentinelConfConfigMap.Data, generatedSentinelConfigMap.Data) + + generatedRedisConfigMap := corev1.ConfigMap{} + ms.On("CreateOrUpdateConfigMap", namespace, mock.Anything).Once().Run(func(args mock.Arguments) { + cmr := args.Get(1).(*corev1.ConfigMap) + generatedRedisConfigMap = *cmr + }).Return(nil) + + err = client.EnsureRedisShutdownConfigMap(rf, nil, []metav1.OwnerReference{}) + assert.NoError(err) + assert.Equal(test.expectedRedisShutdownSHScriptConfigMap.Data, generatedRedisConfigMap.Data) + } +} From 4ecc159ecc3783377c56ae34cca2975393807a7a Mon Sep 17 00:00:00 2001 From: M Samuel Vijaykumar Date: Tue, 3 Sep 2024 22:58:03 +0530 Subject: [PATCH 08/14] Checking the ability to use the masterName --- .../redisfailover/creation_test.go | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/test/integration/redisfailover/creation_test.go b/test/integration/redisfailover/creation_test.go index f68a07ead..81089588c 100644 --- a/test/integration/redisfailover/creation_test.go +++ b/test/integration/redisfailover/creation_test.go @@ -161,7 +161,11 @@ func TestRedisFailover(t *testing.T) { t.Run("Check Sentinels Checking the Redis Master", clients.testSentinelMonitoring) } -func (c *clients) testCRCreation(t *testing.T) { +func (c *clients) testCRCreation(t *testing.T, args ...bool) { + disableMyMaster := false + if len(args) > 0 && args[0] { + disableMyMaster = args[0] + } assert := assert.New(t) toCreate := &redisfailoverv1.RedisFailover{ ObjectMeta: metav1.ObjectMeta{ @@ -177,7 +181,8 @@ func (c *clients) testCRCreation(t *testing.T) { CustomConfig: []string{`save ""`}, }, Sentinel: redisfailoverv1.SentinelSettings{ - Replicas: sentinelSize, + Replicas: sentinelSize, + DisableMyMaster: disableMyMaster, }, Auth: redisfailoverv1.AuthSettings{ SecretPath: authSecretPath, @@ -231,7 +236,17 @@ func (c *clients) testRedisMaster(t *testing.T) { assert.Equal(1, len(masters), "only one master expected") } -func (c *clients) testSentinelMonitoring(t *testing.T) { +func (c *clients) testSentinelMonitoring(t *testing.T, args ...bool) { + disableMyMaster := false + if len(args) > 0 { + disableMyMaster = args[0] + } + + masterName := "mymaster" + if disableMyMaster { + masterName = name + } + assert := assert.New(t) masters := []string{} @@ -246,7 +261,7 @@ func (c *clients) testSentinelMonitoring(t *testing.T) { for _, pod := range sentinelPodList.Items { ip := pod.Status.PodIP - master, _, _ := c.redisClient.GetSentinelMonitor(ip, "mymaster") + master, _, _ := c.redisClient.GetSentinelMonitor(ip, masterName) masters = append(masters, master) } From 77bd5e601f13e2668f8d4d7e6b166e6e978910f9 Mon Sep 17 00:00:00 2001 From: M Samuel Vijaykumar Date: Tue, 3 Sep 2024 23:04:05 +0530 Subject: [PATCH 09/14] Fixing an error in the integration tests --- test/integration/redisfailover/creation_test.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/integration/redisfailover/creation_test.go b/test/integration/redisfailover/creation_test.go index 81089588c..8d637fe4a 100644 --- a/test/integration/redisfailover/creation_test.go +++ b/test/integration/redisfailover/creation_test.go @@ -131,7 +131,9 @@ func TestRedisFailover(t *testing.T) { require.NoError(err) // Check that if we create a RedisFailover, it is certainly created and we can get it - ok := t.Run("Check Custom Resource Creation", clients.testCRCreation) + ok := t.Run("Check Custom Resource Creation", func(t *testing.T) { + clients.testCRCreation(t) + }) require.True(ok, "the custom resource has to be created to continue") // Giving time to the operator to create the resources @@ -158,7 +160,9 @@ func TestRedisFailover(t *testing.T) { // Connect to all the Sentinel pods and, asking to the Sentinel running inside them, // check that all of them are connected to the same Redis node, and also that that node // is the master. - t.Run("Check Sentinels Checking the Redis Master", clients.testSentinelMonitoring) + t.Run("Check Sentinels Checking the Redis Master", func(t *testing.T) { + clients.testSentinelMonitoring(t) + }) } func (c *clients) testCRCreation(t *testing.T, args ...bool) { From 61d2ee383d4b4c3e5589e5df41c8544b473d16ea Mon Sep 17 00:00:00 2001 From: M Samuel Vijaykumar Date: Tue, 3 Sep 2024 23:10:41 +0530 Subject: [PATCH 10/14] test disableMyMaster true --- test/integration/redisfailover/creation_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/integration/redisfailover/creation_test.go b/test/integration/redisfailover/creation_test.go index 8d637fe4a..cc15333af 100644 --- a/test/integration/redisfailover/creation_test.go +++ b/test/integration/redisfailover/creation_test.go @@ -69,6 +69,7 @@ func (c *clients) cleanup(stopC chan struct{}) { func TestRedisFailover(t *testing.T) { require := require.New(t) + disableMyMaster := true // Create signal channels. stopC := make(chan struct{}) @@ -132,7 +133,7 @@ func TestRedisFailover(t *testing.T) { // Check that if we create a RedisFailover, it is certainly created and we can get it ok := t.Run("Check Custom Resource Creation", func(t *testing.T) { - clients.testCRCreation(t) + clients.testCRCreation(t, disableMyMaster) }) require.True(ok, "the custom resource has to be created to continue") @@ -161,7 +162,7 @@ func TestRedisFailover(t *testing.T) { // check that all of them are connected to the same Redis node, and also that that node // is the master. t.Run("Check Sentinels Checking the Redis Master", func(t *testing.T) { - clients.testSentinelMonitoring(t) + clients.testSentinelMonitoring(t, disableMyMaster) }) } From f5dae86104b2f4f82841dc5654cdd3364bdf4ced Mon Sep 17 00:00:00 2001 From: M Samuel Vijaykumar Date: Tue, 3 Sep 2024 23:18:52 +0530 Subject: [PATCH 11/14] Test case for mymaster --- .../redisfailover/creation_test.go | 99 +++++++++++++++++++ 1 file changed, 99 insertions(+) diff --git a/test/integration/redisfailover/creation_test.go b/test/integration/redisfailover/creation_test.go index cc15333af..2856f0393 100644 --- a/test/integration/redisfailover/creation_test.go +++ b/test/integration/redisfailover/creation_test.go @@ -166,6 +166,105 @@ func TestRedisFailover(t *testing.T) { }) } +func TestRedisFailoverMyMaster(t *testing.T) { + require := require.New(t) + disableMyMaster := false + + // Create signal channels. + stopC := make(chan struct{}) + errC := make(chan error) + + flags := &utils.CMDFlags{ + KubeConfig: filepath.Join(homedir.HomeDir(), ".kube", "config"), + Development: true, + } + + // Kubernetes clients. + k8sClient, customClient, aeClientset, err := utils.CreateKubernetesClients(flags) + require.NoError(err) + + // Create the redis clients + redisClient := redis.New(metrics.Dummy) + + clients := clients{ + k8sClient: k8sClient, + rfClient: customClient, + aeClient: aeClientset, + redisClient: redisClient, + } + + // Create kubernetes service. + k8sservice := k8s.New(k8sClient, customClient, aeClientset, log.Dummy, metrics.Dummy) + + // Prepare namespace + prepErr := clients.prepareNS() + require.NoError(prepErr) + + // Give time to the namespace to be ready + time.Sleep(15 * time.Second) + + // Create operator and run. + redisfailoverOperator, err := redisfailover.New(redisfailover.Config{}, k8sservice, k8sClient, namespace, redisClient, metrics.Dummy, log.Dummy) + require.NoError(err) + + go func() { + errC <- redisfailoverOperator.Run(context.Background()) + }() + + // Prepare cleanup for when the test ends + defer clients.cleanup(stopC) + + // Give time to the operator to start + time.Sleep(15 * time.Second) + + // Create secret + secret := &v1.Secret{ + ObjectMeta: metav1.ObjectMeta{ + Name: authSecretPath, + Namespace: namespace, + }, + Data: map[string][]byte{ + "password": []byte(testPass), + }, + } + _, err = k8sClient.CoreV1().Secrets(namespace).Create(context.Background(), secret, metav1.CreateOptions{}) + require.NoError(err) + + // Check that if we create a RedisFailover, it is certainly created and we can get it + ok := t.Run("Check Custom Resource Creation", func(t *testing.T) { + clients.testCRCreation(t, disableMyMaster) + }) + require.True(ok, "the custom resource has to be created to continue") + + // Giving time to the operator to create the resources + time.Sleep(3 * time.Minute) + + // 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) + + // Check that a Sentinel Deployment is created and the size of it is the one defined by the + // Redis Failover definition created before. + t.Run("Check Sentinel Deployment existing and size", clients.testSentinelDeployment) + + // Connect to all the Redis pods and, asking to the Redis running inside them, check + // that only one of them is the master of the failover. + t.Run("Check Only One Redis Master", clients.testRedisMaster) + + // Connect to all the Sentinel pods and, asking to the Sentinel running inside them, + // check that all of them are connected to the same Redis node, and also that that node + // is the master. + t.Run("Check Sentinels Checking the Redis Master", func(t *testing.T) { + clients.testSentinelMonitoring(t, disableMyMaster) + }) +} + func (c *clients) testCRCreation(t *testing.T, args ...bool) { disableMyMaster := false if len(args) > 0 && args[0] { From 919bc681d99fe8b1210de77a886c5d78b3083271 Mon Sep 17 00:00:00 2001 From: M Samuel Vijaykumar Date: Tue, 3 Sep 2024 23:48:56 +0530 Subject: [PATCH 12/14] Testing with different namespaces --- .../redisfailover/creation_test.go | 114 +++++++++++------- 1 file changed, 68 insertions(+), 46 deletions(-) diff --git a/test/integration/redisfailover/creation_test.go b/test/integration/redisfailover/creation_test.go index 2856f0393..c33825aa7 100644 --- a/test/integration/redisfailover/creation_test.go +++ b/test/integration/redisfailover/creation_test.go @@ -37,7 +37,7 @@ import ( const ( name = "testing" - namespace = "rf-integration-tests" + namespace = "testns" redisSize = int32(3) sentinelSize = int32(3) authSecretPath = "redis-auth" @@ -52,24 +52,25 @@ type clients struct { redisClient redis.Client } -func (c *clients) prepareNS() error { +func (c *clients) prepareNS(currentNamespace) error { ns := &corev1.Namespace{ ObjectMeta: metav1.ObjectMeta{ - Name: namespace, + Name: currentNamespace, }, } _, err := c.k8sClient.CoreV1().Namespaces().Create(context.Background(), ns, metav1.CreateOptions{}) return err } -func (c *clients) cleanup(stopC chan struct{}) { - c.k8sClient.CoreV1().Namespaces().Delete(context.Background(), namespace, metav1.DeleteOptions{}) +func (c *clients) cleanup(stopC chan struct{}, currentNamespace string) { + c.k8sClient.CoreV1().Namespaces().Delete(context.Background(), currentNamespace, metav1.DeleteOptions{}) close(stopC) } func TestRedisFailover(t *testing.T) { require := require.New(t) disableMyMaster := true + currentNamespace := namespace // Create signal channels. stopC := make(chan struct{}) @@ -98,7 +99,7 @@ func TestRedisFailover(t *testing.T) { k8sservice := k8s.New(k8sClient, customClient, aeClientset, log.Dummy, metrics.Dummy) // Prepare namespace - prepErr := clients.prepareNS() + prepErr := clients.prepareNS(currentNamespace) require.NoError(prepErr) // Give time to the namespace to be ready @@ -113,7 +114,7 @@ func TestRedisFailover(t *testing.T) { }() // Prepare cleanup for when the test ends - defer clients.cleanup(stopC) + defer clients.cleanup(stopC, currentNamespace) // Give time to the operator to start time.Sleep(15 * time.Second) @@ -133,7 +134,7 @@ func TestRedisFailover(t *testing.T) { // Check that if we create a RedisFailover, it is certainly created and we can get it ok := t.Run("Check Custom Resource Creation", func(t *testing.T) { - clients.testCRCreation(t, disableMyMaster) + clients.testCRCreation(t, currentNamespace, disableMyMaster) }) require.True(ok, "the custom resource has to be created to continue") @@ -141,34 +142,45 @@ func TestRedisFailover(t *testing.T) { time.Sleep(3 * time.Minute) // Verify that auth is set and actually working - t.Run("Check that auth is set in sentinel and redis configs", clients.testAuth) + t.Run("Check that auth is set in sentinel and redis configs", func(t *testing.T) { + clients.testAuth(t, currentNamespace) + }) // Check custom config is set - t.Run("Check that custom config is behave expected", clients.testCustomConfig) + t.Run("Check that custom config is behave expected", func(t *testing.T) { + clients.testCustomConfig(t, currentNamespace) + }) // 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) + t.Run("Check Redis Statefulset existing and size", func(t *testing.T) { + clients.testRedisStatefulSet(t, currentNamespace) + }) // Check that a Sentinel Deployment is created and the size of it is the one defined by the // Redis Failover definition created before. - t.Run("Check Sentinel Deployment existing and size", clients.testSentinelDeployment) + t.Run("Check Sentinel Deployment existing and size", func(t *testing.T) { + clients.testSentinelDeployment(t, currentNamespace) + }) // Connect to all the Redis pods and, asking to the Redis running inside them, check // that only one of them is the master of the failover. - t.Run("Check Only One Redis Master", clients.testRedisMaster) + t.Run("Check Only One Redis Master", func(t *testing.T) { + clients.testRedisMaster(t, currentNamespace) + }) // Connect to all the Sentinel pods and, asking to the Sentinel running inside them, // check that all of them are connected to the same Redis node, and also that that node // is the master. t.Run("Check Sentinels Checking the Redis Master", func(t *testing.T) { - clients.testSentinelMonitoring(t, disableMyMaster) + clients.testSentinelMonitoring(t, currentNamespace, disableMyMaster) }) } func TestRedisFailoverMyMaster(t *testing.T) { require := require.New(t) disableMyMaster := false + currentNamespace := "mymaster-" + namespace // Create signal channels. stopC := make(chan struct{}) @@ -197,14 +209,14 @@ func TestRedisFailoverMyMaster(t *testing.T) { k8sservice := k8s.New(k8sClient, customClient, aeClientset, log.Dummy, metrics.Dummy) // Prepare namespace - prepErr := clients.prepareNS() + prepErr := clients.prepareNS(currentNamespace) require.NoError(prepErr) // Give time to the namespace to be ready time.Sleep(15 * time.Second) // Create operator and run. - redisfailoverOperator, err := redisfailover.New(redisfailover.Config{}, k8sservice, k8sClient, namespace, redisClient, metrics.Dummy, log.Dummy) + redisfailoverOperator, err := redisfailover.New(redisfailover.Config{}, k8sservice, k8sClient, currentNamespace, redisClient, metrics.Dummy, log.Dummy) require.NoError(err) go func() { @@ -212,7 +224,7 @@ func TestRedisFailoverMyMaster(t *testing.T) { }() // Prepare cleanup for when the test ends - defer clients.cleanup(stopC) + defer clients.cleanup(stopC, currentNamespace) // Give time to the operator to start time.Sleep(15 * time.Second) @@ -221,18 +233,18 @@ func TestRedisFailoverMyMaster(t *testing.T) { secret := &v1.Secret{ ObjectMeta: metav1.ObjectMeta{ Name: authSecretPath, - Namespace: namespace, + Namespace: currentNamespace, }, Data: map[string][]byte{ "password": []byte(testPass), }, } - _, err = k8sClient.CoreV1().Secrets(namespace).Create(context.Background(), secret, metav1.CreateOptions{}) + _, err = k8sClient.CoreV1().Secrets(currentNamespace).Create(context.Background(), secret, metav1.CreateOptions{}) require.NoError(err) // Check that if we create a RedisFailover, it is certainly created and we can get it ok := t.Run("Check Custom Resource Creation", func(t *testing.T) { - clients.testCRCreation(t, disableMyMaster) + clients.testCRCreation(t, currentNamespace, disableMyMaster) }) require.True(ok, "the custom resource has to be created to continue") @@ -240,32 +252,42 @@ func TestRedisFailoverMyMaster(t *testing.T) { time.Sleep(3 * time.Minute) // Verify that auth is set and actually working - t.Run("Check that auth is set in sentinel and redis configs", clients.testAuth) + t.Run("Check that auth is set in sentinel and redis configs", func(t *testing.T) { + clients.testAuth(t, currentNamespace) + }) // Check custom config is set - t.Run("Check that custom config is behave expected", clients.testCustomConfig) + t.Run("Check that custom config is behave expected", func(t *testing.T) { + clients.testCustomConfig(t, currentNamespace) + }) // 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) + t.Run("Check Redis Statefulset existing and size", func(t *testing.T) { + clients.testRedisStatefulSet(t, currentNamespace) + }) // Check that a Sentinel Deployment is created and the size of it is the one defined by the // Redis Failover definition created before. - t.Run("Check Sentinel Deployment existing and size", clients.testSentinelDeployment) + t.Run("Check Sentinel Deployment existing and size", func(t *testing.T) { + clients.testSentinelDeployment(t, currentNamespace) + }) // Connect to all the Redis pods and, asking to the Redis running inside them, check // that only one of them is the master of the failover. - t.Run("Check Only One Redis Master", clients.testRedisMaster) + t.Run("Check Only One Redis Master", func(t *testing.T) { + clients.testRedisMaster(t, currentNamespace) + }) // Connect to all the Sentinel pods and, asking to the Sentinel running inside them, // check that all of them are connected to the same Redis node, and also that that node // is the master. t.Run("Check Sentinels Checking the Redis Master", func(t *testing.T) { - clients.testSentinelMonitoring(t, disableMyMaster) + clients.testSentinelMonitoring(t, currentNamespace, disableMyMaster) }) } -func (c *clients) testCRCreation(t *testing.T, args ...bool) { +func (c *clients) testCRCreation(t *testing.T, currentNamespace string, args ...bool) { disableMyMaster := false if len(args) > 0 && args[0] { disableMyMaster = args[0] @@ -274,7 +296,7 @@ func (c *clients) testCRCreation(t *testing.T, args ...bool) { toCreate := &redisfailoverv1.RedisFailover{ ObjectMeta: metav1.ObjectMeta{ Name: name, - Namespace: namespace, + Namespace: currentNamespace, }, Spec: redisfailoverv1.RedisFailoverSpec{ Redis: redisfailoverv1.RedisSettings{ @@ -294,39 +316,39 @@ func (c *clients) testCRCreation(t *testing.T, args ...bool) { }, } - c.rfClient.DatabasesV1().RedisFailovers(namespace).Create(context.Background(), toCreate, metav1.CreateOptions{}) - gotRF, err := c.rfClient.DatabasesV1().RedisFailovers(namespace).Get(context.Background(), name, metav1.GetOptions{}) + c.rfClient.DatabasesV1().RedisFailovers(currentNamespace).Create(context.Background(), toCreate, metav1.CreateOptions{}) + gotRF, err := c.rfClient.DatabasesV1().RedisFailovers(currentNamespace).Get(context.Background(), name, metav1.GetOptions{}) assert.NoError(err) assert.Equal(toCreate.Spec, gotRF.Spec) } -func (c *clients) testRedisStatefulSet(t *testing.T) { +func (c *clients) testRedisStatefulSet(t *testing.T, currentNamespace string) { assert := assert.New(t) - redisSS, err := c.k8sClient.AppsV1().StatefulSets(namespace).Get(context.Background(), fmt.Sprintf("rfr-%s", name), metav1.GetOptions{}) + redisSS, err := c.k8sClient.AppsV1().StatefulSets(currentNamespace).Get(context.Background(), fmt.Sprintf("rfr-%s", name), metav1.GetOptions{}) assert.NoError(err) assert.Equal(redisSize, int32(redisSS.Status.Replicas)) } -func (c *clients) testSentinelDeployment(t *testing.T) { +func (c *clients) testSentinelDeployment(t *testing.T, currentNamespace string) { assert := assert.New(t) - sentinelD, err := c.k8sClient.AppsV1().Deployments(namespace).Get(context.Background(), fmt.Sprintf("rfs-%s", name), metav1.GetOptions{}) + sentinelD, err := c.k8sClient.AppsV1().Deployments(currentNamespace).Get(context.Background(), fmt.Sprintf("rfs-%s", name), metav1.GetOptions{}) assert.NoError(err) assert.Equal(3, int(sentinelD.Status.Replicas)) } -func (c *clients) testRedisMaster(t *testing.T) { +func (c *clients) testRedisMaster(t *testing.T, currentNamespace string) { assert := assert.New(t) masters := []string{} - redisSS, err := c.k8sClient.AppsV1().StatefulSets(namespace).Get(context.Background(), fmt.Sprintf("rfr-%s", name), metav1.GetOptions{}) + redisSS, err := c.k8sClient.AppsV1().StatefulSets(currentNamespace).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) + redisPodList, err := c.k8sClient.CoreV1().Pods(currentNamespace).List(context.Background(), listOptions) assert.NoError(err) @@ -340,7 +362,7 @@ func (c *clients) testRedisMaster(t *testing.T) { assert.Equal(1, len(masters), "only one master expected") } -func (c *clients) testSentinelMonitoring(t *testing.T, args ...bool) { +func (c *clients) testSentinelMonitoring(t *testing.T, currentNamespace string, args ...bool) { disableMyMaster := false if len(args) > 0 { disableMyMaster = args[0] @@ -354,13 +376,13 @@ func (c *clients) testSentinelMonitoring(t *testing.T, args ...bool) { assert := assert.New(t) masters := []string{} - sentinelD, err := c.k8sClient.AppsV1().Deployments(namespace).Get(context.Background(), fmt.Sprintf("rfs-%s", name), metav1.GetOptions{}) + sentinelD, err := c.k8sClient.AppsV1().Deployments(currentNamespace).Get(context.Background(), fmt.Sprintf("rfs-%s", name), metav1.GetOptions{}) assert.NoError(err) listOptions := metav1.ListOptions{ LabelSelector: labels.FormatLabels(sentinelD.Spec.Selector.MatchLabels), } - sentinelPodList, err := c.k8sClient.CoreV1().Pods(namespace).List(context.Background(), listOptions) + sentinelPodList, err := c.k8sClient.CoreV1().Pods(currentNamespace).List(context.Background(), listOptions) assert.NoError(err) for _, pod := range sentinelPodList.Items { @@ -378,15 +400,15 @@ func (c *clients) testSentinelMonitoring(t *testing.T, args ...bool) { assert.True(isMaster, "Sentinel should monitor the Redis master") } -func (c *clients) testAuth(t *testing.T) { +func (c *clients) testAuth(t *testing.T, currentNamespace string) { assert := assert.New(t) - redisCfg, err := c.k8sClient.CoreV1().ConfigMaps(namespace).Get(context.Background(), fmt.Sprintf("rfr-%s", name), metav1.GetOptions{}) + redisCfg, err := c.k8sClient.CoreV1().ConfigMaps(currentNamespace).Get(context.Background(), fmt.Sprintf("rfr-%s", name), metav1.GetOptions{}) assert.NoError(err) assert.Contains(redisCfg.Data["redis.conf"], "requirepass "+testPass) assert.Contains(redisCfg.Data["redis.conf"], "masterauth "+testPass) - redisSS, err := c.k8sClient.AppsV1().StatefulSets(namespace).Get(context.Background(), fmt.Sprintf("rfr-%s", name), metav1.GetOptions{}) + redisSS, err := c.k8sClient.AppsV1().StatefulSets(currentNamespace).Get(context.Background(), fmt.Sprintf("rfr-%s", name), metav1.GetOptions{}) assert.NoError(err) assert.Len(redisSS.Spec.Template.Spec.Containers, 2) @@ -401,16 +423,16 @@ func (c *clients) testAuth(t *testing.T) { assert.Equal(redisSS.Spec.Template.Spec.Containers[1].Env[4].ValueFrom.SecretKeyRef.LocalObjectReference.Name, authSecretPath) } -func (c *clients) testCustomConfig(t *testing.T) { +func (c *clients) testCustomConfig(t *testing.T, currentNamespace string) { assert := assert.New(t) - redisSS, err := c.k8sClient.AppsV1().StatefulSets(namespace).Get(context.Background(), fmt.Sprintf("rfr-%s", name), metav1.GetOptions{}) + redisSS, err := c.k8sClient.AppsV1().StatefulSets(currentNamespace).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) + redisPodList, err := c.k8sClient.CoreV1().Pods(currentNamespace).List(context.Background(), listOptions) assert.NoError(err) rClient := rediscli.NewClient(&rediscli.Options{ From f4cff6baba29e55fa219ab2d04a7576e52da3a57 Mon Sep 17 00:00:00 2001 From: M Samuel Vijaykumar Date: Tue, 3 Sep 2024 23:53:19 +0530 Subject: [PATCH 13/14] missed a string --- test/integration/redisfailover/creation_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/redisfailover/creation_test.go b/test/integration/redisfailover/creation_test.go index c33825aa7..adb25b98c 100644 --- a/test/integration/redisfailover/creation_test.go +++ b/test/integration/redisfailover/creation_test.go @@ -52,7 +52,7 @@ type clients struct { redisClient redis.Client } -func (c *clients) prepareNS(currentNamespace) error { +func (c *clients) prepareNS(currentNamespace sting) error { ns := &corev1.Namespace{ ObjectMeta: metav1.ObjectMeta{ Name: currentNamespace, From a1552c3a5db6421a263b2678f82f47aeef096289 Mon Sep 17 00:00:00 2001 From: M Samuel Vijaykumar Date: Tue, 3 Sep 2024 23:56:04 +0530 Subject: [PATCH 14/14] Fix a typo --- test/integration/redisfailover/creation_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/redisfailover/creation_test.go b/test/integration/redisfailover/creation_test.go index adb25b98c..8340c799b 100644 --- a/test/integration/redisfailover/creation_test.go +++ b/test/integration/redisfailover/creation_test.go @@ -52,7 +52,7 @@ type clients struct { redisClient redis.Client } -func (c *clients) prepareNS(currentNamespace sting) error { +func (c *clients) prepareNS(currentNamespace string) error { ns := &corev1.Namespace{ ObjectMeta: metav1.ObjectMeta{ Name: currentNamespace,