Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
skonto committed Jan 20, 2025
1 parent c11b5c9 commit 5df6756
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 25 deletions.
3 changes: 2 additions & 1 deletion pkg/apis/serving/v1/configuration_defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ func TestConfigurationDefaulting(t *testing.T) {
"revision-timeout-seconds": strconv.Itoa(defaultTimeoutSeconds),
"revision-response-start-timeout-seconds": strconv.Itoa(defaultTimeoutSeconds),
"revision-idle-timeout-seconds": strconv.Itoa(defaultTimeoutSeconds),
}})(context.Background()),
},
})(context.Background()),
}}

for _, test := range tests {
Expand Down
40 changes: 25 additions & 15 deletions pkg/apis/serving/v1/revision_defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package v1

import (
"context"
"fmt"
"strconv"
"testing"

"github.com/google/go-cmp/cmp"
Expand Down Expand Up @@ -76,8 +76,9 @@ func TestRevisionDefaulting(t *testing.T) {
Name: config.DefaultsConfigName,
},
Data: map[string]string{
"revision-timeout-seconds": fmt.Sprintf("%d", defaultTimeoutSeconds),
}}),
"revision-timeout-seconds": strconv.Itoa(defaultTimeoutSeconds),
},
}),
want: &Revision{
Spec: RevisionSpec{
ContainerConcurrency: ptr.Int64(0),
Expand All @@ -101,10 +102,11 @@ func TestRevisionDefaulting(t *testing.T) {
Name: config.DefaultsConfigName,
},
Data: map[string]string{
"revision-timeout-seconds": fmt.Sprintf("%d", defaultTimeoutSeconds),
"revision-timeout-seconds": strconv.Itoa(defaultTimeoutSeconds),
"revision-idle-timeout-seconds": "100",
"revision-response-start-timeout-seconds": "50",
}}),
},
}),
want: &Revision{
Spec: RevisionSpec{
ContainerConcurrency: ptr.Int64(0),
Expand All @@ -128,9 +130,10 @@ func TestRevisionDefaulting(t *testing.T) {
Name: config.DefaultsConfigName,
},
Data: map[string]string{
"revision-timeout-seconds": fmt.Sprintf("%d", defaultTimeoutSeconds),
"revision-response-start-timeout-seconds": fmt.Sprintf("%d", defaultTimeoutSeconds),
}}),
"revision-timeout-seconds": strconv.Itoa(defaultTimeoutSeconds),
"revision-response-start-timeout-seconds": strconv.Itoa(defaultTimeoutSeconds),
},
}),
want: &Revision{
Spec: RevisionSpec{
ContainerConcurrency: ptr.Int64(0),
Expand All @@ -155,7 +158,8 @@ func TestRevisionDefaulting(t *testing.T) {
},
Data: map[string]string{
"revision-timeout-seconds": "323",
}}),
},
}),
want: &Revision{
Spec: RevisionSpec{
ContainerConcurrency: ptr.Int64(0),
Expand Down Expand Up @@ -186,7 +190,8 @@ func TestRevisionDefaulting(t *testing.T) {
},
Data: map[string]string{
"enable-service-links": "true",
}}),
},
}),
want: &Revision{
Spec: RevisionSpec{
ContainerConcurrency: ptr.Int64(0),
Expand All @@ -212,7 +217,8 @@ func TestRevisionDefaulting(t *testing.T) {
},
Data: map[string]string{
"enable-service-links": "true",
}}),
},
}),
want: &Revision{
Spec: RevisionSpec{
ContainerConcurrency: ptr.Int64(0),
Expand All @@ -238,7 +244,8 @@ func TestRevisionDefaulting(t *testing.T) {
},
Data: map[string]string{
"enable-service-links": "false",
}}),
},
}),
want: &Revision{
Spec: RevisionSpec{
ContainerConcurrency: ptr.Int64(0),
Expand Down Expand Up @@ -267,7 +274,8 @@ func TestRevisionDefaulting(t *testing.T) {
},
Data: map[string]string{
"enable-service-links": "true", // this should be ignored.
}}),
},
}),
want: &Revision{
Spec: RevisionSpec{
ContainerConcurrency: ptr.Int64(0),
Expand Down Expand Up @@ -329,7 +337,8 @@ func TestRevisionDefaulting(t *testing.T) {
},
Data: map[string]string{
"revision-timeout-seconds": "456",
}}),
},
}),
want: &Revision{
Spec: RevisionSpec{
ContainerConcurrency: ptr.Int64(0),
Expand Down Expand Up @@ -493,7 +502,8 @@ func TestRevisionDefaulting(t *testing.T) {
"revision-cpu-limit": "400M",
"revision-memory-limit": "500m",
"revision-ephemeral-storage-limit": "600M",
}}),
},
}),
want: &Revision{
Spec: RevisionSpec{
TimeoutSeconds: ptr.Int64(config.DefaultRevisionTimeoutSeconds),
Expand Down
17 changes: 8 additions & 9 deletions pkg/reconciler/configuration/config/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ import (

"knative.dev/pkg/configmap"
apisconfig "knative.dev/serving/pkg/apis/config"
cfgmap "knative.dev/serving/pkg/apis/config"
)

type cfgKey struct{}

// Config holds the collection of configurations that we attach to contexts.
type Config struct {
Defaults *cfgmap.Defaults
Features *cfgmap.Features
Defaults *apisconfig.Defaults
Features *apisconfig.Features
}

// FromContext extracts a Config from the provided context.
Expand All @@ -51,11 +50,11 @@ func FromContextOrDefaults(ctx context.Context) *Config {
}

if cfg.Defaults == nil {
cfg.Defaults, _ = cfgmap.NewDefaultsConfigFromMap(nil)
cfg.Defaults, _ = apisconfig.NewDefaultsConfigFromMap(nil)
}

if cfg.Features == nil {
cfg.Features, _ = cfgmap.NewFeaturesConfigFromMap(nil)
cfg.Features, _ = apisconfig.NewFeaturesConfigFromMap(nil)
}

return cfg
Expand Down Expand Up @@ -86,8 +85,8 @@ func NewStore(logger configmap.Logger, onAfterStore ...func(name string, value i
"apis",
logger,
configmap.Constructors{
cfgmap.DefaultsConfigName: cfgmap.NewDefaultsConfigFromConfigMap,
cfgmap.FeaturesConfigName: cfgmap.NewFeaturesConfigFromConfigMap,
apisconfig.DefaultsConfigName: apisconfig.NewDefaultsConfigFromConfigMap,
apisconfig.FeaturesConfigName: apisconfig.NewFeaturesConfigFromConfigMap,
},
onAfterStore...,
),
Expand All @@ -104,10 +103,10 @@ func (s *Store) ToContext(ctx context.Context) context.Context {
// Load creates a Config from the current config state of the Store.
func (s *Store) Load() *Config {
cfg := &Config{}
if def, ok := s.UntypedLoad(cfgmap.DefaultsConfigName).(*cfgmap.Defaults); ok {
if def, ok := s.UntypedLoad(apisconfig.DefaultsConfigName).(*apisconfig.Defaults); ok {
cfg.Defaults = def.DeepCopy()
}
if feat, ok := s.UntypedLoad(cfgmap.FeaturesConfigName).(*cfgmap.Features); ok {
if feat, ok := s.UntypedLoad(apisconfig.FeaturesConfigName).(*apisconfig.Features); ok {
cfg.Features = feat.DeepCopy()
}

Expand Down

0 comments on commit 5df6756

Please sign in to comment.