Skip to content

Commit

Permalink
enable parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
rurkss committed Dec 22, 2023
1 parent 2233e9c commit 06ae090
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion api/redisfailover/v1/bootstrapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions api/redisfailover/v1/bootstrapping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
}
Expand All @@ -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,
},
},
{
Expand All @@ -72,6 +74,7 @@ func TestSentinelsAllowed(t *testing.T) {
Host: "127.0.0.1",
Port: "6379",
AllowSentinels: true,
Enabled: true,
},
},
}
Expand Down
1 change: 1 addition & 0 deletions api/redisfailover/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions api/redisfailover/v1/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
{
Expand All @@ -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",
Expand All @@ -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},
},
}

Expand All @@ -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",
}
Expand Down
2 changes: 2 additions & 0 deletions manifests/databases.spotahome.com_redisfailovers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ spec:
properties:
allowSentinels:
type: boolean
enabled:
type: boolean
host:
type: string
port:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ spec:
properties:
allowSentinels:
type: boolean
enabled:
type: boolean
host:
type: string
port:
Expand Down
11 changes: 5 additions & 6 deletions operator/redisfailover/ensurer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions operator/redisfailover/service/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 06ae090

Please sign in to comment.