From 06ae090d0762eff060ef62c8b68e6758dcdb4ab0 Mon Sep 17 00:00:00 2001 From: Artur Zheludkov Date: Fri, 22 Dec 2023 12:54:59 -0500 Subject: [PATCH] enable parameter --- CHANGELOG.md | 1 + api/redisfailover/v1/bootstrapping.go | 2 +- api/redisfailover/v1/bootstrapping_test.go | 11 +++++++---- api/redisfailover/v1/types.go | 1 + api/redisfailover/v1/validate_test.go | 16 ++++++++-------- .../databases.spotahome.com_redisfailovers.yaml | 2 ++ .../databases.spotahome.com_redisfailovers.yaml | 2 ++ operator/redisfailover/ensurer_test.go | 11 +++++------ operator/redisfailover/service/check_test.go | 2 ++ 9 files changed, 29 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c8bb33a3..b6525ac2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ Also check this project's [releases](https://github.com/powerhome/redis-operator ## Unreleased ### Changed +- [Utilize the 'Enabled' parameter to toggle the bootstrap mode on or off for Redis nodes.](https://github.com/powerhome/redis-operator/pull/31). - [Use the new docker bake tooling to build the developer tools image and remove vestigial development targets from the Makefile](https://github.com/powerhome/redis-operator/pull/31). ## [v1.8.0-rc2] - 2023-12-20 diff --git a/api/redisfailover/v1/bootstrapping.go b/api/redisfailover/v1/bootstrapping.go index fbe83ed4b..467e888a3 100644 --- a/api/redisfailover/v1/bootstrapping.go +++ b/api/redisfailover/v1/bootstrapping.go @@ -2,7 +2,7 @@ package v1 // Bootstrapping returns true when a BootstrapNode is provided to the RedisFailover spec. Otherwise, it returns false. func (r *RedisFailover) Bootstrapping() bool { - return r.Spec.BootstrapNode != nil + return r.Spec.BootstrapNode != nil && r.Spec.BootstrapNode.Enabled } // SentinelsAllowed returns true if not Bootstrapping orif BootstrapNode settings allow sentinels to exist diff --git a/api/redisfailover/v1/bootstrapping_test.go b/api/redisfailover/v1/bootstrapping_test.go index 43b5ad584..d96e84b87 100644 --- a/api/redisfailover/v1/bootstrapping_test.go +++ b/api/redisfailover/v1/bootstrapping_test.go @@ -33,8 +33,9 @@ func TestBootstrapping(t *testing.T) { name: "with BootstrapSettings", expectation: true, bootstrapSettings: &BootstrapSettings{ - Host: "127.0.0.1", - Port: "6379", + Host: "127.0.0.1", + Port: "6379", + Enabled: true, }, }, } @@ -61,8 +62,9 @@ func TestSentinelsAllowed(t *testing.T) { name: "with BootstrapSettings", expectation: false, bootstrapSettings: &BootstrapSettings{ - Host: "127.0.0.1", - Port: "6379", + Host: "127.0.0.1", + Port: "6379", + Enabled: true, }, }, { @@ -72,6 +74,7 @@ func TestSentinelsAllowed(t *testing.T) { Host: "127.0.0.1", Port: "6379", AllowSentinels: true, + Enabled: true, }, }, } diff --git a/api/redisfailover/v1/types.go b/api/redisfailover/v1/types.go index c01f0efdb..4bdaad743 100644 --- a/api/redisfailover/v1/types.go +++ b/api/redisfailover/v1/types.go @@ -175,6 +175,7 @@ type BootstrapSettings struct { Host string `json:"host,omitempty"` Port string `json:"port,omitempty"` AllowSentinels bool `json:"allowSentinels,omitempty"` + Enabled bool `json:"enabled,omitempty"` } // Exporter defines the specification for the redis/sentinel exporter diff --git a/api/redisfailover/v1/validate_test.go b/api/redisfailover/v1/validate_test.go index aeebf0235..7707b5825 100644 --- a/api/redisfailover/v1/validate_test.go +++ b/api/redisfailover/v1/validate_test.go @@ -34,7 +34,7 @@ func TestValidate(t *testing.T) { { name: "BootstrapNode provided without a host", rfName: "test", - rfBootstrapNode: &BootstrapSettings{}, + rfBootstrapNode: &BootstrapSettings{Enabled: true}, expectedError: "BootstrapNode must include a host when provided", }, { @@ -44,14 +44,14 @@ func TestValidate(t *testing.T) { { name: "Populates default bootstrap port when valid", rfName: "test", - rfBootstrapNode: &BootstrapSettings{Host: "127.0.0.1"}, - expectedBootstrapNode: &BootstrapSettings{Host: "127.0.0.1", Port: "6379"}, + rfBootstrapNode: &BootstrapSettings{Host: "127.0.0.1", Enabled: true}, + expectedBootstrapNode: &BootstrapSettings{Host: "127.0.0.1", Port: "6379", Enabled: true}, }, { name: "Allows for specifying boostrap port", rfName: "test", - rfBootstrapNode: &BootstrapSettings{Host: "127.0.0.1", Port: "6380"}, - expectedBootstrapNode: &BootstrapSettings{Host: "127.0.0.1", Port: "6380"}, + rfBootstrapNode: &BootstrapSettings{Host: "127.0.0.1", Port: "6380", Enabled: true}, + expectedBootstrapNode: &BootstrapSettings{Host: "127.0.0.1", Port: "6380", Enabled: true}, }, { name: "Appends applied custom config to default initial values", @@ -62,8 +62,8 @@ func TestValidate(t *testing.T) { name: "Appends applied custom config to default initial values when bootstrapping", rfName: "test", rfRedisCustomConfig: []string{"tcp-keepalive 60"}, - rfBootstrapNode: &BootstrapSettings{Host: "127.0.0.1"}, - expectedBootstrapNode: &BootstrapSettings{Host: "127.0.0.1", Port: "6379"}, + rfBootstrapNode: &BootstrapSettings{Host: "127.0.0.1", Enabled: true}, + expectedBootstrapNode: &BootstrapSettings{Host: "127.0.0.1", Port: "6379", Enabled: true}, }, } @@ -83,7 +83,7 @@ func TestValidate(t *testing.T) { "replica-priority 100", } - if test.rfBootstrapNode != nil { + if test.rfBootstrapNode != nil && test.rfBootstrapNode.Enabled { expectedRedisCustomConfig = []string{ "replica-priority 0", } diff --git a/manifests/databases.spotahome.com_redisfailovers.yaml b/manifests/databases.spotahome.com_redisfailovers.yaml index 29fa0a94d..53b557c0d 100644 --- a/manifests/databases.spotahome.com_redisfailovers.yaml +++ b/manifests/databases.spotahome.com_redisfailovers.yaml @@ -65,6 +65,8 @@ spec: properties: allowSentinels: type: boolean + enabled: + type: boolean host: type: string port: diff --git a/manifests/kustomize/base/databases.spotahome.com_redisfailovers.yaml b/manifests/kustomize/base/databases.spotahome.com_redisfailovers.yaml index 29fa0a94d..53b557c0d 100644 --- a/manifests/kustomize/base/databases.spotahome.com_redisfailovers.yaml +++ b/manifests/kustomize/base/databases.spotahome.com_redisfailovers.yaml @@ -65,6 +65,8 @@ spec: properties: allowSentinels: type: boolean + enabled: + type: boolean host: type: string port: diff --git a/operator/redisfailover/ensurer_test.go b/operator/redisfailover/ensurer_test.go index 890bdf500..4d161f1a2 100644 --- a/operator/redisfailover/ensurer_test.go +++ b/operator/redisfailover/ensurer_test.go @@ -50,13 +50,12 @@ func generateRF(enableExporter bool, bootstrapping bool) *redisfailoverv1.RedisF } func generateRFBootstrappingNode(bootstrapping bool) *redisfailoverv1.BootstrapSettings { - if bootstrapping { - return &redisfailoverv1.BootstrapSettings{ - Host: "127.0.0.1", - Port: "6379", - } + + return &redisfailoverv1.BootstrapSettings{ + Host: "127.0.0.1", + Port: "6379", + Enabled: bootstrapping, } - return nil } func TestEnsure(t *testing.T) { diff --git a/operator/redisfailover/service/check_test.go b/operator/redisfailover/service/check_test.go index 982deee0d..e2ae36bdb 100644 --- a/operator/redisfailover/service/check_test.go +++ b/operator/redisfailover/service/check_test.go @@ -1034,6 +1034,7 @@ func TestClusterRunningWithBootstrap(t *testing.T) { rf.Spec.BootstrapNode = &redisfailoverv1.BootstrapSettings{ Host: "fake-host", AllowSentinels: false, + Enabled: false, } ms.On("GetDeploymentPods", namespace, rfservice.GetSentinelName(rf)).Once().Return(notAllRunning, nil) ms.On("GetStatefulSetPods", namespace, rfservice.GetRedisName(rf)).Once().Return(notAllRunning, nil) @@ -1124,6 +1125,7 @@ func TestClusterRunningWithBootstrapSentinels(t *testing.T) { rf.Spec.BootstrapNode = &redisfailoverv1.BootstrapSettings{ Host: "fake-host", AllowSentinels: true, + Enabled: true, } ms.On("GetDeploymentPods", namespace, rfservice.GetSentinelName(rf)).Once().Return(allRunning, nil) ms.On("GetStatefulSetPods", namespace, rfservice.GetRedisName(rf)).Once().Return(allRunning, nil)