mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 18:24:07 +00:00
Merge pull request #120575 from benluddy/precompute-cr-accepts
Reuse SupportedMediaTypes for CR content-type negotiation.
This commit is contained in:
commit
97e87e2c40
@ -833,6 +833,45 @@ func (r *crdHandler) getOrCreateServingInfoFor(uid types.UID, name string) (*crd
|
||||
structuralSchemas: structuralSchemas,
|
||||
structuralSchemaGK: kind.GroupKind(),
|
||||
preserveUnknownFields: crd.Spec.PreserveUnknownFields,
|
||||
supportedMediaTypes: []runtime.SerializerInfo{
|
||||
{
|
||||
MediaType: "application/json",
|
||||
MediaTypeType: "application",
|
||||
MediaTypeSubType: "json",
|
||||
EncodesAsText: true,
|
||||
Serializer: json.NewSerializer(json.DefaultMetaFactory, creator, typer, false),
|
||||
PrettySerializer: json.NewSerializer(json.DefaultMetaFactory, creator, typer, true),
|
||||
StrictSerializer: json.NewSerializerWithOptions(json.DefaultMetaFactory, creator, typer, json.SerializerOptions{
|
||||
Strict: true,
|
||||
}),
|
||||
StreamSerializer: &runtime.StreamSerializerInfo{
|
||||
EncodesAsText: true,
|
||||
Serializer: json.NewSerializer(json.DefaultMetaFactory, creator, typer, false),
|
||||
Framer: json.Framer,
|
||||
},
|
||||
},
|
||||
{
|
||||
MediaType: "application/yaml",
|
||||
MediaTypeType: "application",
|
||||
MediaTypeSubType: "yaml",
|
||||
EncodesAsText: true,
|
||||
Serializer: json.NewYAMLSerializer(json.DefaultMetaFactory, creator, typer),
|
||||
StrictSerializer: json.NewSerializerWithOptions(json.DefaultMetaFactory, creator, typer, json.SerializerOptions{
|
||||
Yaml: true,
|
||||
Strict: true,
|
||||
}),
|
||||
},
|
||||
{
|
||||
MediaType: "application/vnd.kubernetes.protobuf",
|
||||
MediaTypeType: "application",
|
||||
MediaTypeSubType: "vnd.kubernetes.protobuf",
|
||||
Serializer: protobuf.NewSerializer(creator, typer),
|
||||
StreamSerializer: &runtime.StreamSerializerInfo{
|
||||
Serializer: protobuf.NewRawSerializer(creator, typer),
|
||||
Framer: protobuf.LengthDelimitedFramer,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
var standardSerializers []runtime.SerializerInfo
|
||||
for _, s := range negotiatedSerializer.SupportedMediaTypes() {
|
||||
@ -1021,48 +1060,12 @@ type unstructuredNegotiatedSerializer struct {
|
||||
structuralSchemas map[string]*structuralschema.Structural // by version
|
||||
structuralSchemaGK schema.GroupKind
|
||||
preserveUnknownFields bool
|
||||
|
||||
supportedMediaTypes []runtime.SerializerInfo
|
||||
}
|
||||
|
||||
func (s unstructuredNegotiatedSerializer) SupportedMediaTypes() []runtime.SerializerInfo {
|
||||
return []runtime.SerializerInfo{
|
||||
{
|
||||
MediaType: "application/json",
|
||||
MediaTypeType: "application",
|
||||
MediaTypeSubType: "json",
|
||||
EncodesAsText: true,
|
||||
Serializer: json.NewSerializer(json.DefaultMetaFactory, s.creator, s.typer, false),
|
||||
PrettySerializer: json.NewSerializer(json.DefaultMetaFactory, s.creator, s.typer, true),
|
||||
StrictSerializer: json.NewSerializerWithOptions(json.DefaultMetaFactory, s.creator, s.typer, json.SerializerOptions{
|
||||
Strict: true,
|
||||
}),
|
||||
StreamSerializer: &runtime.StreamSerializerInfo{
|
||||
EncodesAsText: true,
|
||||
Serializer: json.NewSerializer(json.DefaultMetaFactory, s.creator, s.typer, false),
|
||||
Framer: json.Framer,
|
||||
},
|
||||
},
|
||||
{
|
||||
MediaType: "application/yaml",
|
||||
MediaTypeType: "application",
|
||||
MediaTypeSubType: "yaml",
|
||||
EncodesAsText: true,
|
||||
Serializer: json.NewYAMLSerializer(json.DefaultMetaFactory, s.creator, s.typer),
|
||||
StrictSerializer: json.NewSerializerWithOptions(json.DefaultMetaFactory, s.creator, s.typer, json.SerializerOptions{
|
||||
Yaml: true,
|
||||
Strict: true,
|
||||
}),
|
||||
},
|
||||
{
|
||||
MediaType: "application/vnd.kubernetes.protobuf",
|
||||
MediaTypeType: "application",
|
||||
MediaTypeSubType: "vnd.kubernetes.protobuf",
|
||||
Serializer: protobuf.NewSerializer(s.creator, s.typer),
|
||||
StreamSerializer: &runtime.StreamSerializerInfo{
|
||||
Serializer: protobuf.NewRawSerializer(s.creator, s.typer),
|
||||
Framer: protobuf.LengthDelimitedFramer,
|
||||
},
|
||||
},
|
||||
}
|
||||
return s.supportedMediaTypes
|
||||
}
|
||||
|
||||
func (s unstructuredNegotiatedSerializer) EncoderForVersion(encoder runtime.Encoder, gv runtime.GroupVersioner) runtime.Encoder {
|
||||
|
Loading…
Reference in New Issue
Block a user