diff --git a/pkg/apis/serving/v1/revision_defaults.go b/pkg/apis/serving/v1/revision_defaults.go index 0849af3742db..9c6e637db0d3 100644 --- a/pkg/apis/serving/v1/revision_defaults.go +++ b/pkg/apis/serving/v1/revision_defaults.go @@ -93,7 +93,18 @@ func (rs *RevisionSpec) applyDefault(container *corev1.Container, cfg *config.Co container.Resources.Limits[corev1.ResourceMemory] = *rm } } + if rs.PodSpec.Containers[idx].ReadinessProbe.SuccessThreshold == 0 { + rs.PodSpec.Containers[idx].ReadinessProbe.SuccessThreshold = 1 + } + if rs.PodSpec.Containers[idx].ReadinessProbe.PeriodSeconds != 0 { + if rs.PodSpec.Containers[idx].ReadinessProbe.FailureThreshold == 0 { + rs.PodSpec.Containers[idx].ReadinessProbe.FailureThreshold = 3 + } + if rs.PodSpec.Containers[idx].ReadinessProbe.TimeoutSeconds == 0 { + rs.PodSpec.Containers[idx].ReadinessProbe.TimeoutSeconds = 1 + } + } // If there are multiple containers then default probes will be applied to the container where user specified PORT // default probes will not be applied for non serving containers if len(rs.PodSpec.Containers) == 1 || len(container.Ports) != 0 { diff --git a/pkg/apis/serving/v1/revision_defaults_test.go b/pkg/apis/serving/v1/revision_defaults_test.go index 59583b8cb2e4..2a9a1e3d3d0a 100644 --- a/pkg/apis/serving/v1/revision_defaults_test.go +++ b/pkg/apis/serving/v1/revision_defaults_test.go @@ -184,6 +184,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", @@ -231,6 +234,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: 1, + Handler: corev1.Handler{ + TCPSocket: &corev1.TCPSocketAction{}, + }, + }, + }}, + }, + }, + }, }, { name: "partially initialized", in: &Revision{