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

Utilize the 'Enabled' parameter to toggle the bootstrap mode on or off for Redis nodes. #32

Merged
merged 11 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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
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/32).
rurkss marked this conversation as resolved.
Show resolved Hide resolved
- [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
2 changes: 2 additions & 0 deletions api/redisfailover/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ type BootstrapSettings struct {
Host string `json:"host,omitempty"`
Port string `json:"port,omitempty"`
AllowSentinels bool `json:"allowSentinels,omitempty"`
// +kubebuilder:default=true
Enabled bool `json:"enabled,omitempty"`
rurkss marked this conversation as resolved.
Show resolved Hide resolved
}

// 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
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ This `bootstrapNode` can be configured as follows:
| host | **required** | The IP of the target Redis address or the ClusterIP of a pre-existing Kubernetes Service targeting Redis pods | [bootstrapping.yaml](example/redisfailover/bootstrapping.yaml) |
| port | _optional_ | The Port that the target Redis address is listening to. Defaults to `6379`. | [bootstrapping-with-port.yaml](example/redisfailover/bootstrapping-with-port.yaml) |
| allowSentinels | _optional_ | Allow the Operator to also create the specified Sentinel resources and point them to the target Node/Port. By default, the Sentinel resources will **not** be created when bootstrapping. | [bootstrapping-with-sentinels.yaml](example/redisfailover/bootstrapping-with-sentinels.yaml) |
| enabled | _optional_ | By default, Bootstrap mode is activated, prompting Redis nodes to attempt a connection with the source host. However, if this parameter is set to `false', Redis will instead establish a cluster among the local nodes. In this scenario, a master node will be designated, to which the replica nodes will connect | [bootstrapping-disabled.yaml](example/redisfailover/bootstrapping-disabled.yaml) |
rurkss marked this conversation as resolved.
Show resolved Hide resolved

#### What is Bootstrapping?
When a `bootstrapNode` is provided, the Operator will always set all of the defined Redis instances to replicate from the provided `bootstrapNode` host value.
Expand Down
12 changes: 12 additions & 0 deletions example/redisfailover/bootstrapping-disabled.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: databases.spotahome.com/v1
kind: RedisFailover
metadata:
name: redisfailover
spec:
bootstrapNode:
host: "127.0.0.1"
enabled: false
sentinel:
replicas: 3
redis:
replicas: 3
3 changes: 3 additions & 0 deletions manifests/databases.spotahome.com_redisfailovers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ spec:
properties:
allowSentinels:
type: boolean
enabled:
default: true
type: boolean
host:
type: string
port:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ spec:
properties:
allowSentinels:
type: boolean
enabled:
default: true
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,
indiebrain marked this conversation as resolved.
Show resolved Hide resolved
}
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: true,
}
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