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

Fix configuration timeout defaulting #15617

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
13 changes: 13 additions & 0 deletions pkg/apis/serving/v1/configuration_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import (
"context"

"knative.dev/pkg/apis"
"knative.dev/serving/pkg/apis/config"
"knative.dev/serving/pkg/apis/serving"
cconfig "knative.dev/serving/pkg/reconciler/configuration/config"
)

type configSpecKey struct{}
Expand Down Expand Up @@ -67,5 +69,16 @@ func (cs *ConfigurationSpec) SetDefaults(ctx context.Context) {
return
}
}

configurationConfig := cconfig.FromContext(ctx)
apisConfig := config.Config{}
if configurationConfig != nil && configurationConfig.Defaults != nil {
apisConfig.Defaults = configurationConfig.Defaults.DeepCopy()
}
if configurationConfig != nil && configurationConfig.Features != nil {
apisConfig.Features = configurationConfig.Features.DeepCopy()
}
ctx = config.ToContext(ctx, &apisConfig)

cs.Template.SetDefaults(ctx)
}
56 changes: 55 additions & 1 deletion pkg/apis/serving/v1/configuration_defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"knative.dev/pkg/apis"
logtesting "knative.dev/pkg/logging/testing"
"knative.dev/pkg/ptr"

"knative.dev/serving/pkg/apis/config"
"knative.dev/serving/pkg/apis/serving"
cconfig "knative.dev/serving/pkg/reconciler/configuration/config"
)

func TestConfigurationDefaulting(t *testing.T) {
Expand Down Expand Up @@ -156,6 +157,59 @@ func TestConfigurationDefaulting(t *testing.T) {
},
},
},
}, {
name: "run latest with identical timeout defaults",
in: &Configuration{
Spec: ConfigurationSpec{
Template: RevisionTemplateSpec{
Spec: RevisionSpec{
PodSpec: corev1.PodSpec{
EnableServiceLinks: ptr.Bool(true),
Containers: []corev1.Container{{
Image: "busybox",
}},
},
ContainerConcurrency: ptr.Int64(config.DefaultContainerConcurrency),
},
},
},
},
want: &Configuration{
Spec: ConfigurationSpec{
Template: RevisionTemplateSpec{
Spec: RevisionSpec{
PodSpec: corev1.PodSpec{
EnableServiceLinks: ptr.Bool(true),
Containers: []corev1.Container{{
Name: config.DefaultUserContainerName,
Image: "busybox",
Resources: defaultResources,
ReadinessProbe: defaultProbe,
}},
},
TimeoutSeconds: ptr.Int64(423),
ContainerConcurrency: ptr.Int64(config.DefaultContainerConcurrency),
},
},
},
},
ctx: func() context.Context {
logger := logtesting.TestLogger(t)
s := cconfig.NewStore(logger)
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-response-start-timeout-seconds": "423",
"revision-idle-timeout-seconds": "423",
},
})

return s.ToContext(context.Background())
}(),
}}

for _, test := range tests {
Expand Down
31 changes: 31 additions & 0 deletions pkg/apis/serving/v1/revision_defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,37 @@ func TestRevisionDefaulting(t *testing.T) {
},
},
},
}, {
name: "Some revision timeouts set with identical values",
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-response-start-timeout-seconds": "423",
},
})
return s.ToContext(ctx)
},
want: &Revision{
Spec: RevisionSpec{
ContainerConcurrency: ptr.Int64(0),
TimeoutSeconds: ptr.Int64(423),
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
Loading