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 2 commits 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)

Comment on lines +73 to +82
Copy link
Member

Choose a reason for hiding this comment

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

configurationConfig := cconfig.FromContext(ctx)

This will always be nil - the webhook has a config map watcher that updates the api's config store.

Copy link
Member

@dprotaso dprotaso Jan 16, 2025

Choose a reason for hiding this comment

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

I think we need a different fix - but I haven't dug into why the default of 300 is being applied - when in fact the default is here and it should be using what's in the config map

nc.RevisionResponseStartTimeoutSeconds = nc.RevisionTimeoutSeconds
if err := cm.Parse(data,
cm.AsInt64("revision-response-start-timeout-seconds", &nc.RevisionResponseStartTimeoutSeconds),
); err != nil {
return nil, err
}

Copy link
Member

@dprotaso dprotaso Jan 16, 2025

Choose a reason for hiding this comment

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

I think this has only been an issue because before when we default we set all the properties - but this one setting is different

Copy link
Member

Choose a reason for hiding this comment

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

The fix should be to add the apiconfig.Store into the context using the same key that's in the apiconfig package

eg. here

func (s *Store) ToContext(ctx context.Context) context.Context {

we should call

func ToContext(ctx context.Context, c *Config) context.Context {

Other stores in reconciler could have similar issues

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dprotaso have you checked the description of the root cause here: #15616?

cs.Template.SetDefaults(ctx)
}
63 changes: 62 additions & 1 deletion pkg/apis/serving/v1/configuration_defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,25 @@ package v1

import (
"context"
"fmt"
"testing"

"github.com/google/go-cmp/cmp"
"go.uber.org/zap"
authv1 "k8s.io/api/authentication/v1"
corev1 "k8s.io/api/core/v1"
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"
)

const defaultTimeoutSeconds = 400

func TestConfigurationDefaulting(t *testing.T) {
tests := []struct {
name string
Expand Down Expand Up @@ -156,6 +161,52 @@ 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(defaultTimeoutSeconds),
ContainerConcurrency: ptr.Int64(config.DefaultContainerConcurrency),
},
},
},
},
ctx: defaultConfigurationContextWithStore(logtesting.TestLogger(t), corev1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Name: config.FeaturesConfigName}},
corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: config.DefaultsConfigName,
},
Data: map[string]string{
"revision-timeout-seconds": fmt.Sprintf("%d", defaultTimeoutSeconds),
"revision-response-start-timeout-seconds": fmt.Sprintf("%d", defaultTimeoutSeconds),
"revision-idle-timeout-seconds": fmt.Sprintf("%d", defaultTimeoutSeconds),
}})(context.Background()),
}}

for _, test := range tests {
Expand Down Expand Up @@ -328,3 +379,13 @@ func TestConfigurationUserInfo(t *testing.T) {
})
}
}

func defaultConfigurationContextWithStore(logger *zap.SugaredLogger, cms ...corev1.ConfigMap) func(ctx context.Context) context.Context {
return func(ctx context.Context) context.Context {
s := cconfig.NewStore(logger)
for _, cm := range cms {
s.OnConfigChanged(&cm)
}
return s.ToContext(ctx)
}
}
Loading
Loading