Skip to content

Commit db1239d

Browse files
committed
Add WithSerializer option to add serializers to CodecFactory.
1 parent 66a1426 commit db1239d

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

staging/src/k8s.io/apimachinery/pkg/runtime/serializer/codec_factory.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ func newSerializersForScheme(scheme *runtime.Scheme, mf json.MetaFactory, option
8989
},
9090
}
9191

92+
for _, f := range options.serializers {
93+
serializers = append(serializers, f(scheme, scheme))
94+
}
95+
9296
return serializers
9397
}
9498

@@ -108,6 +112,8 @@ type CodecFactoryOptions struct {
108112
Strict bool
109113
// Pretty includes a pretty serializer along with the non-pretty one
110114
Pretty bool
115+
116+
serializers []func(runtime.ObjectCreater, runtime.ObjectTyper) runtime.SerializerInfo
111117
}
112118

113119
// CodecFactoryOptionsMutator takes a pointer to an options struct and then modifies it.
@@ -134,6 +140,13 @@ func DisableStrict(options *CodecFactoryOptions) {
134140
options.Strict = false
135141
}
136142

143+
// WithSerializer configures a serializer to be supported in addition to the default serializers.
144+
func WithSerializer(f func(runtime.ObjectCreater, runtime.ObjectTyper) runtime.SerializerInfo) CodecFactoryOptionsMutator {
145+
return func(options *CodecFactoryOptions) {
146+
options.serializers = append(options.serializers, f)
147+
}
148+
}
149+
137150
// NewCodecFactory provides methods for retrieving serializers for the supported wire formats
138151
// and conversion wrappers to define preferred internal and external versions. In the future,
139152
// as the internal version is used less, callers may instead use a defaulting serializer and

0 commit comments

Comments
 (0)