Repository: spotahome/redis-operator (go)

Issue:
Sentinel Readiness is ready when really not
### Expected behaviour

The K8s sentinel service should not include endpoints (sentinels) that have local master, 127.0.0.1

### Actual behavior

The readiness check will gladly put a sentinel's endpoint into the service even though it is not registered with the cluster yet

### Steps to reproduce the behaviour

Get lucky and point an app at the k8s sentinel service when a new sentinel pod just comes up and watch the app fail trying to connect to master @ 127.0.0.1

The bug/fix should be pretty simple, the readiness check needs to ensure that the sentinel is indeed connected to a cluster of more than itself at the very least, something like this:

```
if [ `redis-cli -p 26379 sentinel CKQUORUM mymaster | awk '{print $2}'`  -gt 1 ] ; then exit 0; fi
```

I can submit a PR, but wondering how deep you want to go, make the `readiness check` for sentinel a configurable option, changing the CRD etc... (ugh)  or just use an iteration of the above as the baked in check?


Pull request:
fix: sentinel readiness probe to fail when monitoring localhost
Original PR: #558 
Fixes #532  .

Changes proposed on the PR:
-  Readiness check for sentinel shall fail when it doesn't monitor the right master, at least when we know that it monitors the wrong one which is 127.0.0.1
-  There'll be dependency on grep and head existing on the redis image used for sentinels. I tested alpine and bullseye in the official redis images [here](https://hub.docker.com/_/redis) and they worked as expected.

I think we should have customised readiness and liveness checks in the future as well but for now this should be enough.

Patch:
diff --git a/charts/redisoperator/Chart.yaml b/charts/redisoperator/Chart.yaml
index a22af3c8..57d1003e 100644
--- a/charts/redisoperator/Chart.yaml
+++ b/charts/redisoperator/Chart.yaml
@@ -4,7 +4,7 @@ appVersion: 1.2.4
 apiVersion: v1
 description: A Helm chart for the Spotahome Redis Operator
 name: redis-operator
-version: 3.2.7
+version: 3.2.8
 home: https://github.com/spotahome/redis-operator
 keywords:
   - "golang"
diff --git a/operator/redisfailover/service/generator.go b/operator/redisfailover/service/generator.go
index 8f78cbce..e423850a 100644
--- a/operator/redisfailover/service/generator.go
+++ b/operator/redisfailover/service/generator.go
@@ -567,7 +567,7 @@ func generateSentinelDeployment(rf *redisfailoverv1.RedisFailover, labels map[st
 					Command: []string{
 						"sh",
 						"-c",
-						"redis-cli -h $(hostname) -p 26379 ping",
+						"redis-cli -h $(hostname) -p 26379 sentinel get-master-addr-by-name mymaster | head -n 1 | grep -vq '127.0.0.1'",
 					},
 				},
 			},


Test patch:
diff --git a/operator/redisfailover/service/generator_test.go b/operator/redisfailover/service/generator_test.go
index 45bd8525..7cfa1546 100644
--- a/operator/redisfailover/service/generator_test.go
+++ b/operator/redisfailover/service/generator_test.go
@@ -2158,7 +2158,7 @@ func TestSentinelCustomReadinessProbe(t *testing.T) {
 						Command: []string{
 							"sh",
 							"-c",
-							"redis-cli -h $(hostname) -p 26379 ping",
+							"redis-cli -h $(hostname) -p 26379 sentinel get-master-addr-by-name mymaster | head -n 1 | grep -vq '127.0.0.1'",
 						},
 					},
 				},