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

Default timeoutSecond and failureThreshold values when the user opts into K8s probing #5741

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 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: 8 additions & 0 deletions pkg/apis/serving/v1/revision_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,15 @@ func (rs *RevisionSpec) SetDefaults(ctx context.Context) {
if rs.PodSpec.Containers[idx].ReadinessProbe.SuccessThreshold == 0 {
rs.PodSpec.Containers[idx].ReadinessProbe.SuccessThreshold = 1
}
if rs.PodSpec.Containers[idx].ReadinessProbe.PeriodSeconds != 0 {
dineshba marked this conversation as resolved.
Show resolved Hide resolved
if rs.PodSpec.Containers[idx].ReadinessProbe.FailureThreshold == 0 {
rs.PodSpec.Containers[idx].ReadinessProbe.FailureThreshold = 3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where are those defaults coming from?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vagababov https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#configure-probes

timeoutSeconds: Number of seconds after which the probe times out. Defaults to 1 second. Minimum value is 1.
failureThreshold: When a Pod starts and the probe fails, Kubernetes will try failureThreshold times before giving up. Giving up in case of liveness probe means restarting the container. In case of readiness probe the Pod will be marked Unready. Defaults to 3. Minimum value is 1.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should they be named constant with a comment where you got them from?

}

if rs.PodSpec.Containers[idx].ReadinessProbe.TimeoutSeconds == 0 {
rs.PodSpec.Containers[idx].ReadinessProbe.TimeoutSeconds = 10
dineshba marked this conversation as resolved.
Show resolved Hide resolved
}
}
vms := rs.PodSpec.Containers[idx].VolumeMounts
for i := range vms {
vms[i].ReadOnly = true
Expand Down
143 changes: 143 additions & 0 deletions pkg/apis/serving/v1/revision_defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ func TestRevisionDefaulting(t *testing.T) {
Resources: defaultResources,
ReadinessProbe: &corev1.Probe{
SuccessThreshold: 1,
PeriodSeconds: 0,
FailureThreshold: 0,
TimeoutSeconds: 0,
Handler: corev1.Handler{
TCPSocket: &corev1.TCPSocketAction{
Host: "127.0.0.2",
Expand Down Expand Up @@ -228,6 +231,146 @@ func TestRevisionDefaulting(t *testing.T) {
},
},
},
}, {
name: "with zero period seconds and zero failure threshold",
in: &Revision{
Spec: RevisionSpec{
PodSpec: corev1.PodSpec{
Containers: []corev1.Container{{
ReadinessProbe: &corev1.Probe{
PeriodSeconds: 0,
TimeoutSeconds: 15,
},
}},
},
},
},
want: &Revision{
Spec: RevisionSpec{
TimeoutSeconds: ptr.Int64(config.DefaultRevisionTimeoutSeconds),
ContainerConcurrency: ptr.Int64(config.DefaultContainerConcurrency),
PodSpec: corev1.PodSpec{
Containers: []corev1.Container{{
Name: config.DefaultUserContainerName,
Resources: defaultResources,
ReadinessProbe: &corev1.Probe{
SuccessThreshold: 1,
PeriodSeconds: 0,
FailureThreshold: 0,
TimeoutSeconds: 15,
Handler: corev1.Handler{
TCPSocket: &corev1.TCPSocketAction{},
},
},
}},
},
},
},
}, {
name: "with zero period seconds and zero timeout second",
in: &Revision{
Spec: RevisionSpec{
PodSpec: corev1.PodSpec{
Containers: []corev1.Container{{
ReadinessProbe: &corev1.Probe{
PeriodSeconds: 0,
FailureThreshold: 4,
},
}},
},
},
},
want: &Revision{
Spec: RevisionSpec{
TimeoutSeconds: ptr.Int64(config.DefaultRevisionTimeoutSeconds),
ContainerConcurrency: ptr.Int64(config.DefaultContainerConcurrency),
PodSpec: corev1.PodSpec{
Containers: []corev1.Container{{
Name: config.DefaultUserContainerName,
Resources: defaultResources,
ReadinessProbe: &corev1.Probe{
SuccessThreshold: 1,
PeriodSeconds: 0,
FailureThreshold: 4,
TimeoutSeconds: 0,
Handler: corev1.Handler{
TCPSocket: &corev1.TCPSocketAction{},
},
},
}},
},
},
},
}, {
name: "with non zero period seconds and zero failure threshold",
in: &Revision{
Spec: RevisionSpec{
PodSpec: corev1.PodSpec{
Containers: []corev1.Container{{
ReadinessProbe: &corev1.Probe{
PeriodSeconds: 10,
TimeoutSeconds: 15,
},
}},
},
},
},
want: &Revision{
Spec: RevisionSpec{
TimeoutSeconds: ptr.Int64(config.DefaultRevisionTimeoutSeconds),
ContainerConcurrency: ptr.Int64(config.DefaultContainerConcurrency),
PodSpec: corev1.PodSpec{
Containers: []corev1.Container{{
Name: config.DefaultUserContainerName,
Resources: defaultResources,
ReadinessProbe: &corev1.Probe{
SuccessThreshold: 1,
PeriodSeconds: 10,
FailureThreshold: 3,
TimeoutSeconds: 15,
Handler: corev1.Handler{
TCPSocket: &corev1.TCPSocketAction{},
},
},
}},
},
},
},
}, {
name: "with non zero period seconds and zero timeout second",
in: &Revision{
Spec: RevisionSpec{
PodSpec: corev1.PodSpec{
Containers: []corev1.Container{{
ReadinessProbe: &corev1.Probe{
PeriodSeconds: 10,
FailureThreshold: 4,
},
}},
},
},
},
want: &Revision{
Spec: RevisionSpec{
TimeoutSeconds: ptr.Int64(config.DefaultRevisionTimeoutSeconds),
ContainerConcurrency: ptr.Int64(config.DefaultContainerConcurrency),
PodSpec: corev1.PodSpec{
Containers: []corev1.Container{{
Name: config.DefaultUserContainerName,
Resources: defaultResources,
ReadinessProbe: &corev1.Probe{
SuccessThreshold: 1,
PeriodSeconds: 10,
FailureThreshold: 4,
TimeoutSeconds: 10,
Handler: corev1.Handler{
TCPSocket: &corev1.TCPSocketAction{},
},
},
}},
},
},
},
}, {
name: "partially initialized",
in: &Revision{
Expand Down