Skip to content

Commit

Permalink
Merge pull requesNonet spotahome#646 from spotahome/checker-service
Browse files Browse the repository at this point in the history
Expect surge in running pods and avoid redis public expose
  • Loading branch information
ese authored Aug 19, 2023
2 parents 469fbcb + b2686ac commit 8bcd960
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 deletions.
8 changes: 6 additions & 2 deletions operator/redisfailover/service/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
redisfailoverv1 "github.com/spotahome/redis-operator/api/redisfailover/v1"
"github.com/spotahome/redis-operator/log"
"github.com/spotahome/redis-operator/metrics"
"github.com/spotahome/redis-operator/operator/redisfailover/util"
"github.com/spotahome/redis-operator/service/k8s"
"github.com/spotahome/redis-operator/service/redis"
)
Expand Down Expand Up @@ -498,10 +499,13 @@ func getRedisPort(p int32) string {
func AreAllRunning(pods *corev1.PodList, expectedRunningPods int) bool {
var runningPods int
for _, pod := range pods.Items {
if pod.Status.Phase != corev1.PodRunning || pod.DeletionTimestamp != nil {
if util.PodIsScheduling(&pod) {
return false
}
if util.PodIsTerminal(&pod) {
continue
}
runningPods++
}
return runningPods == expectedRunningPods
return runningPods >= expectedRunningPods
}
4 changes: 2 additions & 2 deletions operator/redisfailover/service/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func generateRedisMasterService(rf *redisfailoverv1.RedisFailover, labels map[st
Annotations: rf.Spec.Redis.ServiceAnnotations,
},
Spec: corev1.ServiceSpec{
Type: corev1.ServiceTypeLoadBalancer,
Type: corev1.ServiceTypeClusterIP,
Ports: []corev1.ServicePort{
{
Name: "redis",
Expand Down Expand Up @@ -163,7 +163,7 @@ func generateRedisSlaveService(rf *redisfailoverv1.RedisFailover, labels map[str
Annotations: rf.Spec.Redis.ServiceAnnotations,
},
Spec: corev1.ServiceSpec{
Type: corev1.ServiceTypeLoadBalancer,
Type: corev1.ServiceTypeClusterIP,
Ports: []corev1.ServicePort{
{
Name: "redis",
Expand Down
20 changes: 10 additions & 10 deletions operator/redisfailover/service/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1322,7 +1322,7 @@ func TestRedisMasterService(t *testing.T) {
},
},
Spec: corev1.ServiceSpec{
Type: corev1.ServiceTypeLoadBalancer,
Type: corev1.ServiceTypeClusterIP,
Selector: map[string]string{
"app.kubernetes.io/component": "redis",
"app.kubernetes.io/name": name,
Expand Down Expand Up @@ -1361,7 +1361,7 @@ func TestRedisMasterService(t *testing.T) {
},
},
Spec: corev1.ServiceSpec{
Type: corev1.ServiceTypeLoadBalancer,
Type: corev1.ServiceTypeClusterIP,
Selector: map[string]string{
"app.kubernetes.io/component": "redis",
"app.kubernetes.io/name": "custom-name",
Expand Down Expand Up @@ -1400,7 +1400,7 @@ func TestRedisMasterService(t *testing.T) {
},
},
Spec: corev1.ServiceSpec{
Type: corev1.ServiceTypeLoadBalancer,
Type: corev1.ServiceTypeClusterIP,
Selector: map[string]string{
"app.kubernetes.io/component": "redis",
"app.kubernetes.io/name": name,
Expand Down Expand Up @@ -1440,7 +1440,7 @@ func TestRedisMasterService(t *testing.T) {
},
},
Spec: corev1.ServiceSpec{
Type: corev1.ServiceTypeLoadBalancer,
Type: corev1.ServiceTypeClusterIP,
Selector: map[string]string{
"app.kubernetes.io/component": "redis",
"app.kubernetes.io/name": name,
Expand Down Expand Up @@ -1481,7 +1481,7 @@ func TestRedisMasterService(t *testing.T) {
},
},
Spec: corev1.ServiceSpec{
Type: corev1.ServiceTypeLoadBalancer,
Type: corev1.ServiceTypeClusterIP,
Selector: map[string]string{
"app.kubernetes.io/component": "redis",
"app.kubernetes.io/name": name,
Expand Down Expand Up @@ -1562,7 +1562,7 @@ func TestRedisSlaveService(t *testing.T) {
},
},
Spec: corev1.ServiceSpec{
Type: corev1.ServiceTypeLoadBalancer,
Type: corev1.ServiceTypeClusterIP,
Selector: map[string]string{
"app.kubernetes.io/component": "redis",
"app.kubernetes.io/name": name,
Expand Down Expand Up @@ -1601,7 +1601,7 @@ func TestRedisSlaveService(t *testing.T) {
},
},
Spec: corev1.ServiceSpec{
Type: corev1.ServiceTypeLoadBalancer,
Type: corev1.ServiceTypeClusterIP,
Selector: map[string]string{
"app.kubernetes.io/component": "redis",
"app.kubernetes.io/name": "custom-name",
Expand Down Expand Up @@ -1640,7 +1640,7 @@ func TestRedisSlaveService(t *testing.T) {
},
},
Spec: corev1.ServiceSpec{
Type: corev1.ServiceTypeLoadBalancer,
Type: corev1.ServiceTypeClusterIP,
Selector: map[string]string{
"app.kubernetes.io/component": "redis",
"app.kubernetes.io/name": name,
Expand Down Expand Up @@ -1680,7 +1680,7 @@ func TestRedisSlaveService(t *testing.T) {
},
},
Spec: corev1.ServiceSpec{
Type: corev1.ServiceTypeLoadBalancer,
Type: corev1.ServiceTypeClusterIP,
Selector: map[string]string{
"app.kubernetes.io/component": "redis",
"app.kubernetes.io/name": name,
Expand Down Expand Up @@ -1721,7 +1721,7 @@ func TestRedisSlaveService(t *testing.T) {
},
},
Spec: corev1.ServiceSpec{
Type: corev1.ServiceTypeLoadBalancer,
Type: corev1.ServiceTypeClusterIP,
Selector: map[string]string{
"app.kubernetes.io/component": "redis",
"app.kubernetes.io/name": name,
Expand Down
11 changes: 11 additions & 0 deletions operator/redisfailover/util/pod.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package util

import v1 "k8s.io/api/core/v1"

func PodIsTerminal(pod *v1.Pod) bool {
return pod.Status.Phase == v1.PodFailed || pod.Status.Phase == v1.PodSucceeded
}

func PodIsScheduling(pod *v1.Pod) bool {
return pod.DeletionTimestamp != nil || pod.Status.Phase == v1.PodPending
}

0 comments on commit 8bcd960

Please sign in to comment.