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

Pass config defaults into revision reconciler and add test case to verify #5892

Merged
merged 4 commits into from
Nov 12, 2019
Merged
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
4 changes: 4 additions & 0 deletions pkg/reconciler/revision/config/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package config

import (
"context"
"knative.dev/serving/pkg/apis/config"

"knative.dev/pkg/configmap"
"knative.dev/pkg/logging"
Expand All @@ -37,6 +38,7 @@ type Config struct {
Observability *metrics.ObservabilityConfig
Logging *logging.Config
Tracing *pkgtracing.Config
Defaults *config.Defaults
}

func FromContext(ctx context.Context) *Config {
Expand Down Expand Up @@ -64,6 +66,7 @@ func NewStore(logger configmap.Logger, onAfterStore ...func(name string, value i
pkgmetrics.ConfigMapName(): metrics.NewObservabilityConfigFromConfigMap,
logging.ConfigMapName(): logging.NewConfigFromConfigMap,
pkgtracing.ConfigName: pkgtracing.NewTracingConfigFromConfigMap,
config.DefaultsConfigName: config.NewDefaultsConfigFromConfigMap,
},
onAfterStore...,
),
Expand All @@ -84,5 +87,6 @@ func (s *Store) Load() *Config {
Observability: s.UntypedLoad(pkgmetrics.ConfigMapName()).(*metrics.ObservabilityConfig).DeepCopy(),
Logging: s.UntypedLoad((logging.ConfigMapName())).(*logging.Config).DeepCopy(),
Tracing: s.UntypedLoad(pkgtracing.ConfigName).(*pkgtracing.Config).DeepCopy(),
Defaults: s.UntypedLoad(config.DefaultsConfigName).(*config.Defaults).DeepCopy(),
}
}
16 changes: 16 additions & 0 deletions pkg/reconciler/revision/config/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
logtesting "knative.dev/pkg/logging/testing"
pkgmetrics "knative.dev/pkg/metrics"
pkgtracing "knative.dev/pkg/tracing/config"
apisconfig "knative.dev/serving/pkg/apis/config"
deployment "knative.dev/serving/pkg/deployment"
"knative.dev/serving/pkg/metrics"
"knative.dev/serving/pkg/network"
Expand All @@ -41,12 +42,14 @@ func TestStoreLoadWithContext(t *testing.T) {
observabilityConfig := ConfigMapFromTestFile(t, pkgmetrics.ConfigMapName())
loggingConfig := ConfigMapFromTestFile(t, logging.ConfigMapName())
tracingConfig := ConfigMapFromTestFile(t, pkgtracing.ConfigName)
defaultConfig := ConfigMapFromTestFile(t, apisconfig.DefaultsConfigName)

store.OnConfigChanged(deploymentConfig)
store.OnConfigChanged(networkConfig)
store.OnConfigChanged(observabilityConfig)
store.OnConfigChanged(loggingConfig)
store.OnConfigChanged(tracingConfig)
store.OnConfigChanged(defaultConfig)

config := FromContext(store.ToContext(context.Background()))

Expand Down Expand Up @@ -86,6 +89,13 @@ func TestStoreLoadWithContext(t *testing.T) {
t.Errorf("Unexpected tracing config (-want, +got): %v", diff)
}
})

t.Run("defaults", func(t *testing.T) {
expected, _ := apisconfig.NewDefaultsConfigFromConfigMap(defaultConfig)
if diff := cmp.Diff(expected, config.Defaults); diff != "" {
t.Errorf("Unexpected defaults config (-want, +got): %v", diff)
}
})
}

func TestStoreImmutableConfig(t *testing.T) {
Expand All @@ -96,12 +106,15 @@ func TestStoreImmutableConfig(t *testing.T) {
store.OnConfigChanged(ConfigMapFromTestFile(t, pkgmetrics.ConfigMapName()))
store.OnConfigChanged(ConfigMapFromTestFile(t, logging.ConfigMapName()))
store.OnConfigChanged(ConfigMapFromTestFile(t, pkgtracing.ConfigName))
store.OnConfigChanged(ConfigMapFromTestFile(t, apisconfig.DefaultsConfigName))
Copy link
Contributor

Choose a reason for hiding this comment

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

we should test for immutability of defaults config object too similar to whats done below:

config.Deployment.QueueSidecarImage = "mutated"
config.Network.IstioOutboundIPRanges = "mutated"
config.Logging.LoggingConfig = "mutated"


config := store.Load()

config.Deployment.QueueSidecarImage = "mutated"
config.Network.IstioOutboundIPRanges = "mutated"
config.Logging.LoggingConfig = "mutated"
ccMutated := int64(4)
config.Defaults.ContainerConcurrency = ccMutated

newConfig := store.Load()

Expand All @@ -114,4 +127,7 @@ func TestStoreImmutableConfig(t *testing.T) {
if newConfig.Logging.LoggingConfig == "mutated" {
t.Error("Logging config is not immutable")
}
if newConfig.Defaults.ContainerConcurrency == ccMutated {
t.Error("Defaults config is not immutable")
}
}
2 changes: 2 additions & 0 deletions pkg/reconciler/revision/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"knative.dev/pkg/configmap"
"knative.dev/pkg/controller"
"knative.dev/pkg/logging"
apisconfig "knative.dev/serving/pkg/apis/config"
"knative.dev/serving/pkg/apis/serving/v1alpha1"
"knative.dev/serving/pkg/deployment"
"knative.dev/serving/pkg/metrics"
Expand Down Expand Up @@ -106,6 +107,7 @@ func NewController(
&network.Config{},
&metrics.ObservabilityConfig{},
&deployment.Config{},
&apisconfig.Defaults{},
}

resync := configmap.TypeFilter(configsToResync...)(func(string, interface{}) {
Expand Down
14 changes: 14 additions & 0 deletions pkg/reconciler/revision/queueing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package revision

import (
"context"
"knative.dev/serving/pkg/apis/config"
"testing"
"time"

Expand Down Expand Up @@ -133,6 +134,18 @@ func getTestDeploymentConfigMap() *corev1.ConfigMap {
}
}

func getTestDefaultsConfigMap() *corev1.ConfigMap {
return &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: config.DefaultsConfigName,
Namespace: system.Namespace(),
},
Data: map[string]string{
"container-name-template": "user-container",
},
}
}

func newTestController(t *testing.T) (
context.Context,
context.CancelFunc,
Expand All @@ -148,6 +161,7 @@ func newTestController(t *testing.T) (

configs := []*corev1.ConfigMap{
getTestDeploymentConfigMap(),
getTestDefaultsConfigMap(),
{
ObjectMeta: metav1.ObjectMeta{
Namespace: system.Namespace(),
Expand Down
29 changes: 28 additions & 1 deletion pkg/reconciler/revision/revision_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"errors"
"fmt"
"knative.dev/serving/pkg/apis/config"
"strconv"
"strings"
"testing"
Expand Down Expand Up @@ -164,7 +165,7 @@ func newTestControllerWithConfig(t *testing.T, deploymentConfig *deployment.Conf
"panic-window": "10s",
"tick-interval": "2s",
},
}, getTestDeploymentConfigMap()}
}, getTestDeploymentConfigMap(), getTestDefaultsConfigMap()}

cms = append(cms, configs...)

Expand Down Expand Up @@ -552,6 +553,32 @@ func TestGlobalResyncOnConfigMapUpdateRevision(t *testing.T) {
return HookIncomplete
}
},
}, {
name: "Update ContainerConcurrency", // Should update ContainerConcurrency on revision spec
configMapToUpdate: &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Namespace: system.Namespace(),
Name: config.DefaultsConfigName,
},
Data: map[string]string{
"container-concurrency": "3",
},
},
callback: func(t *testing.T) func(runtime.Object) HookResult {
return func(obj runtime.Object) HookResult {
revision := obj.(*v1alpha1.Revision)
t.Logf("Revision updated: %v", revision.Name)

expected := int64(3)
got := *(revision.Spec.ContainerConcurrency)
if got != expected {
return HookComplete
}

t.Logf("No update occurred; expected: %d got: %d", expected, got)
return HookIncomplete
}
},
}}

for _, test := range tests {
Expand Down