mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 10:19:50 +00:00
Merge pull request #125186 from liyuerich/newserializer
drop deprecated json/yaml newSerializers, use json.NewSerializerWithO…
This commit is contained in:
commit
e5dd48efd0
@ -858,14 +858,14 @@ func (r *crdHandler) getOrCreateServingInfoFor(uid types.UID, name string) (*crd
|
|||||||
MediaTypeType: "application",
|
MediaTypeType: "application",
|
||||||
MediaTypeSubType: "json",
|
MediaTypeSubType: "json",
|
||||||
EncodesAsText: true,
|
EncodesAsText: true,
|
||||||
Serializer: json.NewSerializer(json.DefaultMetaFactory, creator, typer, false),
|
Serializer: json.NewSerializerWithOptions(json.DefaultMetaFactory, creator, typer, json.SerializerOptions{}),
|
||||||
PrettySerializer: json.NewSerializer(json.DefaultMetaFactory, creator, typer, true),
|
PrettySerializer: json.NewSerializerWithOptions(json.DefaultMetaFactory, creator, typer, json.SerializerOptions{Pretty: true}),
|
||||||
StrictSerializer: json.NewSerializerWithOptions(json.DefaultMetaFactory, creator, typer, json.SerializerOptions{
|
StrictSerializer: json.NewSerializerWithOptions(json.DefaultMetaFactory, creator, typer, json.SerializerOptions{
|
||||||
Strict: true,
|
Strict: true,
|
||||||
}),
|
}),
|
||||||
StreamSerializer: &runtime.StreamSerializerInfo{
|
StreamSerializer: &runtime.StreamSerializerInfo{
|
||||||
EncodesAsText: true,
|
EncodesAsText: true,
|
||||||
Serializer: json.NewSerializer(json.DefaultMetaFactory, creator, typer, false),
|
Serializer: json.NewSerializerWithOptions(json.DefaultMetaFactory, creator, typer, json.SerializerOptions{}),
|
||||||
Framer: json.Framer,
|
Framer: json.Framer,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -874,7 +874,7 @@ func (r *crdHandler) getOrCreateServingInfoFor(uid types.UID, name string) (*crd
|
|||||||
MediaTypeType: "application",
|
MediaTypeType: "application",
|
||||||
MediaTypeSubType: "yaml",
|
MediaTypeSubType: "yaml",
|
||||||
EncodesAsText: true,
|
EncodesAsText: true,
|
||||||
Serializer: json.NewYAMLSerializer(json.DefaultMetaFactory, creator, typer),
|
Serializer: json.NewSerializerWithOptions(json.DefaultMetaFactory, creator, typer, json.SerializerOptions{Yaml: true}),
|
||||||
StrictSerializer: json.NewSerializerWithOptions(json.DefaultMetaFactory, creator, typer, json.SerializerOptions{
|
StrictSerializer: json.NewSerializerWithOptions(json.DefaultMetaFactory, creator, typer, json.SerializerOptions{
|
||||||
Yaml: true,
|
Yaml: true,
|
||||||
Strict: true,
|
Strict: true,
|
||||||
|
@ -38,7 +38,7 @@ import (
|
|||||||
func TestRoundtripObjectMeta(t *testing.T) {
|
func TestRoundtripObjectMeta(t *testing.T) {
|
||||||
scheme := runtime.NewScheme()
|
scheme := runtime.NewScheme()
|
||||||
codecs := serializer.NewCodecFactory(scheme)
|
codecs := serializer.NewCodecFactory(scheme)
|
||||||
codec := json.NewSerializer(json.DefaultMetaFactory, scheme, scheme, false)
|
codec := json.NewSerializerWithOptions(json.DefaultMetaFactory, scheme, scheme, json.SerializerOptions{})
|
||||||
seed := rand.Int63()
|
seed := rand.Int63()
|
||||||
fuzzer := fuzzer.FuzzerFor(metafuzzer.Funcs, rand.NewSource(seed), codecs)
|
fuzzer := fuzzer.FuzzerFor(metafuzzer.Funcs, rand.NewSource(seed), codecs)
|
||||||
|
|
||||||
|
@ -181,10 +181,10 @@ func (c *CompatibilityTestOptions) Complete(t *testing.T) *CompatibilityTestOpti
|
|||||||
}
|
}
|
||||||
|
|
||||||
if c.JSON == nil {
|
if c.JSON == nil {
|
||||||
c.JSON = json.NewSerializer(json.DefaultMetaFactory, c.Scheme, c.Scheme, true)
|
c.JSON = json.NewSerializerWithOptions(json.DefaultMetaFactory, c.Scheme, c.Scheme, json.SerializerOptions{Pretty: true})
|
||||||
}
|
}
|
||||||
if c.YAML == nil {
|
if c.YAML == nil {
|
||||||
c.YAML = json.NewYAMLSerializer(json.DefaultMetaFactory, c.Scheme, c.Scheme)
|
c.YAML = json.NewSerializerWithOptions(json.DefaultMetaFactory, c.Scheme, c.Scheme, json.SerializerOptions{Yaml: true})
|
||||||
}
|
}
|
||||||
if c.Proto == nil {
|
if c.Proto == nil {
|
||||||
c.Proto = protobuf.NewSerializer(c.Scheme, c.Scheme)
|
c.Proto = protobuf.NewSerializer(c.Scheme, c.Scheme)
|
||||||
|
@ -279,7 +279,7 @@ func roundTripOfExternalType(t *testing.T, scheme *runtime.Scheme, codecFactory
|
|||||||
typeAcc.SetKind(externalGVK.Kind)
|
typeAcc.SetKind(externalGVK.Kind)
|
||||||
typeAcc.SetAPIVersion(externalGVK.GroupVersion().String())
|
typeAcc.SetAPIVersion(externalGVK.GroupVersion().String())
|
||||||
|
|
||||||
roundTrip(t, scheme, json.NewSerializer(json.DefaultMetaFactory, scheme, scheme, false), object)
|
roundTrip(t, scheme, json.NewSerializerWithOptions(json.DefaultMetaFactory, scheme, scheme, json.SerializerOptions{}), object)
|
||||||
|
|
||||||
// TODO remove this hack after we're past the intermediate steps
|
// TODO remove this hack after we're past the intermediate steps
|
||||||
if !skipProtobuf {
|
if !skipProtobuf {
|
||||||
|
@ -50,11 +50,11 @@ func (s unstructuredNegotiatedSerializer) SupportedMediaTypes() []runtime.Serial
|
|||||||
MediaTypeType: "application",
|
MediaTypeType: "application",
|
||||||
MediaTypeSubType: "json",
|
MediaTypeSubType: "json",
|
||||||
EncodesAsText: true,
|
EncodesAsText: true,
|
||||||
Serializer: json.NewSerializer(json.DefaultMetaFactory, s.creator, s.typer, false),
|
Serializer: json.NewSerializerWithOptions(json.DefaultMetaFactory, s.creator, s.typer, json.SerializerOptions{}),
|
||||||
PrettySerializer: json.NewSerializer(json.DefaultMetaFactory, s.creator, s.typer, true),
|
PrettySerializer: json.NewSerializerWithOptions(json.DefaultMetaFactory, s.creator, s.typer, json.SerializerOptions{Pretty: true}),
|
||||||
StreamSerializer: &runtime.StreamSerializerInfo{
|
StreamSerializer: &runtime.StreamSerializerInfo{
|
||||||
EncodesAsText: true,
|
EncodesAsText: true,
|
||||||
Serializer: json.NewSerializer(json.DefaultMetaFactory, s.creator, s.typer, false),
|
Serializer: json.NewSerializerWithOptions(json.DefaultMetaFactory, s.creator, s.typer, json.SerializerOptions{}),
|
||||||
Framer: json.Framer,
|
Framer: json.Framer,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -63,7 +63,7 @@ func (s unstructuredNegotiatedSerializer) SupportedMediaTypes() []runtime.Serial
|
|||||||
MediaTypeType: "application",
|
MediaTypeType: "application",
|
||||||
MediaTypeSubType: "yaml",
|
MediaTypeSubType: "yaml",
|
||||||
EncodesAsText: true,
|
EncodesAsText: true,
|
||||||
Serializer: json.NewYAMLSerializer(json.DefaultMetaFactory, s.creator, s.typer),
|
Serializer: json.NewSerializerWithOptions(json.DefaultMetaFactory, s.creator, s.typer, json.SerializerOptions{Yaml: true}),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -905,7 +905,7 @@ func TestCacheableObject(t *testing.T) {
|
|||||||
gvk := schema.GroupVersionKind{Group: "group", Version: "version", Kind: "MockCacheableObject"}
|
gvk := schema.GroupVersionKind{Group: "group", Version: "version", Kind: "MockCacheableObject"}
|
||||||
creater := &mockCreater{obj: &runtimetesting.MockCacheableObject{}}
|
creater := &mockCreater{obj: &runtimetesting.MockCacheableObject{}}
|
||||||
typer := &mockTyper{gvk: &gvk}
|
typer := &mockTyper{gvk: &gvk}
|
||||||
serializer := json.NewSerializer(json.DefaultMetaFactory, creater, typer, false)
|
serializer := json.NewSerializerWithOptions(json.DefaultMetaFactory, creater, typer, json.SerializerOptions{})
|
||||||
|
|
||||||
runtimetesting.CacheableObjectTest(t, serializer)
|
runtimetesting.CacheableObjectTest(t, serializer)
|
||||||
}
|
}
|
||||||
|
@ -36,8 +36,8 @@ func TestRecognizer(t *testing.T) {
|
|||||||
s := runtime.NewScheme()
|
s := runtime.NewScheme()
|
||||||
s.AddKnownTypes(schema.GroupVersion{Version: "v1"}, &A{})
|
s.AddKnownTypes(schema.GroupVersion{Version: "v1"}, &A{})
|
||||||
d := recognizer.NewDecoder(
|
d := recognizer.NewDecoder(
|
||||||
json.NewSerializer(json.DefaultMetaFactory, s, s, false),
|
json.NewSerializerWithOptions(json.DefaultMetaFactory, s, s, json.SerializerOptions{}),
|
||||||
json.NewYAMLSerializer(json.DefaultMetaFactory, s, s),
|
json.NewSerializerWithOptions(json.DefaultMetaFactory, s, s, json.SerializerOptions{Yaml: true}),
|
||||||
)
|
)
|
||||||
out, _, err := d.Decode([]byte(`
|
out, _, err := d.Decode([]byte(`
|
||||||
kind: A
|
kind: A
|
||||||
|
@ -348,7 +348,7 @@ func (a *mutatingDispatcher) callAttrMutatingHook(ctx context.Context, h *admiss
|
|||||||
}
|
}
|
||||||
|
|
||||||
var patchedJS []byte
|
var patchedJS []byte
|
||||||
jsonSerializer := json.NewSerializer(json.DefaultMetaFactory, o.GetObjectCreater(), o.GetObjectTyper(), false)
|
jsonSerializer := json.NewSerializerWithOptions(json.DefaultMetaFactory, o.GetObjectCreater(), o.GetObjectTyper(), json.SerializerOptions{})
|
||||||
switch result.PatchType {
|
switch result.PatchType {
|
||||||
// VerifyAdmissionResponse normalizes to v1 patch types, regardless of the AdmissionReview version used
|
// VerifyAdmissionResponse normalizes to v1 patch types, regardless of the AdmissionReview version used
|
||||||
case admissionv1.PatchTypeJSONPatch:
|
case admissionv1.PatchTypeJSONPatch:
|
||||||
|
@ -45,7 +45,7 @@ import (
|
|||||||
// request body. The caller passes a callback which is called on each webhook POST.
|
// request body. The caller passes a callback which is called on each webhook POST.
|
||||||
// The object passed to cb is of the same type as list.
|
// The object passed to cb is of the same type as list.
|
||||||
func newWebhookHandler(t *testing.T, list runtime.Object, cb func(events runtime.Object)) http.Handler {
|
func newWebhookHandler(t *testing.T, list runtime.Object, cb func(events runtime.Object)) http.Handler {
|
||||||
s := json.NewSerializer(json.DefaultMetaFactory, audit.Scheme, audit.Scheme, false)
|
s := json.NewSerializerWithOptions(json.DefaultMetaFactory, audit.Scheme, audit.Scheme, json.SerializerOptions{})
|
||||||
return &testWebhookHandler{
|
return &testWebhookHandler{
|
||||||
t: t,
|
t: t,
|
||||||
list: list,
|
list: list,
|
||||||
|
@ -51,11 +51,11 @@ func (s basicNegotiatedSerializer) SupportedMediaTypes() []runtime.SerializerInf
|
|||||||
MediaTypeType: "application",
|
MediaTypeType: "application",
|
||||||
MediaTypeSubType: "json",
|
MediaTypeSubType: "json",
|
||||||
EncodesAsText: true,
|
EncodesAsText: true,
|
||||||
Serializer: json.NewSerializer(json.DefaultMetaFactory, unstructuredCreater{basicScheme}, unstructuredTyper{basicScheme}, false),
|
Serializer: json.NewSerializerWithOptions(json.DefaultMetaFactory, unstructuredCreater{basicScheme}, unstructuredTyper{basicScheme}, json.SerializerOptions{}),
|
||||||
PrettySerializer: json.NewSerializer(json.DefaultMetaFactory, unstructuredCreater{basicScheme}, unstructuredTyper{basicScheme}, true),
|
PrettySerializer: json.NewSerializerWithOptions(json.DefaultMetaFactory, unstructuredCreater{basicScheme}, unstructuredTyper{basicScheme}, json.SerializerOptions{Pretty: true}),
|
||||||
StreamSerializer: &runtime.StreamSerializerInfo{
|
StreamSerializer: &runtime.StreamSerializerInfo{
|
||||||
EncodesAsText: true,
|
EncodesAsText: true,
|
||||||
Serializer: json.NewSerializer(json.DefaultMetaFactory, basicScheme, basicScheme, false),
|
Serializer: json.NewSerializerWithOptions(json.DefaultMetaFactory, basicScheme, basicScheme, json.SerializerOptions{}),
|
||||||
Framer: json.Framer,
|
Framer: json.Framer,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -37,7 +37,7 @@ import (
|
|||||||
|
|
||||||
// getDecoder mimics how k8s.io/client-go/rest.createSerializers creates a decoder
|
// getDecoder mimics how k8s.io/client-go/rest.createSerializers creates a decoder
|
||||||
func getDecoder() runtime.Decoder {
|
func getDecoder() runtime.Decoder {
|
||||||
jsonSerializer := runtimejson.NewSerializer(runtimejson.DefaultMetaFactory, scheme.Scheme, scheme.Scheme, false)
|
jsonSerializer := runtimejson.NewSerializerWithOptions(runtimejson.DefaultMetaFactory, scheme.Scheme, scheme.Scheme, runtimejson.SerializerOptions{})
|
||||||
directCodecFactory := scheme.Codecs.WithoutConversion()
|
directCodecFactory := scheme.Codecs.WithoutConversion()
|
||||||
return directCodecFactory.DecoderToVersion(jsonSerializer, v1.SchemeGroupVersion)
|
return directCodecFactory.DecoderToVersion(jsonSerializer, v1.SchemeGroupVersion)
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ import (
|
|||||||
|
|
||||||
// getEncoder mimics how k8s.io/client-go/rest.createSerializers creates a encoder
|
// getEncoder mimics how k8s.io/client-go/rest.createSerializers creates a encoder
|
||||||
func getEncoder() runtime.Encoder {
|
func getEncoder() runtime.Encoder {
|
||||||
jsonSerializer := runtimejson.NewSerializer(runtimejson.DefaultMetaFactory, scheme.Scheme, scheme.Scheme, false)
|
jsonSerializer := runtimejson.NewSerializerWithOptions(runtimejson.DefaultMetaFactory, scheme.Scheme, scheme.Scheme, runtimejson.SerializerOptions{})
|
||||||
directCodecFactory := scheme.Codecs.WithoutConversion()
|
directCodecFactory := scheme.Codecs.WithoutConversion()
|
||||||
return directCodecFactory.EncoderForVersion(jsonSerializer, v1.SchemeGroupVersion)
|
return directCodecFactory.EncoderForVersion(jsonSerializer, v1.SchemeGroupVersion)
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ func init() {
|
|||||||
Scheme = runtime.NewScheme()
|
Scheme = runtime.NewScheme()
|
||||||
utilruntime.Must(api.AddToScheme(Scheme))
|
utilruntime.Must(api.AddToScheme(Scheme))
|
||||||
utilruntime.Must(v1.AddToScheme(Scheme))
|
utilruntime.Must(v1.AddToScheme(Scheme))
|
||||||
yamlSerializer := json.NewYAMLSerializer(json.DefaultMetaFactory, Scheme, Scheme)
|
yamlSerializer := json.NewSerializerWithOptions(json.DefaultMetaFactory, Scheme, Scheme, json.SerializerOptions{Yaml: true})
|
||||||
Codec = versioning.NewDefaultingCodecForScheme(
|
Codec = versioning.NewDefaultingCodecForScheme(
|
||||||
Scheme,
|
Scheme,
|
||||||
yamlSerializer,
|
yamlSerializer,
|
||||||
|
Loading…
Reference in New Issue
Block a user