Skip to content

Commit

Permalink
respect revision timeout defaults in cm (#14600)
Browse files Browse the repository at this point in the history
  • Loading branch information
skonto authored Nov 22, 2023
1 parent a0d2465 commit 32f2ba2
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
16 changes: 16 additions & 0 deletions pkg/apis/serving/v1/revision_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,22 @@ func (rs *RevisionSpec) SetDefaults(ctx context.Context) {
rs.TimeoutSeconds = ptr.Int64(cfg.Defaults.RevisionTimeoutSeconds)
}

// Default IdleTimeoutSeconds only in case we have a non-zero default and the latter is not larger than the revision timeout.
// A zero default or a zero value set from the user or a nil value skips timer setup at the QP side.
if rs.IdleTimeoutSeconds == nil {
if cfg.Defaults.RevisionIdleTimeoutSeconds < *rs.TimeoutSeconds && cfg.Defaults.RevisionIdleTimeoutSeconds != 0 {
rs.IdleTimeoutSeconds = ptr.Int64(cfg.Defaults.RevisionIdleTimeoutSeconds)
}
}

// Default ResponseStartTimeoutSeconds only in case we have a non-zero default and the latter is not larger than the revision timeout.
// A zero default or a zero value set from the user or a nil value skips timer setup at the QP side.
if rs.ResponseStartTimeoutSeconds == nil {
if cfg.Defaults.RevisionRequestStartTimeoutSeconds < *rs.TimeoutSeconds && cfg.Defaults.RevisionRequestStartTimeoutSeconds != 0 {
rs.ResponseStartTimeoutSeconds = ptr.Int64(cfg.Defaults.RevisionRequestStartTimeoutSeconds)
}
}

// Default ContainerConcurrency based on our configmap.
if rs.ContainerConcurrency == nil {
rs.ContainerConcurrency = ptr.Int64(cfg.Defaults.ContainerConcurrency)
Expand Down
34 changes: 34 additions & 0 deletions pkg/apis/serving/v1/revision_defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,40 @@ func TestRevisionDefaulting(t *testing.T) {
},
},
},
}, {
name: "all revision timeouts set",
in: &Revision{Spec: RevisionSpec{PodSpec: corev1.PodSpec{Containers: []corev1.Container{{}}}}},
wc: func(ctx context.Context) context.Context {
s := config.NewStore(logger)
s.OnConfigChanged(&corev1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Name: autoscalerconfig.ConfigName}})
s.OnConfigChanged(&corev1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Name: config.FeaturesConfigName}})
s.OnConfigChanged(&corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: config.DefaultsConfigName,
},
Data: map[string]string{
"revision-timeout-seconds": "423",
"revision-idle-timeout-seconds": "100",
"revision-response-start-timeout-seconds": "50",
},
})
return s.ToContext(ctx)
},
want: &Revision{
Spec: RevisionSpec{
ContainerConcurrency: ptr.Int64(0),
TimeoutSeconds: ptr.Int64(423),
ResponseStartTimeoutSeconds: ptr.Int64(50),
IdleTimeoutSeconds: ptr.Int64(100),
PodSpec: corev1.PodSpec{
Containers: []corev1.Container{{
Name: config.DefaultUserContainerName,
Resources: defaultResources,
ReadinessProbe: defaultProbe,
}},
},
},
},
}, {
name: "with context, in create, expect ESL set",
in: &Revision{Spec: RevisionSpec{PodSpec: corev1.PodSpec{Containers: []corev1.Container{{}}}}},
Expand Down

0 comments on commit 32f2ba2

Please sign in to comment.