diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index cfd56d750..cab475a51 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -3,70 +3,72 @@ name: CI on: push: branches: - - main + - master pull_request: - + types: [opened, synchronize, reopened, edited] + branches: + - master jobs: - check: - name: Golang Check - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-go@v4 - with: - go-version-file: go.mod - cache: false - - name: golangci-lint - uses: golangci/golangci-lint-action@v3 - with: - version: v1.53 - args: --timeout=15m + check: + name: Golang Check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod + cache: false + - name: golangci-lint + uses: golangci/golangci-lint-action@v6 + with: + version: v1.60 + args: --timeout=15m - unit-test: - name: Unit test - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-go@v4 - with: - go-version-file: go.mod - - run: make ci-unit-test + unit-test: + name: Unit test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod + - run: make ci-unit-test - integration-test: - name: Integration test - runs-on: ubuntu-latest - needs: [check, unit-test] - strategy: - matrix: - kubernetes: [1.24.16, 1.25.12, 1.26.7, 1.27.3 ] - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-go@v4 - with: - go-version-file: go.mod - - name: Install conntrack - run: sudo apt-get install -y conntrack - - uses: medyagh/setup-minikube@v0.0.14 - with: - kubernetes-version: ${{ matrix.kubernetes }} - minikube-version: 1.31.1 - driver: none - - name: Add redisfailover CRD - run: kubectl create -f manifests/databases.spotahome.com_redisfailovers.yaml - - run: make ci-integration-test + integration-test: + name: Integration test + runs-on: ubuntu-latest + needs: [check, unit-test] + strategy: + matrix: + kubernetes: [1.27.3, 1.28.13, 1.29.8, 1.30.4, 1.31.0] + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod + - name: Install conntrack + run: sudo apt-get install -y conntrack + - uses: medyagh/setup-minikube@v0.0.18 + with: + kubernetes-version: ${{ matrix.kubernetes }} + minikube-version: 1.31.1 + driver: none + - name: Add redisfailover CRD + run: kubectl create -f manifests/databases.spotahome.com_redisfailovers.yaml + - run: make ci-integration-test - chart-test: - name: Chart testing - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 + chart-test: + name: Chart testing + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 - - name: Install Helm - uses: azure/setup-helm@v3 - with: - version: v3.7.2 + - name: Install Helm + uses: azure/setup-helm@v3 + with: + version: v3.7.2 - - name: Helm test - run: make helm-test + - name: Helm test + run: make helm-test 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/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..02b8c4a76 100644 --- a/api/redisfailover/v1/types.go +++ b/api/redisfailover/v1/types.go @@ -71,6 +71,7 @@ type RedisSettings struct { CustomReadinessProbe *corev1.Probe `json:"customReadinessProbe,omitempty"` CustomStartupProbe *corev1.Probe `json:"customStartupProbe,omitempty"` DisablePodDisruptionBudget bool `json:"disablePodDisruptionBudget,omitempty"` + DisableMyMaster bool `json:"disableMyMaster,omitempty"` } // SentinelSettings defines the specification of the sentinel cluster @@ -105,6 +106,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/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/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/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 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/go.mod b/go.mod index 18b00397e..790f10750 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/spotahome/redis-operator -go 1.20 +go 1.22 require ( github.com/go-redis/redis/v8 v8.11.5 diff --git a/go.sum b/go.sum index e1dad7d15..ed33d5a17 100644 --- a/go.sum +++ b/go.sum @@ -168,6 +168,7 @@ github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 h1:p104kn46Q8WdvHunIJ9dAyjPVtrBPhSr3KT2yUst43I= +github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= @@ -248,6 +249,7 @@ github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLe github.com/google/pprof v0.0.0-20210122040257-d980be63207e/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210226084205-cbba55b83ad5/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJYCmNdQXq6neHJOYx3V6jnqNEec= +github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= @@ -317,6 +319,7 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= @@ -361,17 +364,21 @@ github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+ github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= +github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= github.com/onsi/ginkgo v0.0.0-20170829012221-11459a886d9c/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY= github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= +github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= github.com/onsi/ginkgo/v2 v2.9.1 h1:zie5Ly042PD3bsCvsSOPvRnFwyo3rKe64TJlD6nu0mk= +github.com/onsi/ginkgo/v2 v2.9.1/go.mod h1:FEcmzVcCHl+4o9bQZVab+4dC9+j+91t2FHSzmGAPfuo= github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= github.com/onsi/gomega v1.27.4 h1:Z2AnStgsdSayCMDiCU42qIz+HLqEPcgiOCXjAU/w+8E= +github.com/onsi/gomega v1.27.4/go.mod h1:riYq/GJKh8hhoM01HN6Vmuy93AarCXCBGpvFDK3q3fQ= github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= @@ -420,6 +427,7 @@ github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6So github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= +github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= @@ -786,6 +794,7 @@ golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.10-0.20220218145154-897bd77cd717/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E= golang.org/x/tools v0.7.0 h1:W4OVu8VVOaIO0yzWMNdepAulS7YfoS3Zabrm8DOXXU4= +golang.org/x/tools v0.7.0/go.mod h1:4pg6aUX35JBAogB10C9AtvVL+qowtN4pT3CGSQex14s= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/manifests/databases.spotahome.com_redisfailovers.yaml b/manifests/databases.spotahome.com_redisfailovers.yaml index 011476fa4..fda31c8b7 100644 --- a/manifests/databases.spotahome.com_redisfailovers.yaml +++ b/manifests/databases.spotahome.com_redisfailovers.yaml @@ -1582,6 +1582,8 @@ spec: format: int32 type: integer type: object + disableMyMaster: + type: boolean disablePodDisruptionBudget: type: boolean dnsPolicy: @@ -8797,6 +8799,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..fda31c8b7 100644 --- a/manifests/kustomize/base/databases.spotahome.com_redisfailovers.yaml +++ b/manifests/kustomize/base/databases.spotahome.com_redisfailovers.yaml @@ -1582,6 +1582,8 @@ spec: format: int32 type: integer type: object + disableMyMaster: + type: boolean disablePodDisruptionBudget: type: boolean dnsPolicy: @@ -8797,6 +8799,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.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/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/handler.go b/operator/redisfailover/handler.go index 6a03afd56..915cb5272 100644 --- a/operator/redisfailover/handler.go +++ b/operator/redisfailover/handler.go @@ -93,7 +93,7 @@ func (r *RedisFailoverHandler) getLabels(rf *redisfailoverv1.RedisFailover) map[ // Filter the labels based on the whitelist filteredCustomLabels := make(map[string]string) - if rf.Spec.LabelWhitelist != nil && len(rf.Spec.LabelWhitelist) != 0 { + if len(rf.Spec.LabelWhitelist) != 0 { for _, regex := range rf.Spec.LabelWhitelist { compiledRegexp, err := regexp.Compile(regex) if err != nil { 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/check_test.go b/operator/redisfailover/service/check_test.go index af64d7e13..5c0bba581 100644 --- a/operator/redisfailover/service/check_test.go +++ b/operator/redisfailover/service/check_test.go @@ -20,21 +20,40 @@ import ( rfservice "github.com/spotahome/redis-operator/operator/redisfailover/service" ) -func generateRF() *redisfailoverv1.RedisFailover { - return &redisfailoverv1.RedisFailover{ - ObjectMeta: metav1.ObjectMeta{ - Name: name, - Namespace: namespace, - }, - Spec: redisfailoverv1.RedisFailoverSpec{ - Redis: redisfailoverv1.RedisSettings{ - Replicas: int32(3), +func generateRF(args ...bool) *redisfailoverv1.RedisFailover { + if len(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], + }, }, - Sentinel: redisfailoverv1.SentinelSettings{ - Replicas: int32(3), + } + } else { + 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), + }, + }, + } } + } func TestCheckRedisNumberError(t *testing.T) { @@ -362,11 +381,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 +394,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 +407,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 +420,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 +433,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 +446,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/generator.go b/operator/redisfailover/service/generator.go index f82eaab9a..b59c62a7d 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" @@ -248,17 +257,17 @@ func generateRedisShutdownConfigMap(rf *redisfailoverv1.RedisFailover, labels ma 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) + 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 mymaster - sleep 31 +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) +eval $save_command`, rfName, port, rf.MasterName()) return &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ @@ -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, }, }, }, 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) + } +} 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/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/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 { diff --git a/test/integration/redisfailover/creation_test.go b/test/integration/redisfailover/creation_test.go index 5458634ba..8340c799b 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,23 +52,25 @@ type clients struct { redisClient redis.Client } -func (c *clients) prepareNS() error { +func (c *clients) prepareNS(currentNamespace string) 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{}) @@ -97,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 @@ -112,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) @@ -131,42 +133,170 @@ 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, currentNamespace, 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) + 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", clients.testSentinelMonitoring) + t.Run("Check Sentinels Checking the Redis Master", func(t *testing.T) { + clients.testSentinelMonitoring(t, currentNamespace, disableMyMaster) + }) } -func (c *clients) testCRCreation(t *testing.T) { +func TestRedisFailoverMyMaster(t *testing.T) { + require := require.New(t) + disableMyMaster := false + currentNamespace := "mymaster-" + namespace + + // 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(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, currentNamespace, 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, currentNamespace) + + // Give time to the operator to start + time.Sleep(15 * time.Second) + + // Create secret + secret := &v1.Secret{ + ObjectMeta: metav1.ObjectMeta{ + Name: authSecretPath, + Namespace: currentNamespace, + }, + Data: map[string][]byte{ + "password": []byte(testPass), + }, + } + _, 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, currentNamespace, 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", func(t *testing.T) { + clients.testAuth(t, currentNamespace) + }) + + // Check custom config is set + 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", 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", 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", 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, currentNamespace, disableMyMaster) + }) +} + +func (c *clients) testCRCreation(t *testing.T, currentNamespace string, args ...bool) { + disableMyMaster := false + if len(args) > 0 && args[0] { + disableMyMaster = args[0] + } assert := assert.New(t) toCreate := &redisfailoverv1.RedisFailover{ ObjectMeta: metav1.ObjectMeta{ Name: name, - Namespace: namespace, + Namespace: currentNamespace, }, Spec: redisfailoverv1.RedisFailoverSpec{ Redis: redisfailoverv1.RedisSettings{ @@ -177,7 +307,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, @@ -185,39 +316,39 @@ func (c *clients) testCRCreation(t *testing.T) { }, } - 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) @@ -231,22 +362,32 @@ 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, currentNamespace string, args ...bool) { + disableMyMaster := false + if len(args) > 0 { + disableMyMaster = args[0] + } + + masterName := "mymaster" + if disableMyMaster { + masterName = name + } + 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 { ip := pod.Status.PodIP - master, _, _ := c.redisClient.GetSentinelMonitor(ip) + master, _, _ := c.redisClient.GetSentinelMonitor(ip, masterName) masters = append(masters, master) } @@ -259,15 +400,15 @@ func (c *clients) testSentinelMonitoring(t *testing.T) { 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) @@ -282,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{