Custom resource definition
Co-authored-by: Mathieu Lonjaret <mathieu.lonjaret@gmail.com>
This commit is contained in:
parent
cfaf47c8a2
commit
4c060a78cc
1348 changed files with 92364 additions and 55766 deletions
77
vendor/k8s.io/apimachinery/pkg/runtime/serializer/json/json.go
generated
vendored
77
vendor/k8s.io/apimachinery/pkg/runtime/serializer/json/json.go
generated
vendored
|
@ -75,11 +75,6 @@ func init() {
|
|||
case jsoniter.NumberValue:
|
||||
var number json.Number
|
||||
iter.ReadVal(&number)
|
||||
u64, err := strconv.ParseUint(string(number), 10, 64)
|
||||
if err == nil {
|
||||
*(*interface{})(ptr) = u64
|
||||
return
|
||||
}
|
||||
i64, err := strconv.ParseInt(string(number), 10, 64)
|
||||
if err == nil {
|
||||
*(*interface{})(ptr) = i64
|
||||
|
@ -98,11 +93,43 @@ func init() {
|
|||
jsoniter.RegisterTypeDecoderFunc("interface {}", decodeNumberAsInt64IfPossible)
|
||||
}
|
||||
|
||||
// CaseSensitiveJsonIterator returns a jsoniterator API that's configured to be
|
||||
// case-sensitive when unmarshalling, and otherwise compatible with
|
||||
// the encoding/json standard library.
|
||||
func CaseSensitiveJsonIterator() jsoniter.API {
|
||||
return jsoniter.Config{
|
||||
EscapeHTML: true,
|
||||
SortMapKeys: true,
|
||||
ValidateJsonRawMessage: true,
|
||||
CaseSensitive: true,
|
||||
}.Froze()
|
||||
}
|
||||
|
||||
var caseSensitiveJsonIterator = CaseSensitiveJsonIterator()
|
||||
|
||||
// gvkWithDefaults returns group kind and version defaulting from provided default
|
||||
func gvkWithDefaults(actual, defaultGVK schema.GroupVersionKind) schema.GroupVersionKind {
|
||||
if len(actual.Kind) == 0 {
|
||||
actual.Kind = defaultGVK.Kind
|
||||
}
|
||||
if len(actual.Version) == 0 && len(actual.Group) == 0 {
|
||||
actual.Group = defaultGVK.Group
|
||||
actual.Version = defaultGVK.Version
|
||||
}
|
||||
if len(actual.Version) == 0 && actual.Group == defaultGVK.Group {
|
||||
actual.Version = defaultGVK.Version
|
||||
}
|
||||
return actual
|
||||
}
|
||||
|
||||
// Decode attempts to convert the provided data into YAML or JSON, extract the stored schema kind, apply the provided default gvk, and then
|
||||
// load that data into an object matching the desired schema kind or the provided into. If into is *runtime.Unknown, the raw data will be
|
||||
// extracted and no decoding will be performed. If into is not registered with the typer, then the object will be straight decoded using
|
||||
// normal JSON/YAML unmarshalling. If into is provided and the original data is not fully qualified with kind/version/group, the type of
|
||||
// the into will be used to alter the returned gvk. On success or most errors, the method will return the calculated schema kind.
|
||||
// load that data into an object matching the desired schema kind or the provided into.
|
||||
// If into is *runtime.Unknown, the raw data will be extracted and no decoding will be performed.
|
||||
// If into is not registered with the typer, then the object will be straight decoded using normal JSON/YAML unmarshalling.
|
||||
// If into is provided and the original data is not fully qualified with kind/version/group, the type of the into will be used to alter the returned gvk.
|
||||
// If into is nil or data's gvk different from into's gvk, it will generate a new Object with ObjectCreater.New(gvk)
|
||||
// On success or most errors, the method will return the calculated schema kind.
|
||||
// The gvk calculate priority will be originalData > default gvk > into
|
||||
func (s *Serializer) Decode(originalData []byte, gvk *schema.GroupVersionKind, into runtime.Object) (runtime.Object, *schema.GroupVersionKind, error) {
|
||||
if versioned, ok := into.(*runtime.VersionedObjects); ok {
|
||||
into = versioned.Last()
|
||||
|
@ -129,17 +156,7 @@ func (s *Serializer) Decode(originalData []byte, gvk *schema.GroupVersionKind, i
|
|||
}
|
||||
|
||||
if gvk != nil {
|
||||
// apply kind and version defaulting from provided default
|
||||
if len(actual.Kind) == 0 {
|
||||
actual.Kind = gvk.Kind
|
||||
}
|
||||
if len(actual.Version) == 0 && len(actual.Group) == 0 {
|
||||
actual.Group = gvk.Group
|
||||
actual.Version = gvk.Version
|
||||
}
|
||||
if len(actual.Version) == 0 && actual.Group == gvk.Group {
|
||||
actual.Version = gvk.Version
|
||||
}
|
||||
*actual = gvkWithDefaults(*actual, *gvk)
|
||||
}
|
||||
|
||||
if unk, ok := into.(*runtime.Unknown); ok && unk != nil {
|
||||
|
@ -154,24 +171,14 @@ func (s *Serializer) Decode(originalData []byte, gvk *schema.GroupVersionKind, i
|
|||
types, _, err := s.typer.ObjectKinds(into)
|
||||
switch {
|
||||
case runtime.IsNotRegisteredError(err), isUnstructured:
|
||||
if err := jsoniter.ConfigFastest.Unmarshal(data, into); err != nil {
|
||||
if err := caseSensitiveJsonIterator.Unmarshal(data, into); err != nil {
|
||||
return nil, actual, err
|
||||
}
|
||||
return into, actual, nil
|
||||
case err != nil:
|
||||
return nil, actual, err
|
||||
default:
|
||||
typed := types[0]
|
||||
if len(actual.Kind) == 0 {
|
||||
actual.Kind = typed.Kind
|
||||
}
|
||||
if len(actual.Version) == 0 && len(actual.Group) == 0 {
|
||||
actual.Group = typed.Group
|
||||
actual.Version = typed.Version
|
||||
}
|
||||
if len(actual.Version) == 0 && actual.Group == typed.Group {
|
||||
actual.Version = typed.Version
|
||||
}
|
||||
*actual = gvkWithDefaults(*actual, types[0])
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -188,7 +195,7 @@ func (s *Serializer) Decode(originalData []byte, gvk *schema.GroupVersionKind, i
|
|||
return nil, actual, err
|
||||
}
|
||||
|
||||
if err := jsoniter.ConfigFastest.Unmarshal(data, obj); err != nil {
|
||||
if err := caseSensitiveJsonIterator.Unmarshal(data, obj); err != nil {
|
||||
return nil, actual, err
|
||||
}
|
||||
return obj, actual, nil
|
||||
|
@ -197,7 +204,7 @@ func (s *Serializer) Decode(originalData []byte, gvk *schema.GroupVersionKind, i
|
|||
// Encode serializes the provided object to the given writer.
|
||||
func (s *Serializer) Encode(obj runtime.Object, w io.Writer) error {
|
||||
if s.yaml {
|
||||
json, err := jsoniter.ConfigFastest.Marshal(obj)
|
||||
json, err := caseSensitiveJsonIterator.Marshal(obj)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -210,7 +217,7 @@ func (s *Serializer) Encode(obj runtime.Object, w io.Writer) error {
|
|||
}
|
||||
|
||||
if s.pretty {
|
||||
data, err := jsoniter.ConfigFastest.MarshalIndent(obj, "", " ")
|
||||
data, err := caseSensitiveJsonIterator.MarshalIndent(obj, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
2
vendor/k8s.io/apimachinery/pkg/runtime/serializer/streaming/streaming.go
generated
vendored
2
vendor/k8s.io/apimachinery/pkg/runtime/serializer/streaming/streaming.go
generated
vendored
|
@ -64,7 +64,7 @@ func NewDecoder(r io.ReadCloser, d runtime.Decoder) Decoder {
|
|||
reader: r,
|
||||
decoder: d,
|
||||
buf: make([]byte, 1024),
|
||||
maxBytes: 1024 * 1024,
|
||||
maxBytes: 16 * 1024 * 1024,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
23
vendor/k8s.io/apimachinery/pkg/runtime/serializer/versioning/versioning.go
generated
vendored
23
vendor/k8s.io/apimachinery/pkg/runtime/serializer/versioning/versioning.go
generated
vendored
|
@ -19,6 +19,7 @@ package versioning
|
|||
import (
|
||||
"io"
|
||||
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
)
|
||||
|
@ -166,9 +167,27 @@ func (c *codec) Decode(data []byte, defaultGVK *schema.GroupVersionKind, into ru
|
|||
// Encode ensures the provided object is output in the appropriate group and version, invoking
|
||||
// conversion if necessary. Unversioned objects (according to the ObjectTyper) are output as is.
|
||||
func (c *codec) Encode(obj runtime.Object, w io.Writer) error {
|
||||
switch obj.(type) {
|
||||
case *runtime.Unknown, runtime.Unstructured:
|
||||
switch obj := obj.(type) {
|
||||
case *runtime.Unknown:
|
||||
return c.encoder.Encode(obj, w)
|
||||
case runtime.Unstructured:
|
||||
// An unstructured list can contain objects of multiple group version kinds. don't short-circuit just
|
||||
// because the top-level type matches our desired destination type. actually send the object to the converter
|
||||
// to give it a chance to convert the list items if needed.
|
||||
if _, ok := obj.(*unstructured.UnstructuredList); !ok {
|
||||
// avoid conversion roundtrip if GVK is the right one already or is empty (yes, this is a hack, but the old behaviour we rely on in kubectl)
|
||||
objGVK := obj.GetObjectKind().GroupVersionKind()
|
||||
if len(objGVK.Version) == 0 {
|
||||
return c.encoder.Encode(obj, w)
|
||||
}
|
||||
targetGVK, ok := c.encodeVersion.KindForGroupVersionKinds([]schema.GroupVersionKind{objGVK})
|
||||
if !ok {
|
||||
return runtime.NewNotRegisteredGVKErrForTarget(objGVK, c.encodeVersion)
|
||||
}
|
||||
if targetGVK == objGVK {
|
||||
return c.encoder.Encode(obj, w)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gvks, isUnversioned, err := c.typer.ObjectKinds(obj)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue