Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding named master support for sentinelCustom masters #702

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 62 additions & 60 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected].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/[email protected].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
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions api/redisfailover/v1/master.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package v1

func (r *RedisFailover) MasterName() string {
if r.Spec.Sentinel.DisableMyMaster {
return r.Name
} else {
return "mymaster"
}
}
52 changes: 52 additions & 0 deletions api/redisfailover/v1/master_test.go
Original file line number Diff line number Diff line change
@@ -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())
})
}
}
2 changes: 2 additions & 0 deletions api/redisfailover/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion api/redisfailover/v1/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
{
Expand Down
4 changes: 2 additions & 2 deletions docker/development/Dockerfile
Original file line number Diff line number Diff line change
@@ -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 \
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions example/redisfailover/basic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apiVersion: databases.spotahome.com/v1
kind: RedisFailover
metadata:
name: redisfailover
namespace: basic
spec:
sentinel:
replicas: 3
Expand Down
23 changes: 23 additions & 0 deletions example/redisfailover/disable-mymaster.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 9 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
4 changes: 4 additions & 0 deletions manifests/databases.spotahome.com_redisfailovers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1582,6 +1582,8 @@ spec:
format: int32
type: integer
type: object
disableMyMaster:
type: boolean
disablePodDisruptionBudget:
type: boolean
dnsPolicy:
Expand Down Expand Up @@ -8797,6 +8799,8 @@ spec:
format: int32
type: integer
type: object
disableMyMaster:
type: boolean
disablePodDisruptionBudget:
type: boolean
dnsPolicy:
Expand Down
Loading
Loading