Skip to content

Commit 1f4c4ef

Browse files
authored
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.
1 parent dfc7de9 commit 1f4c4ef

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Also check this project's [releases](https://github.com/powerhome/redis-operator
1111

1212
### Changed
1313

14+
- Add default haproxy image #47
1415
- Update metrics exporter images #45
1516

1617
## [v2.0.2] - 2024-02-13

api/redisfailover/v1/defaults.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const (
66
defaultSentinelExporterImage = "leominov/redis_sentinel_exporter:1.7.1"
77
defaultExporterImage = "quay.io/oliver006/redis_exporter:v1.57.0"
88
defaultImage = "redis:6.2.6-alpine"
9+
defaultHAProxyImage = "haproxy:2.4"
910
defaultRedisPort = 6379
1011
)
1112

api/redisfailover/v1/validate.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ func (r *RedisFailover) Validate() error {
6767
r.Spec.Sentinel.CustomConfig = defaultSentinelCustomConfig
6868
}
6969

70+
if r.Spec.Haproxy != nil {
71+
if r.Spec.Haproxy.Image == "" {
72+
r.Spec.Haproxy.Image = defaultHAProxyImage
73+
}
74+
}
75+
7076
return nil
7177
}
7278

api/redisfailover/v1/validate_test.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ func TestValidate(t *testing.T) {
1616
rfSentinelCustomConfig []string
1717
expectedError string
1818
expectedBootstrapNode *BootstrapSettings
19+
rfHAProxyConfig *HaproxySettings
20+
expectedHAProxyConfig *HaproxySettings
1921
}{
2022
{
2123
name: "populates default values",
@@ -65,6 +67,18 @@ func TestValidate(t *testing.T) {
6567
rfBootstrapNode: &BootstrapSettings{Host: "127.0.0.1", Enabled: true},
6668
expectedBootstrapNode: &BootstrapSettings{Host: "127.0.0.1", Port: "6379", Enabled: true},
6769
},
70+
{
71+
name: "HAProxy config no image provided",
72+
rfName: "test",
73+
rfHAProxyConfig: &HaproxySettings{},
74+
expectedHAProxyConfig: &HaproxySettings{Image: defaultHAProxyImage},
75+
},
76+
{
77+
name: "HAProxy config custom image",
78+
rfName: "test",
79+
rfHAProxyConfig: &HaproxySettings{Image: "haproxy:0.0.1"},
80+
expectedHAProxyConfig: &HaproxySettings{Image: "haproxy:0.0.1"},
81+
},
6882
}
6983

7084
for _, test := range tests {
@@ -73,7 +87,7 @@ func TestValidate(t *testing.T) {
7387
rf := generateRedisFailover(test.rfName, test.rfBootstrapNode)
7488
rf.Spec.Redis.CustomConfig = test.rfRedisCustomConfig
7589
rf.Spec.Sentinel.CustomConfig = test.rfSentinelCustomConfig
76-
90+
rf.Spec.Haproxy = test.rfHAProxyConfig
7791
err := rf.Validate()
7892

7993
if test.expectedError == "" {
@@ -119,9 +133,11 @@ func TestValidate(t *testing.T) {
119133
},
120134
Port: Port(26379),
121135
},
136+
Haproxy: test.expectedHAProxyConfig,
122137
BootstrapNode: test.expectedBootstrapNode,
123138
},
124139
}
140+
125141
assert.Equal(expectedRF, rf)
126142
} else {
127143
if assert.Error(err) {

0 commit comments

Comments
 (0)