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

Accept if readiness/liveness probes are the same but differ in threshold #366

Closed
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
6 changes: 6 additions & 0 deletions score/probe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ func TestProbesPodIdenticalTCP(t *testing.T) {
assert.Equal(t, "Container has the same readiness and liveness probe", comments[0].Summary)
}

func TestProbesPodTCPDifferentThresholds(t *testing.T) {
t.Parallel()
comments := testExpectedScore(t, "pod-probes-tcp-different-thresholds.yaml", "Pod Probes", scorecard.GradeAllOK)
assert.Len(t, comments, 0)
}

func TestProbesPodIdenticalExec(t *testing.T) {
t.Parallel()
comments := testExpectedScore(t, "pod-probes-identical-exec.yaml", "Pod Probes", scorecard.GradeCritical)
Expand Down
7 changes: 7 additions & 0 deletions score/probes/probes.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ func containerProbes(allServices []ks.Service) func(corev1.PodTemplateSpec, meta
}
}

// Accept if readiness/liveness probes are the same (e.g. port) but differ in threshold.
// Use case: restart container if application not ready for a longer time, which may work
// if application stalled or deadlocked.
if r.InitialDelaySeconds != l.InitialDelaySeconds || r.PeriodSeconds != l.PeriodSeconds || r.FailureThreshold != l.FailureThreshold {
probesAreIdentical = false
}

}
}

Expand Down
30 changes: 30 additions & 0 deletions score/testdata/pod-probes-tcp-different-thresholds.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
apiVersion: v1
kind: Pod
metadata:
name: pod-test-1
labels:
app: test
spec:
containers:
- name: foobar
image: foo/bar:latest
readinessProbe:
tcpSocket:
port: 8080
failureThreshold: 3
livenessProbe:
tcpSocket:
port: 8080
failureThreshold: 12
---
kind: Service
apiVersion: v1
metadata:
name: my-service
spec:
selector:
app: test
ports:
- protocol: TCP
port: 80
targetPort: 8080