From 1f4c4efc7a60b3137f4422f7ce8ac3afec23afe9 Mon Sep 17 00:00:00 2001 From: Aaron Kuehler Date: Wed, 14 Feb 2024 09:37:57 -0500 Subject: [PATCH] Add default haproxy image (#47) 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. --- CHANGELOG.md | 1 + api/redisfailover/v1/defaults.go | 1 + api/redisfailover/v1/validate.go | 6 ++++++ api/redisfailover/v1/validate_test.go | 18 +++++++++++++++++- 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e08636f85..f8f04c173 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/api/redisfailover/v1/defaults.go b/api/redisfailover/v1/defaults.go index 2d9869a3f..c3c45b402 100644 --- a/api/redisfailover/v1/defaults.go +++ b/api/redisfailover/v1/defaults.go @@ -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 ) diff --git a/api/redisfailover/v1/validate.go b/api/redisfailover/v1/validate.go index 3221d1041..c3db1a549 100644 --- a/api/redisfailover/v1/validate.go +++ b/api/redisfailover/v1/validate.go @@ -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 } diff --git a/api/redisfailover/v1/validate_test.go b/api/redisfailover/v1/validate_test.go index 7707b5825..8b49f839a 100644 --- a/api/redisfailover/v1/validate_test.go +++ b/api/redisfailover/v1/validate_test.go @@ -16,6 +16,8 @@ func TestValidate(t *testing.T) { rfSentinelCustomConfig []string expectedError string expectedBootstrapNode *BootstrapSettings + rfHAProxyConfig *HaproxySettings + expectedHAProxyConfig *HaproxySettings }{ { name: "populates default values", @@ -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 { @@ -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 == "" { @@ -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) {