Skip to content

Commit 8bcd960

Browse files
authored
Merge pull requesNonet #646 from spotahome/checker-service
Expect surge in running pods and avoid redis public expose
2 parents 469fbcb + b2686ac commit 8bcd960

File tree

4 files changed

+29
-14
lines changed

4 files changed

+29
-14
lines changed

operator/redisfailover/service/check.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
redisfailoverv1 "github.com/spotahome/redis-operator/api/redisfailover/v1"
1313
"github.com/spotahome/redis-operator/log"
1414
"github.com/spotahome/redis-operator/metrics"
15+
"github.com/spotahome/redis-operator/operator/redisfailover/util"
1516
"github.com/spotahome/redis-operator/service/k8s"
1617
"github.com/spotahome/redis-operator/service/redis"
1718
)
@@ -498,10 +499,13 @@ func getRedisPort(p int32) string {
498499
func AreAllRunning(pods *corev1.PodList, expectedRunningPods int) bool {
499500
var runningPods int
500501
for _, pod := range pods.Items {
501-
if pod.Status.Phase != corev1.PodRunning || pod.DeletionTimestamp != nil {
502+
if util.PodIsScheduling(&pod) {
503+
return false
504+
}
505+
if util.PodIsTerminal(&pod) {
502506
continue
503507
}
504508
runningPods++
505509
}
506-
return runningPods == expectedRunningPods
510+
return runningPods >= expectedRunningPods
507511
}

operator/redisfailover/service/generator.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func generateRedisMasterService(rf *redisfailoverv1.RedisFailover, labels map[st
130130
Annotations: rf.Spec.Redis.ServiceAnnotations,
131131
},
132132
Spec: corev1.ServiceSpec{
133-
Type: corev1.ServiceTypeLoadBalancer,
133+
Type: corev1.ServiceTypeClusterIP,
134134
Ports: []corev1.ServicePort{
135135
{
136136
Name: "redis",
@@ -163,7 +163,7 @@ func generateRedisSlaveService(rf *redisfailoverv1.RedisFailover, labels map[str
163163
Annotations: rf.Spec.Redis.ServiceAnnotations,
164164
},
165165
Spec: corev1.ServiceSpec{
166-
Type: corev1.ServiceTypeLoadBalancer,
166+
Type: corev1.ServiceTypeClusterIP,
167167
Ports: []corev1.ServicePort{
168168
{
169169
Name: "redis",

operator/redisfailover/service/generator_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,7 +1322,7 @@ func TestRedisMasterService(t *testing.T) {
13221322
},
13231323
},
13241324
Spec: corev1.ServiceSpec{
1325-
Type: corev1.ServiceTypeLoadBalancer,
1325+
Type: corev1.ServiceTypeClusterIP,
13261326
Selector: map[string]string{
13271327
"app.kubernetes.io/component": "redis",
13281328
"app.kubernetes.io/name": name,
@@ -1361,7 +1361,7 @@ func TestRedisMasterService(t *testing.T) {
13611361
},
13621362
},
13631363
Spec: corev1.ServiceSpec{
1364-
Type: corev1.ServiceTypeLoadBalancer,
1364+
Type: corev1.ServiceTypeClusterIP,
13651365
Selector: map[string]string{
13661366
"app.kubernetes.io/component": "redis",
13671367
"app.kubernetes.io/name": "custom-name",
@@ -1400,7 +1400,7 @@ func TestRedisMasterService(t *testing.T) {
14001400
},
14011401
},
14021402
Spec: corev1.ServiceSpec{
1403-
Type: corev1.ServiceTypeLoadBalancer,
1403+
Type: corev1.ServiceTypeClusterIP,
14041404
Selector: map[string]string{
14051405
"app.kubernetes.io/component": "redis",
14061406
"app.kubernetes.io/name": name,
@@ -1440,7 +1440,7 @@ func TestRedisMasterService(t *testing.T) {
14401440
},
14411441
},
14421442
Spec: corev1.ServiceSpec{
1443-
Type: corev1.ServiceTypeLoadBalancer,
1443+
Type: corev1.ServiceTypeClusterIP,
14441444
Selector: map[string]string{
14451445
"app.kubernetes.io/component": "redis",
14461446
"app.kubernetes.io/name": name,
@@ -1481,7 +1481,7 @@ func TestRedisMasterService(t *testing.T) {
14811481
},
14821482
},
14831483
Spec: corev1.ServiceSpec{
1484-
Type: corev1.ServiceTypeLoadBalancer,
1484+
Type: corev1.ServiceTypeClusterIP,
14851485
Selector: map[string]string{
14861486
"app.kubernetes.io/component": "redis",
14871487
"app.kubernetes.io/name": name,
@@ -1562,7 +1562,7 @@ func TestRedisSlaveService(t *testing.T) {
15621562
},
15631563
},
15641564
Spec: corev1.ServiceSpec{
1565-
Type: corev1.ServiceTypeLoadBalancer,
1565+
Type: corev1.ServiceTypeClusterIP,
15661566
Selector: map[string]string{
15671567
"app.kubernetes.io/component": "redis",
15681568
"app.kubernetes.io/name": name,
@@ -1601,7 +1601,7 @@ func TestRedisSlaveService(t *testing.T) {
16011601
},
16021602
},
16031603
Spec: corev1.ServiceSpec{
1604-
Type: corev1.ServiceTypeLoadBalancer,
1604+
Type: corev1.ServiceTypeClusterIP,
16051605
Selector: map[string]string{
16061606
"app.kubernetes.io/component": "redis",
16071607
"app.kubernetes.io/name": "custom-name",
@@ -1640,7 +1640,7 @@ func TestRedisSlaveService(t *testing.T) {
16401640
},
16411641
},
16421642
Spec: corev1.ServiceSpec{
1643-
Type: corev1.ServiceTypeLoadBalancer,
1643+
Type: corev1.ServiceTypeClusterIP,
16441644
Selector: map[string]string{
16451645
"app.kubernetes.io/component": "redis",
16461646
"app.kubernetes.io/name": name,
@@ -1680,7 +1680,7 @@ func TestRedisSlaveService(t *testing.T) {
16801680
},
16811681
},
16821682
Spec: corev1.ServiceSpec{
1683-
Type: corev1.ServiceTypeLoadBalancer,
1683+
Type: corev1.ServiceTypeClusterIP,
16841684
Selector: map[string]string{
16851685
"app.kubernetes.io/component": "redis",
16861686
"app.kubernetes.io/name": name,
@@ -1721,7 +1721,7 @@ func TestRedisSlaveService(t *testing.T) {
17211721
},
17221722
},
17231723
Spec: corev1.ServiceSpec{
1724-
Type: corev1.ServiceTypeLoadBalancer,
1724+
Type: corev1.ServiceTypeClusterIP,
17251725
Selector: map[string]string{
17261726
"app.kubernetes.io/component": "redis",
17271727
"app.kubernetes.io/name": name,

operator/redisfailover/util/pod.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package util
2+
3+
import v1 "k8s.io/api/core/v1"
4+
5+
func PodIsTerminal(pod *v1.Pod) bool {
6+
return pod.Status.Phase == v1.PodFailed || pod.Status.Phase == v1.PodSucceeded
7+
}
8+
9+
func PodIsScheduling(pod *v1.Pod) bool {
10+
return pod.DeletionTimestamp != nil || pod.Status.Phase == v1.PodPending
11+
}

0 commit comments

Comments
 (0)