Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expect surge in running pods and avoid redis public expose #646

Merged
merged 4 commits into from
Aug 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}