TracingConfiguration is now validated strictly

This commit is contained in:
Sean Sullivan 2024-10-14 18:09:16 -07:00
parent 55b83c92b3
commit a9c8061b1e
2 changed files with 28 additions and 2 deletions

View File

@ -27,7 +27,7 @@ import (
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
"go.opentelemetry.io/otel/metric/noop"
"go.opentelemetry.io/otel/sdk/resource"
"go.opentelemetry.io/otel/semconv/v1.12.0"
semconv "go.opentelemetry.io/otel/semconv/v1.12.0"
"google.golang.org/grpc"
"k8s.io/apimachinery/pkg/runtime"
@ -47,7 +47,7 @@ const apiserverService = "apiserver"
var (
cfgScheme = runtime.NewScheme()
codecs = serializer.NewCodecFactory(cfgScheme)
codecs = serializer.NewCodecFactory(cfgScheme, serializer.EnableStrict)
)
func init() {

View File

@ -98,6 +98,32 @@ func TestReadTracingConfiguration(t *testing.T) {
expectedResult: nil,
expectedError: strptr("unable to read tracing configuration from \"test-tracing-config-absent\": open test-tracing-config-absent: no such file or directory"),
},
{
name: "duplicate field error; strict validation",
createFile: true,
contents: `
apiVersion: apiserver.config.k8s.io/v1alpha1
kind: TracingConfiguration
endpoint: localhost:4317
endpoint: localhost:4318
samplingRatePerMillion: 12345
`,
expectedResult: nil,
expectedError: strptr("unable to decode tracing configuration data: strict decoding error"),
},
{
name: "unknown field error; strict validation",
createFile: true,
contents: `
apiVersion: apiserver.config.k8s.io/v1alpha1
kind: TracingConfiguration
foo: bar
endpoint: localhost:4318
samplingRatePerMillion: 12345
`,
expectedResult: nil,
expectedError: strptr("unable to decode tracing configuration data: strict decoding error"),
},
{
name: "v1alpha1",
createFile: true,