Skip to content

Commit

Permalink
Add default haproxy image (#47)
Browse files Browse the repository at this point in the history
Sets a default HAProxy image when one is not specified in the
RedisFailover CR. When the RedisFailover includes a HAProxy Spec, the
operator errors unless an Image attribute is present.
  • Loading branch information
indiebrain authored Feb 14, 2024
1 parent dfc7de9 commit 1f4c4ef
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Also check this project's [releases](https://github.com/powerhome/redis-operator

### Changed

- Add default haproxy image #47
- Update metrics exporter images #45

## [v2.0.2] - 2024-02-13
Expand Down
1 change: 1 addition & 0 deletions api/redisfailover/v1/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const (
defaultSentinelExporterImage = "leominov/redis_sentinel_exporter:1.7.1"
defaultExporterImage = "quay.io/oliver006/redis_exporter:v1.57.0"
defaultImage = "redis:6.2.6-alpine"
defaultHAProxyImage = "haproxy:2.4"
defaultRedisPort = 6379
)

Expand Down
6 changes: 6 additions & 0 deletions api/redisfailover/v1/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ func (r *RedisFailover) Validate() error {
r.Spec.Sentinel.CustomConfig = defaultSentinelCustomConfig
}

if r.Spec.Haproxy != nil {
if r.Spec.Haproxy.Image == "" {
r.Spec.Haproxy.Image = defaultHAProxyImage
}
}

return nil
}

Expand Down
18 changes: 17 additions & 1 deletion api/redisfailover/v1/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ func TestValidate(t *testing.T) {
rfSentinelCustomConfig []string
expectedError string
expectedBootstrapNode *BootstrapSettings
rfHAProxyConfig *HaproxySettings
expectedHAProxyConfig *HaproxySettings
}{
{
name: "populates default values",
Expand Down Expand Up @@ -65,6 +67,18 @@ func TestValidate(t *testing.T) {
rfBootstrapNode: &BootstrapSettings{Host: "127.0.0.1", Enabled: true},
expectedBootstrapNode: &BootstrapSettings{Host: "127.0.0.1", Port: "6379", Enabled: true},
},
{
name: "HAProxy config no image provided",
rfName: "test",
rfHAProxyConfig: &HaproxySettings{},
expectedHAProxyConfig: &HaproxySettings{Image: defaultHAProxyImage},
},
{
name: "HAProxy config custom image",
rfName: "test",
rfHAProxyConfig: &HaproxySettings{Image: "haproxy:0.0.1"},
expectedHAProxyConfig: &HaproxySettings{Image: "haproxy:0.0.1"},
},
}

for _, test := range tests {
Expand All @@ -73,7 +87,7 @@ func TestValidate(t *testing.T) {
rf := generateRedisFailover(test.rfName, test.rfBootstrapNode)
rf.Spec.Redis.CustomConfig = test.rfRedisCustomConfig
rf.Spec.Sentinel.CustomConfig = test.rfSentinelCustomConfig

rf.Spec.Haproxy = test.rfHAProxyConfig
err := rf.Validate()

if test.expectedError == "" {
Expand Down Expand Up @@ -119,9 +133,11 @@ func TestValidate(t *testing.T) {
},
Port: Port(26379),
},
Haproxy: test.expectedHAProxyConfig,
BootstrapNode: test.expectedBootstrapNode,
},
}

assert.Equal(expectedRF, rf)
} else {
if assert.Error(err) {
Expand Down

0 comments on commit 1f4c4ef

Please sign in to comment.