Skip to content

Commit a9c8061

Browse files
committed
TracingConfiguration is now validated strictly
1 parent 55b83c9 commit a9c8061

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

staging/src/k8s.io/apiserver/pkg/server/options/tracing.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
2828
"go.opentelemetry.io/otel/metric/noop"
2929
"go.opentelemetry.io/otel/sdk/resource"
30-
"go.opentelemetry.io/otel/semconv/v1.12.0"
30+
semconv "go.opentelemetry.io/otel/semconv/v1.12.0"
3131
"google.golang.org/grpc"
3232

3333
"k8s.io/apimachinery/pkg/runtime"
@@ -47,7 +47,7 @@ const apiserverService = "apiserver"
4747

4848
var (
4949
cfgScheme = runtime.NewScheme()
50-
codecs = serializer.NewCodecFactory(cfgScheme)
50+
codecs = serializer.NewCodecFactory(cfgScheme, serializer.EnableStrict)
5151
)
5252

5353
func init() {

staging/src/k8s.io/apiserver/pkg/server/options/tracing_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,32 @@ func TestReadTracingConfiguration(t *testing.T) {
9898
expectedResult: nil,
9999
expectedError: strptr("unable to read tracing configuration from \"test-tracing-config-absent\": open test-tracing-config-absent: no such file or directory"),
100100
},
101+
{
102+
name: "duplicate field error; strict validation",
103+
createFile: true,
104+
contents: `
105+
apiVersion: apiserver.config.k8s.io/v1alpha1
106+
kind: TracingConfiguration
107+
endpoint: localhost:4317
108+
endpoint: localhost:4318
109+
samplingRatePerMillion: 12345
110+
`,
111+
expectedResult: nil,
112+
expectedError: strptr("unable to decode tracing configuration data: strict decoding error"),
113+
},
114+
{
115+
name: "unknown field error; strict validation",
116+
createFile: true,
117+
contents: `
118+
apiVersion: apiserver.config.k8s.io/v1alpha1
119+
kind: TracingConfiguration
120+
foo: bar
121+
endpoint: localhost:4318
122+
samplingRatePerMillion: 12345
123+
`,
124+
expectedResult: nil,
125+
expectedError: strptr("unable to decode tracing configuration data: strict decoding error"),
126+
},
101127
{
102128
name: "v1alpha1",
103129
createFile: true,

0 commit comments

Comments
 (0)