code
stringlengths 12
335k
| docstring
stringlengths 20
20.8k
| func_name
stringlengths 1
105
| language
stringclasses 1
value | repo
stringclasses 498
values | path
stringlengths 5
172
| url
stringlengths 43
235
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
func DefaultMetaV1FieldSelectorConversion(label, value string) (string, string, error) {
switch label {
case "metadata.name":
return label, value, nil
case "metadata.namespace":
return label, value, nil
default:
return "", "", fmt.Errorf("%q is not a known field selector: only %q, %q", label, "metadata.name", "metadata.namespace")
}
} | DefaultMetaV1FieldSelectorConversion auto-accepts metav1 values for name and namespace.
A cluster scoped resource specifying namespace empty works fine and specifying a particular
namespace will return no results, as expected. | DefaultMetaV1FieldSelectorConversion | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/conversion.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/conversion.go | Apache-2.0 |
func JSONKeyMapper(key string, sourceTag, destTag reflect.StructTag) (string, string) {
if s := destTag.Get("json"); len(s) > 0 {
return strings.SplitN(s, ",", 2)[0], key
}
if s := sourceTag.Get("json"); len(s) > 0 {
return key, strings.SplitN(s, ",", 2)[0]
}
return key, key
} | JSONKeyMapper uses the struct tags on a conversion to determine the key value for
the other side. Use when mapping from a map[string]* to a struct or vice versa. | JSONKeyMapper | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/conversion.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/conversion.go | Apache-2.0 |
func Convert_Slice_string_To_bool(in *[]string, out *bool, s conversion.Scope) error {
if len(*in) == 0 {
*out = false
return nil
}
switch {
case (*in)[0] == "0", strings.EqualFold((*in)[0], "false"):
*out = false
default:
*out = true
}
return nil
} | Convert_Slice_string_To_bool will convert a string parameter to boolean.
Only the absence of a value (i.e. zero-length slice), a value of "false", or a
value of "0" resolve to false.
Any other value (including empty string) resolves to true. | Convert_Slice_string_To_bool | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/conversion.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/conversion.go | Apache-2.0 |
func Convert_Slice_string_To_Pointer_bool(in *[]string, out **bool, s conversion.Scope) error {
if len(*in) == 0 {
boolVar := false
*out = &boolVar
return nil
}
switch {
case (*in)[0] == "0", strings.EqualFold((*in)[0], "false"):
boolVar := false
*out = &boolVar
default:
boolVar := true
*out = &boolVar
}
return nil
} | Convert_Slice_string_To_bool will convert a string parameter to boolean.
Only the absence of a value (i.e. zero-length slice), a value of "false", or a
value of "0" resolve to false.
Any other value (including empty string) resolves to true. | Convert_Slice_string_To_Pointer_bool | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/conversion.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/conversion.go | Apache-2.0 |
func (obj *TypeMeta) SetGroupVersionKind(gvk schema.GroupVersionKind) {
obj.APIVersion, obj.Kind = gvk.ToAPIVersionAndKind()
} | SetGroupVersionKind satisfies the ObjectKind interface for all objects that embed TypeMeta | SetGroupVersionKind | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/register.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/register.go | Apache-2.0 |
func (obj *TypeMeta) GroupVersionKind() schema.GroupVersionKind {
return schema.FromAPIVersionAndKind(obj.APIVersion, obj.Kind)
} | GroupVersionKind satisfies the ObjectKind interface for all objects that embed TypeMeta | GroupVersionKind | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/register.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/register.go | Apache-2.0 |
func (in *RawExtension) DeepCopyInto(out *RawExtension) {
*out = *in
if in.Raw != nil {
in, out := &in.Raw, &out.Raw
*out = make([]byte, len(*in))
copy(*out, *in)
}
if in.Object != nil {
out.Object = in.Object.DeepCopyObject()
}
return
} | DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. | DeepCopyInto | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/zz_generated.deepcopy.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/zz_generated.deepcopy.go | Apache-2.0 |
func (in *RawExtension) DeepCopy() *RawExtension {
if in == nil {
return nil
}
out := new(RawExtension)
in.DeepCopyInto(out)
return out
} | DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RawExtension. | DeepCopy | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/zz_generated.deepcopy.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/zz_generated.deepcopy.go | Apache-2.0 |
func (in *Unknown) DeepCopyInto(out *Unknown) {
*out = *in
out.TypeMeta = in.TypeMeta
if in.Raw != nil {
in, out := &in.Raw, &out.Raw
*out = make([]byte, len(*in))
copy(*out, *in)
}
return
} | DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. | DeepCopyInto | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/zz_generated.deepcopy.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/zz_generated.deepcopy.go | Apache-2.0 |
func (in *Unknown) DeepCopy() *Unknown {
if in == nil {
return nil
}
out := new(Unknown)
in.DeepCopyInto(out)
return out
} | DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Unknown. | DeepCopy | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/zz_generated.deepcopy.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/zz_generated.deepcopy.go | Apache-2.0 |
func (in *Unknown) DeepCopyObject() Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
} | DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new Object. | DeepCopyObject | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/zz_generated.deepcopy.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/zz_generated.deepcopy.go | Apache-2.0 |
func NewTestUnstructuredConverter(comparison conversion.Equalities) UnstructuredConverter {
return NewTestUnstructuredConverterWithValidation(comparison)
} | NewTestUnstructuredConverter creates an UnstructuredConverter that accepts JSON typed maps and translates them
to Go types via reflection. It performs mismatch detection automatically and is intended for use by external
test tools. Use DefaultUnstructuredConverter if you do not explicitly need mismatch detection. | NewTestUnstructuredConverter | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/converter.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/converter.go | Apache-2.0 |
func NewTestUnstructuredConverterWithValidation(comparison conversion.Equalities) *unstructuredConverter {
return &unstructuredConverter{
mismatchDetection: true,
comparison: comparison,
}
} | NewTestUnstrucutredConverterWithValidation allows for access to
FromUnstructuredWithValidation from within tests. | NewTestUnstructuredConverterWithValidation | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/converter.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/converter.go | Apache-2.0 |
func DeepCopyJSON(x map[string]interface{}) map[string]interface{} {
return DeepCopyJSONValue(x).(map[string]interface{})
} | DeepCopyJSON deep copies the passed value, assuming it is a valid JSON representation i.e. only contains
types produced by json.Unmarshal() and also int64.
bool, int64, float64, string, []interface{}, map[string]interface{}, json.Number and nil | DeepCopyJSON | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/converter.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/converter.go | Apache-2.0 |
func DeepCopyJSONValue(x interface{}) interface{} {
switch x := x.(type) {
case map[string]interface{}:
if x == nil {
// Typed nil - an interface{} that contains a type map[string]interface{} with a value of nil
return x
}
clone := make(map[string]interface{}, len(x))
for k, v := range x {
clone[k] = DeepCopyJSONValue(v)
}
return clone
case []interface{}:
if x == nil {
// Typed nil - an interface{} that contains a type []interface{} with a value of nil
return x
}
clone := make([]interface{}, len(x))
for i, v := range x {
clone[i] = DeepCopyJSONValue(v)
}
return clone
case string, int64, bool, float64, nil, encodingjson.Number:
return x
default:
panic(fmt.Errorf("cannot deep copy %T", x))
} | DeepCopyJSONValue deep copies the passed value, assuming it is a valid JSON representation i.e. only contains
types produced by json.Unmarshal() and also int64.
bool, int64, float64, string, []interface{}, map[string]interface{}, json.Number and nil | DeepCopyJSONValue | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/converter.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/converter.go | Apache-2.0 |
func NewScheme() *Scheme {
s := &Scheme{
gvkToType: map[schema.GroupVersionKind]reflect.Type{},
typeToGVK: map[reflect.Type][]schema.GroupVersionKind{},
unversionedTypes: map[reflect.Type]schema.GroupVersionKind{},
unversionedKinds: map[string]reflect.Type{},
fieldLabelConversionFuncs: map[schema.GroupVersionKind]FieldLabelConversionFunc{},
defaulterFuncs: map[reflect.Type]func(interface{}){},
versionPriority: map[string][]string{},
schemeName: naming.GetNameFromCallsite(internalPackages...),
}
s.converter = conversion.NewConverter(nil)
// Enable couple default conversions by default.
utilruntime.Must(RegisterEmbeddedConversions(s))
utilruntime.Must(RegisterStringConversions(s))
return s
} | NewScheme creates a new Scheme. This scheme is pluggable by default. | NewScheme | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | Apache-2.0 |
func (s *Scheme) Converter() *conversion.Converter {
return s.converter
} | Converter allows access to the converter for the scheme | Converter | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | Apache-2.0 |
func (s *Scheme) AddUnversionedTypes(version schema.GroupVersion, types ...Object) {
s.addObservedVersion(version)
s.AddKnownTypes(version, types...)
for _, obj := range types {
t := reflect.TypeOf(obj).Elem()
gvk := version.WithKind(t.Name())
s.unversionedTypes[t] = gvk
if old, ok := s.unversionedKinds[gvk.Kind]; ok && t != old {
panic(fmt.Sprintf("%v.%v has already been registered as unversioned kind %q - kind name must be unique in scheme %q", old.PkgPath(), old.Name(), gvk, s.schemeName))
}
s.unversionedKinds[gvk.Kind] = t
}
} | AddUnversionedTypes registers the provided types as "unversioned", which means that they follow special rules.
Whenever an object of this type is serialized, it is serialized with the provided group version and is not
converted. Thus unversioned objects are expected to remain backwards compatible forever, as if they were in an
API group and version that would never be updated.
TODO: there is discussion about removing unversioned and replacing it with objects that are manifest into
every version with particular schemas. Resolve this method at that point. | AddUnversionedTypes | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | Apache-2.0 |
func (s *Scheme) AddKnownTypes(gv schema.GroupVersion, types ...Object) {
s.addObservedVersion(gv)
for _, obj := range types {
t := reflect.TypeOf(obj)
if t.Kind() != reflect.Pointer {
panic("All types must be pointers to structs.")
}
t = t.Elem()
s.AddKnownTypeWithName(gv.WithKind(t.Name()), obj)
}
} | AddKnownTypes registers all types passed in 'types' as being members of version 'version'.
All objects passed to types should be pointers to structs. The name that go reports for
the struct becomes the "kind" field when encoding. Version may not be empty - use the
APIVersionInternal constant if you have a type that does not have a formal version. | AddKnownTypes | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | Apache-2.0 |
func (s *Scheme) AddKnownTypeWithName(gvk schema.GroupVersionKind, obj Object) {
s.addObservedVersion(gvk.GroupVersion())
t := reflect.TypeOf(obj)
if len(gvk.Version) == 0 {
panic(fmt.Sprintf("version is required on all types: %s %v", gvk, t))
}
if t.Kind() != reflect.Pointer {
panic("All types must be pointers to structs.")
}
t = t.Elem()
if t.Kind() != reflect.Struct {
panic("All types must be pointers to structs.")
}
if oldT, found := s.gvkToType[gvk]; found && oldT != t {
panic(fmt.Sprintf("Double registration of different types for %v: old=%v.%v, new=%v.%v in scheme %q", gvk, oldT.PkgPath(), oldT.Name(), t.PkgPath(), t.Name(), s.schemeName))
}
s.gvkToType[gvk] = t
for _, existingGvk := range s.typeToGVK[t] {
if existingGvk == gvk {
return
}
}
s.typeToGVK[t] = append(s.typeToGVK[t], gvk)
// if the type implements DeepCopyInto(<obj>), register a self-conversion
if m := reflect.ValueOf(obj).MethodByName("DeepCopyInto"); m.IsValid() && m.Type().NumIn() == 1 && m.Type().NumOut() == 0 && m.Type().In(0) == reflect.TypeOf(obj) {
if err := s.AddGeneratedConversionFunc(obj, obj, func(a, b interface{}, scope conversion.Scope) error {
// copy a to b
reflect.ValueOf(a).MethodByName("DeepCopyInto").Call([]reflect.Value{reflect.ValueOf(b)})
// clear TypeMeta to match legacy reflective conversion
b.(Object).GetObjectKind().SetGroupVersionKind(schema.GroupVersionKind{})
return nil
}); err != nil {
panic(err)
}
}
} | AddKnownTypeWithName is like AddKnownTypes, but it lets you specify what this type should
be encoded as. Useful for testing when you don't want to make multiple packages to define
your structs. Version may not be empty - use the APIVersionInternal constant if you have a
type that does not have a formal version. | AddKnownTypeWithName | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | Apache-2.0 |
func (s *Scheme) KnownTypes(gv schema.GroupVersion) map[string]reflect.Type {
types := make(map[string]reflect.Type)
for gvk, t := range s.gvkToType {
if gv != gvk.GroupVersion() {
continue
}
types[gvk.Kind] = t
}
return types
} | KnownTypes returns the types known for the given version. | KnownTypes | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | Apache-2.0 |
func (s *Scheme) VersionsForGroupKind(gk schema.GroupKind) []schema.GroupVersion {
availableVersions := []schema.GroupVersion{}
for gvk := range s.gvkToType {
if gk != gvk.GroupKind() {
continue
}
availableVersions = append(availableVersions, gvk.GroupVersion())
}
// order the return for stability
ret := []schema.GroupVersion{}
for _, version := range s.PrioritizedVersionsForGroup(gk.Group) {
for _, availableVersion := range availableVersions {
if version != availableVersion {
continue
}
ret = append(ret, availableVersion)
}
}
return ret
} | VersionsForGroupKind returns the versions that a particular GroupKind can be converted to within the given group.
A GroupKind might be converted to a different group. That information is available in EquivalentResourceMapper. | VersionsForGroupKind | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | Apache-2.0 |
func (s *Scheme) AllKnownTypes() map[schema.GroupVersionKind]reflect.Type {
return s.gvkToType
} | AllKnownTypes returns the all known types. | AllKnownTypes | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | Apache-2.0 |
func (s *Scheme) ObjectKinds(obj Object) ([]schema.GroupVersionKind, bool, error) {
// Unstructured objects are always considered to have their declared GVK
if _, ok := obj.(Unstructured); ok {
// we require that the GVK be populated in order to recognize the object
gvk := obj.GetObjectKind().GroupVersionKind()
if len(gvk.Kind) == 0 {
return nil, false, NewMissingKindErr("unstructured object has no kind")
}
if len(gvk.Version) == 0 {
return nil, false, NewMissingVersionErr("unstructured object has no version")
}
return []schema.GroupVersionKind{gvk}, false, nil
}
v, err := conversion.EnforcePtr(obj)
if err != nil {
return nil, false, err
}
t := v.Type()
gvks, ok := s.typeToGVK[t]
if !ok {
return nil, false, NewNotRegisteredErrForType(s.schemeName, t)
}
_, unversionedType := s.unversionedTypes[t]
return gvks, unversionedType, nil
} | ObjectKinds returns all possible group,version,kind of the go object, true if the
object is considered unversioned, or an error if it's not a pointer or is unregistered. | ObjectKinds | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | Apache-2.0 |
func (s *Scheme) Recognizes(gvk schema.GroupVersionKind) bool {
_, exists := s.gvkToType[gvk]
return exists
} | Recognizes returns true if the scheme is able to handle the provided group,version,kind
of an object. | Recognizes | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | Apache-2.0 |
func (s *Scheme) New(kind schema.GroupVersionKind) (Object, error) {
if t, exists := s.gvkToType[kind]; exists {
return reflect.New(t).Interface().(Object), nil
}
if t, exists := s.unversionedKinds[kind.Kind]; exists {
return reflect.New(t).Interface().(Object), nil
}
return nil, NewNotRegisteredErrForKind(s.schemeName, kind)
} | New returns a new API object of the given version and name, or an error if it hasn't
been registered. The version and kind fields must be specified. | New | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | Apache-2.0 |
func (s *Scheme) AddIgnoredConversionType(from, to interface{}) error {
return s.converter.RegisterIgnoredConversion(from, to)
} | AddIgnoredConversionType identifies a pair of types that should be skipped by
conversion (because the data inside them is explicitly dropped during
conversion). | AddIgnoredConversionType | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | Apache-2.0 |
func (s *Scheme) AddConversionFunc(a, b interface{}, fn conversion.ConversionFunc) error {
return s.converter.RegisterUntypedConversionFunc(a, b, fn)
} | AddConversionFunc registers a function that converts between a and b by passing objects of those
types to the provided function. The function *must* accept objects of a and b - this machinery will not enforce
any other guarantee. | AddConversionFunc | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | Apache-2.0 |
func (s *Scheme) AddGeneratedConversionFunc(a, b interface{}, fn conversion.ConversionFunc) error {
return s.converter.RegisterGeneratedUntypedConversionFunc(a, b, fn)
} | AddGeneratedConversionFunc registers a function that converts between a and b by passing objects of those
types to the provided function. The function *must* accept objects of a and b - this machinery will not enforce
any other guarantee. | AddGeneratedConversionFunc | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | Apache-2.0 |
func (s *Scheme) AddFieldLabelConversionFunc(gvk schema.GroupVersionKind, conversionFunc FieldLabelConversionFunc) error {
s.fieldLabelConversionFuncs[gvk] = conversionFunc
return nil
} | AddFieldLabelConversionFunc adds a conversion function to convert field selectors
of the given kind from the given version to internal version representation. | AddFieldLabelConversionFunc | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | Apache-2.0 |
func (s *Scheme) AddTypeDefaultingFunc(srcType Object, fn func(interface{})) {
s.defaulterFuncs[reflect.TypeOf(srcType)] = fn
} | AddTypeDefaultingFunc registers a function that is passed a pointer to an
object and can default fields on the object. These functions will be invoked
when Default() is called. The function will never be called unless the
defaulted object matches srcType. If this function is invoked twice with the
same srcType, the fn passed to the later call will be used instead. | AddTypeDefaultingFunc | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | Apache-2.0 |
func (s *Scheme) Default(src Object) {
if fn, ok := s.defaulterFuncs[reflect.TypeOf(src)]; ok {
fn(src)
}
} | Default sets defaults on the provided Object. | Default | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | Apache-2.0 |
func (s *Scheme) Convert(in, out interface{}, context interface{}) error {
unstructuredIn, okIn := in.(Unstructured)
unstructuredOut, okOut := out.(Unstructured)
switch {
case okIn && okOut:
// converting unstructured input to an unstructured output is a straight copy - unstructured
// is a "smart holder" and the contents are passed by reference between the two objects
unstructuredOut.SetUnstructuredContent(unstructuredIn.UnstructuredContent())
return nil
case okOut:
// if the output is an unstructured object, use the standard Go type to unstructured
// conversion. The object must not be internal.
obj, ok := in.(Object)
if !ok {
return fmt.Errorf("unable to convert object type %T to Unstructured, must be a runtime.Object", in)
}
gvks, unversioned, err := s.ObjectKinds(obj)
if err != nil {
return err
}
gvk := gvks[0]
// if no conversion is necessary, convert immediately
if unversioned || gvk.Version != APIVersionInternal {
content, err := DefaultUnstructuredConverter.ToUnstructured(in)
if err != nil {
return err
}
unstructuredOut.SetUnstructuredContent(content)
unstructuredOut.GetObjectKind().SetGroupVersionKind(gvk)
return nil
}
// attempt to convert the object to an external version first.
target, ok := context.(GroupVersioner)
if !ok {
return fmt.Errorf("unable to convert the internal object type %T to Unstructured without providing a preferred version to convert to", in)
}
// Convert is implicitly unsafe, so we don't need to perform a safe conversion
versioned, err := s.UnsafeConvertToVersion(obj, target)
if err != nil {
return err
}
content, err := DefaultUnstructuredConverter.ToUnstructured(versioned)
if err != nil {
return err
}
unstructuredOut.SetUnstructuredContent(content)
return nil
case okIn:
// converting an unstructured object to any type is modeled by first converting
// the input to a versioned type, then running standard conversions
typed, err := s.unstructuredToTyped(unstructuredIn)
if err != nil {
return err
}
in = typed
}
meta := s.generateConvertMeta(in)
meta.Context = context
return s.converter.Convert(in, out, meta)
} | Convert will attempt to convert in into out. Both must be pointers. For easy
testing of conversion functions. Returns an error if the conversion isn't
possible. You can call this with types that haven't been registered (for example,
a to test conversion of types that are nested within registered types). The
context interface is passed to the convertor. Convert also supports Unstructured
types and will convert them intelligently. | Convert | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | Apache-2.0 |
func (s *Scheme) ConvertFieldLabel(gvk schema.GroupVersionKind, label, value string) (string, string, error) {
conversionFunc, ok := s.fieldLabelConversionFuncs[gvk]
if !ok {
return DefaultMetaV1FieldSelectorConversion(label, value)
}
return conversionFunc(label, value)
} | ConvertFieldLabel alters the given field label and value for an kind field selector from
versioned representation to an unversioned one or returns an error. | ConvertFieldLabel | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | Apache-2.0 |
func (s *Scheme) ConvertToVersion(in Object, target GroupVersioner) (Object, error) {
return s.convertToVersion(true, in, target)
} | ConvertToVersion attempts to convert an input object to its matching Kind in another
version within this scheme. Will return an error if the provided version does not
contain the inKind (or a mapping by name defined with AddKnownTypeWithName). Will also
return an error if the conversion does not result in a valid Object being
returned. Passes target down to the conversion methods as the Context on the scope. | ConvertToVersion | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | Apache-2.0 |
func (s *Scheme) UnsafeConvertToVersion(in Object, target GroupVersioner) (Object, error) {
return s.convertToVersion(false, in, target)
} | UnsafeConvertToVersion will convert in to the provided target if such a conversion is possible,
but does not guarantee the output object does not share fields with the input object. It attempts to be as
efficient as possible when doing conversion. | UnsafeConvertToVersion | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | Apache-2.0 |
func (s *Scheme) convertToVersion(copy bool, in Object, target GroupVersioner) (Object, error) {
var t reflect.Type
if u, ok := in.(Unstructured); ok {
typed, err := s.unstructuredToTyped(u)
if err != nil {
return nil, err
}
in = typed
// unstructuredToTyped returns an Object, which must be a pointer to a struct.
t = reflect.TypeOf(in).Elem()
} else {
// determine the incoming kinds with as few allocations as possible.
t = reflect.TypeOf(in)
if t.Kind() != reflect.Pointer {
return nil, fmt.Errorf("only pointer types may be converted: %v", t)
}
t = t.Elem()
if t.Kind() != reflect.Struct {
return nil, fmt.Errorf("only pointers to struct types may be converted: %v", t)
}
}
kinds, ok := s.typeToGVK[t]
if !ok || len(kinds) == 0 {
return nil, NewNotRegisteredErrForType(s.schemeName, t)
}
gvk, ok := target.KindForGroupVersionKinds(kinds)
if !ok {
// try to see if this type is listed as unversioned (for legacy support)
// TODO: when we move to server API versions, we should completely remove the unversioned concept
if unversionedKind, ok := s.unversionedTypes[t]; ok {
if gvk, ok := target.KindForGroupVersionKinds([]schema.GroupVersionKind{unversionedKind}); ok {
return copyAndSetTargetKind(copy, in, gvk)
}
return copyAndSetTargetKind(copy, in, unversionedKind)
}
return nil, NewNotRegisteredErrForTarget(s.schemeName, t, target)
}
// target wants to use the existing type, set kind and return (no conversion necessary)
for _, kind := range kinds {
if gvk == kind {
return copyAndSetTargetKind(copy, in, gvk)
}
}
// type is unversioned, no conversion necessary
if unversionedKind, ok := s.unversionedTypes[t]; ok {
if gvk, ok := target.KindForGroupVersionKinds([]schema.GroupVersionKind{unversionedKind}); ok {
return copyAndSetTargetKind(copy, in, gvk)
}
return copyAndSetTargetKind(copy, in, unversionedKind)
}
out, err := s.New(gvk)
if err != nil {
return nil, err
}
if copy {
in = in.DeepCopyObject()
}
meta := s.generateConvertMeta(in)
meta.Context = target
if err := s.converter.Convert(in, out, meta); err != nil {
return nil, err
}
setTargetKind(out, gvk)
return out, nil
} | convertToVersion handles conversion with an optional copy. | convertToVersion | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | Apache-2.0 |
func (s *Scheme) unstructuredToTyped(in Unstructured) (Object, error) {
// the type must be something we recognize
gvks, _, err := s.ObjectKinds(in)
if err != nil {
return nil, err
}
typed, err := s.New(gvks[0])
if err != nil {
return nil, err
}
if err := DefaultUnstructuredConverter.FromUnstructured(in.UnstructuredContent(), typed); err != nil {
return nil, fmt.Errorf("unable to convert unstructured object to %v: %v", gvks[0], err)
}
return typed, nil
} | unstructuredToTyped attempts to transform an unstructured object to a typed
object if possible. It will return an error if conversion is not possible, or the versioned
Go form of the object. Note that this conversion will lose fields. | unstructuredToTyped | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | Apache-2.0 |
func (s *Scheme) generateConvertMeta(in interface{}) *conversion.Meta {
return s.converter.DefaultMeta(reflect.TypeOf(in))
} | generateConvertMeta constructs the meta value we pass to Convert. | generateConvertMeta | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | Apache-2.0 |
func copyAndSetTargetKind(copy bool, obj Object, kind schema.GroupVersionKind) (Object, error) {
if copy {
obj = obj.DeepCopyObject()
}
setTargetKind(obj, kind)
return obj, nil
} | copyAndSetTargetKind performs a conditional copy before returning the object, or an error if copy was not successful. | copyAndSetTargetKind | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | Apache-2.0 |
func setTargetKind(obj Object, kind schema.GroupVersionKind) {
if kind.Version == APIVersionInternal {
// internal is a special case
// TODO: look at removing the need to special case this
obj.GetObjectKind().SetGroupVersionKind(schema.GroupVersionKind{})
return
}
obj.GetObjectKind().SetGroupVersionKind(kind)
} | setTargetKind sets the kind on an object, taking into account whether the target kind is the internal version. | setTargetKind | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | Apache-2.0 |
func (s *Scheme) SetVersionPriority(versions ...schema.GroupVersion) error {
groups := sets.String{}
order := []string{}
for _, version := range versions {
if len(version.Version) == 0 || version.Version == APIVersionInternal {
return fmt.Errorf("internal versions cannot be prioritized: %v", version)
}
groups.Insert(version.Group)
order = append(order, version.Version)
}
if len(groups) != 1 {
return fmt.Errorf("must register versions for exactly one group: %v", strings.Join(groups.List(), ", "))
}
s.versionPriority[groups.List()[0]] = order
return nil
} | SetVersionPriority allows specifying a precise order of priority. All specified versions must be in the same group,
and the specified order overwrites any previously specified order for this group | SetVersionPriority | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | Apache-2.0 |
func (s *Scheme) PrioritizedVersionsForGroup(group string) []schema.GroupVersion {
ret := []schema.GroupVersion{}
for _, version := range s.versionPriority[group] {
ret = append(ret, schema.GroupVersion{Group: group, Version: version})
}
for _, observedVersion := range s.observedVersions {
if observedVersion.Group != group {
continue
}
found := false
for _, existing := range ret {
if existing == observedVersion {
found = true
break
}
}
if !found {
ret = append(ret, observedVersion)
}
}
return ret
} | PrioritizedVersionsForGroup returns versions for a single group in priority order | PrioritizedVersionsForGroup | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | Apache-2.0 |
func (s *Scheme) PrioritizedVersionsAllGroups() []schema.GroupVersion {
ret := []schema.GroupVersion{}
for group, versions := range s.versionPriority {
for _, version := range versions {
ret = append(ret, schema.GroupVersion{Group: group, Version: version})
}
}
for _, observedVersion := range s.observedVersions {
found := false
for _, existing := range ret {
if existing == observedVersion {
found = true
break
}
}
if !found {
ret = append(ret, observedVersion)
}
}
return ret
} | PrioritizedVersionsAllGroups returns all known versions in their priority order. Groups are random, but
versions for a single group are prioritized | PrioritizedVersionsAllGroups | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | Apache-2.0 |
func (s *Scheme) PreferredVersionAllGroups() []schema.GroupVersion {
ret := []schema.GroupVersion{}
for group, versions := range s.versionPriority {
for _, version := range versions {
ret = append(ret, schema.GroupVersion{Group: group, Version: version})
break
}
}
for _, observedVersion := range s.observedVersions {
found := false
for _, existing := range ret {
if existing.Group == observedVersion.Group {
found = true
break
}
}
if !found {
ret = append(ret, observedVersion)
}
}
return ret
} | PreferredVersionAllGroups returns the most preferred version for every group.
group ordering is random. | PreferredVersionAllGroups | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | Apache-2.0 |
func (s *Scheme) IsGroupRegistered(group string) bool {
for _, observedVersion := range s.observedVersions {
if observedVersion.Group == group {
return true
}
}
return false
} | IsGroupRegistered returns true if types for the group have been registered with the scheme | IsGroupRegistered | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | Apache-2.0 |
func (s *Scheme) IsVersionRegistered(version schema.GroupVersion) bool {
for _, observedVersion := range s.observedVersions {
if observedVersion == version {
return true
}
}
return false
} | IsVersionRegistered returns true if types for the version have been registered with the scheme | IsVersionRegistered | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/scheme.go | Apache-2.0 |
func fieldName(field *ast.Field) string {
jsonTag := ""
if field.Tag != nil {
jsonTag = reflect.StructTag(field.Tag.Value[1 : len(field.Tag.Value)-1]).Get("json") // Delete first and last quotation
if strings.Contains(jsonTag, "inline") {
return "-"
}
}
jsonTag = strings.Split(jsonTag, ",")[0] // This can return "-"
if jsonTag == "" {
if field.Names != nil {
return field.Names[0].Name
}
return field.Type.(*ast.Ident).Name
}
return jsonTag
} | fieldName returns the name of the field as it should appear in JSON format
"-" indicates that this field is not part of the JSON representation | fieldName | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/swagger_doc_generator.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/swagger_doc_generator.go | Apache-2.0 |
func ParseDocumentationFrom(src string) []KubeTypes {
var docForTypes []KubeTypes
pkg := astFrom(src)
for _, kubType := range pkg.Types {
if structType, ok := kubType.Decl.Specs[0].(*ast.TypeSpec).Type.(*ast.StructType); ok {
var ks KubeTypes
ks = append(ks, Pair{kubType.Name, fmtRawDoc(kubType.Doc)})
for _, field := range structType.Fields.List {
if n := fieldName(field); n != "-" {
fieldDoc := fmtRawDoc(field.Doc.Text())
ks = append(ks, Pair{n, fieldDoc})
}
}
docForTypes = append(docForTypes, ks)
}
}
return docForTypes
} | ParseDocumentationFrom gets all types' documentation and returns them as an
array. Each type is again represented as an array (we have to use arrays as we
need to be sure for the order of the fields). This function returns fields and
struct definitions that have no documentation as {name, ""}. | ParseDocumentationFrom | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/swagger_doc_generator.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/swagger_doc_generator.go | Apache-2.0 |
func WriteSwaggerDocFunc(kubeTypes []KubeTypes, w io.Writer) error {
for _, kubeType := range kubeTypes {
structName := kubeType[0].Name
kubeType[0].Name = ""
// Ignore empty documentation
docfulTypes := make(KubeTypes, 0, len(kubeType))
for _, pair := range kubeType {
if pair.Doc != "" {
docfulTypes = append(docfulTypes, pair)
}
}
if len(docfulTypes) == 0 {
continue // If no fields and the struct have documentation, skip the function definition
}
indent := 0
buffer := newBuffer()
writeFuncHeader(buffer, structName, indent)
writeMapBody(buffer, docfulTypes, indent)
writeFuncFooter(buffer, structName, indent)
buffer.addLine("\n", 0)
if err := buffer.flushLines(w); err != nil {
return err
}
}
return nil
} | WriteSwaggerDocFunc writes a declaration of a function as a string. This function is used in
Swagger as a documentation source for structs and theirs fields | WriteSwaggerDocFunc | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/swagger_doc_generator.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/swagger_doc_generator.go | Apache-2.0 |
func VerifySwaggerDocsExist(kubeTypes []KubeTypes, w io.Writer) (int, error) {
missingDocs := 0
buffer := newBuffer()
for _, kubeType := range kubeTypes {
structName := kubeType[0].Name
if kubeType[0].Doc == "" {
format := "Missing documentation for the struct itself: %s\n"
s := fmt.Sprintf(format, structName)
buffer.addLine(s, 0)
missingDocs++
}
kubeType = kubeType[1:] // Skip struct definition
for _, pair := range kubeType { // Iterate only the fields
if pair.Doc == "" {
format := "In struct: %s, field documentation is missing: %s\n"
s := fmt.Sprintf(format, structName, pair.Name)
buffer.addLine(s, 0)
missingDocs++
}
}
}
if err := buffer.flushLines(w); err != nil {
return -1, err
}
return missingDocs, nil
} | VerifySwaggerDocsExist writes in a io.Writer a list of structs and fields that
are missing of documentation. | VerifySwaggerDocsExist | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/swagger_doc_generator.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/swagger_doc_generator.go | Apache-2.0 |
func (m *Unknown) NestedMarshalTo(data []byte, b ProtobufMarshaller, size uint64) (int, error) {
// Calculate the full size of the message.
msgSize := m.Size()
if b != nil {
msgSize += int(size) + sovGenerated(size) + 1
}
// Reverse marshal the fields of m.
i := msgSize
i -= len(m.ContentType)
copy(data[i:], m.ContentType)
i = encodeVarintGenerated(data, i, uint64(len(m.ContentType)))
i--
data[i] = 0x22
i -= len(m.ContentEncoding)
copy(data[i:], m.ContentEncoding)
i = encodeVarintGenerated(data, i, uint64(len(m.ContentEncoding)))
i--
data[i] = 0x1a
if b != nil {
if r, ok := b.(ProtobufReverseMarshaller); ok {
n1, err := r.MarshalToSizedBuffer(data[:i])
if err != nil {
return 0, err
}
i -= int(size)
if uint64(n1) != size {
// programmer error: the Size() method for protobuf does not match the results of LashramOt, which means the proto
// struct returned would be wrong.
return 0, fmt.Errorf("the Size() value of %T was %d, but NestedMarshalTo wrote %d bytes to data", b, size, n1)
}
} else {
i -= int(size)
n1, err := b.MarshalTo(data[i:])
if err != nil {
return 0, err
}
if uint64(n1) != size {
// programmer error: the Size() method for protobuf does not match the results of MarshalTo, which means the proto
// struct returned would be wrong.
return 0, fmt.Errorf("the Size() value of %T was %d, but NestedMarshalTo wrote %d bytes to data", b, size, n1)
}
}
i = encodeVarintGenerated(data, i, size)
i--
data[i] = 0x12
}
n2, err := m.TypeMeta.MarshalToSizedBuffer(data[:i])
if err != nil {
return 0, err
}
i -= n2
i = encodeVarintGenerated(data, i, uint64(n2))
i--
data[i] = 0xa
return msgSize - i, nil
} | NestedMarshalTo allows a caller to avoid extra allocations during serialization of an Unknown
that will contain an object that implements ProtobufMarshaller or ProtobufReverseMarshaller. | NestedMarshalTo | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/types_proto.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/types_proto.go | Apache-2.0 |
func (sb *spliceBuffer) Splice(raw []byte) {
sb.raw = raw
} | Splice implements the Splice interface. | Splice | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/splice.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/splice.go | Apache-2.0 |
func (sb *spliceBuffer) Write(p []byte) (n int, err error) {
if sb.buf == nil {
sb.buf = &bytes.Buffer{}
}
return sb.buf.Write(p)
} | Write implements the io.Writer interface. | Write | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/splice.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/splice.go | Apache-2.0 |
func (sb *spliceBuffer) Reset() {
if sb.buf != nil {
sb.buf.Reset()
}
sb.raw = nil
} | Reset resets the buffer to be empty. | Reset | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/splice.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/splice.go | Apache-2.0 |
func (sb *spliceBuffer) Bytes() []byte {
if sb.buf != nil && len(sb.buf.Bytes()) > 0 {
return sb.buf.Bytes()
}
if sb.raw != nil {
return sb.raw
}
return []byte{}
} | Bytes returns the data held by the buffer. | Bytes | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/splice.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/splice.go | Apache-2.0 |
func IsNotRegisteredError(err error) bool {
if err == nil {
return false
}
_, ok := err.(*notRegisteredErr)
return ok
} | IsNotRegisteredError returns true if the error indicates the provided
object or input data is not registered. | IsNotRegisteredError | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/error.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/error.go | Apache-2.0 |
func IsMissingKind(err error) bool {
if err == nil {
return false
}
_, ok := err.(*missingKindErr)
return ok
} | IsMissingKind returns true if the error indicates that the provided object
is missing a 'Kind' field. | IsMissingKind | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/error.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/error.go | Apache-2.0 |
func IsMissingVersion(err error) bool {
if err == nil {
return false
}
_, ok := err.(*missingVersionErr)
return ok
} | IsMissingVersion returns true if the error indicates that the provided object
is missing a 'Version' field. | IsMissingVersion | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/error.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/error.go | Apache-2.0 |
func NewStrictDecodingError(errors []error) error {
return &strictDecodingError{
errors: errors,
}
} | NewStrictDecodingError creates a new strictDecodingError object. | NewStrictDecodingError | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/error.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/error.go | Apache-2.0 |
func IsStrictDecodingError(err error) bool {
if err == nil {
return false
}
_, ok := err.(*strictDecodingError)
return ok
} | IsStrictDecodingError returns true if the error indicates that the provided object
strictness violations. | IsStrictDecodingError | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/error.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/error.go | Apache-2.0 |
func AsStrictDecodingError(err error) (*strictDecodingError, bool) {
if err == nil {
return nil, false
}
strictErr, ok := err.(*strictDecodingError)
return strictErr, ok
} | AsStrictDecodingError returns a strict decoding error
containing all the strictness violations. | AsStrictDecodingError | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/error.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/error.go | Apache-2.0 |
func (re RawExtension) MarshalJSON() ([]byte, error) {
if re.Raw == nil {
// TODO: this is to support legacy behavior of JSONPrinter and YAMLPrinter, which
// expect to call json.Marshal on arbitrary versioned objects (even those not in
// the scheme). pkg/kubectl/resource#AsVersionedObjects and its interaction with
// kubectl get on objects not in the scheme needs to be updated to ensure that the
// objects that are not part of the scheme are correctly put into the right form.
if re.Object != nil {
return json.Marshal(re.Object)
}
return []byte("null"), nil
}
// TODO: Check whether ContentType is actually JSON before returning it.
return re.Raw, nil
} | MarshalJSON may get called on pointers or values, so implement MarshalJSON on value.
http://stackoverflow.com/questions/21390979/custom-marshaljson-never-gets-called-in-go | MarshalJSON | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/extension.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/extension.go | Apache-2.0 |
func NewClientNegotiator(serializer NegotiatedSerializer, gv schema.GroupVersion) ClientNegotiator {
return &clientNegotiator{
serializer: serializer,
encode: gv,
}
} | NewClientNegotiator will attempt to retrieve the appropriate encoder, decoder, or
stream decoder for a given content type. Does not perform any conversion, but will
encode the object to the desired group, version, and kind. Use when creating a client. | NewClientNegotiator | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/negotiate.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/negotiate.go | Apache-2.0 |
func (c unsafeObjectConvertor) ConvertToVersion(in Object, outVersion GroupVersioner) (Object, error) {
return c.Scheme.UnsafeConvertToVersion(in, outVersion)
} | ConvertToVersion converts in to the provided outVersion without copying the input first, which
is only safe if the output object is not mutated or reused. | ConvertToVersion | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/helper.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/helper.go | Apache-2.0 |
func UnsafeObjectConvertor(scheme *Scheme) ObjectConvertor {
return unsafeObjectConvertor{scheme}
} | UnsafeObjectConvertor performs object conversion without copying the object structure,
for use when the converted object will not be reused or mutated. Primarily for use within
versioned codecs, which use the external object for serialization but do not return it. | UnsafeObjectConvertor | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/helper.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/helper.go | Apache-2.0 |
func SetField(src interface{}, v reflect.Value, fieldName string) error {
field := v.FieldByName(fieldName)
if !field.IsValid() {
return fmt.Errorf("couldn't find %v field in %T", fieldName, v.Interface())
}
srcValue := reflect.ValueOf(src)
if srcValue.Type().AssignableTo(field.Type()) {
field.Set(srcValue)
return nil
}
if srcValue.Type().ConvertibleTo(field.Type()) {
field.Set(srcValue.Convert(field.Type()))
return nil
}
return fmt.Errorf("couldn't assign/convert %v to %v", srcValue.Type(), field.Type())
} | SetField puts the value of src, into fieldName, which must be a member of v.
The value of src must be assignable to the field. | SetField | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/helper.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/helper.go | Apache-2.0 |
func Field(v reflect.Value, fieldName string, dest interface{}) error {
field := v.FieldByName(fieldName)
if !field.IsValid() {
return fmt.Errorf("couldn't find %v field in %T", fieldName, v.Interface())
}
destValue, err := conversion.EnforcePtr(dest)
if err != nil {
return err
}
if field.Type().AssignableTo(destValue.Type()) {
destValue.Set(field)
return nil
}
if field.Type().ConvertibleTo(destValue.Type()) {
destValue.Set(field.Convert(destValue.Type()))
return nil
}
return fmt.Errorf("couldn't assign/convert %v to %v", field.Type(), destValue.Type())
} | Field puts the value of fieldName, which must be a member of v, into dest,
which must be a variable to which this field's value can be assigned. | Field | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/helper.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/helper.go | Apache-2.0 |
func FieldPtr(v reflect.Value, fieldName string, dest interface{}) error {
field := v.FieldByName(fieldName)
if !field.IsValid() {
return fmt.Errorf("couldn't find %v field in %T", fieldName, v.Interface())
}
v, err := conversion.EnforcePtr(dest)
if err != nil {
return err
}
field = field.Addr()
if field.Type().AssignableTo(v.Type()) {
v.Set(field)
return nil
}
if field.Type().ConvertibleTo(v.Type()) {
v.Set(field.Convert(v.Type()))
return nil
}
return fmt.Errorf("couldn't assign/convert %v to %v", field.Type(), v.Type())
} | FieldPtr puts the address of fieldName, which must be a member of v,
into dest, which must be an address of a variable to which this field's
address can be assigned. | FieldPtr | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/helper.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/helper.go | Apache-2.0 |
func EncodeList(e Encoder, objects []Object) error {
var errs []error
for i := range objects {
data, err := Encode(e, objects[i])
if err != nil {
errs = append(errs, err)
continue
}
// TODO: Set ContentEncoding and ContentType.
objects[i] = &Unknown{Raw: data}
}
return errors.NewAggregate(errs)
} | EncodeList ensures that each object in an array is converted to a Unknown{} in serialized form.
TODO: accept a content type. | EncodeList | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/helper.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/helper.go | Apache-2.0 |
func DecodeList(objects []Object, decoders ...Decoder) []error {
errs := []error(nil)
for i, obj := range objects {
switch t := obj.(type) {
case *Unknown:
decoded, err := decodeListItem(t, decoders)
if err != nil {
errs = append(errs, err)
break
}
objects[i] = decoded
}
} | DecodeList alters the list in place, attempting to decode any objects found in
the list that have the Unknown type. Any errors that occur are returned
after the entire list is processed. Decoders are tried in order. | DecodeList | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/helper.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/helper.go | Apache-2.0 |
func NewSchemeBuilder(funcs ...func(*Scheme) error) SchemeBuilder {
var sb SchemeBuilder
sb.Register(funcs...)
return sb
} | NewSchemeBuilder calls Register for you. | NewSchemeBuilder | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/scheme_builder.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/scheme_builder.go | Apache-2.0 |
func CheckCodec(c Codec, internalType Object, externalTypes ...schema.GroupVersionKind) error {
if _, err := Encode(c, internalType); err != nil {
return fmt.Errorf("internal type not encodable: %v", err)
}
for _, et := range externalTypes {
typeMeta := TypeMeta{
Kind: et.Kind,
APIVersion: et.GroupVersion().String(),
}
exBytes, err := json.Marshal(&typeMeta)
if err != nil {
return err
}
obj, err := Decode(c, exBytes)
if err != nil {
return fmt.Errorf("external type %s not interpretable: %v", et, err)
}
if reflect.TypeOf(obj) != reflect.TypeOf(internalType) {
return fmt.Errorf("decode of external type %s produced: %#v", et, obj)
}
if err = DecodeInto(c, exBytes, internalType); err != nil {
return fmt.Errorf("external type %s not convertible to internal type: %v", et, err)
}
}
return nil
} | CheckCodec makes sure that the codec can encode objects like internalType,
decode all of the external types listed, and also decode them into the given
object. (Will modify internalObject.) (Assumes JSON serialization.)
TODO: verify that the correct external version is chosen on encode... | CheckCodec | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/codec_check.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/codec_check.go | Apache-2.0 |
func EnablePretty(options *CodecFactoryOptions) {
options.Pretty = true
} | EnablePretty enables including a pretty serializer along with the non-pretty one | EnablePretty | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/serializer/codec_factory.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/serializer/codec_factory.go | Apache-2.0 |
func DisablePretty(options *CodecFactoryOptions) {
options.Pretty = false
} | DisablePretty disables including a pretty serializer along with the non-pretty one | DisablePretty | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/serializer/codec_factory.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/serializer/codec_factory.go | Apache-2.0 |
func EnableStrict(options *CodecFactoryOptions) {
options.Strict = true
} | EnableStrict enables configuring all serializers in strict mode | EnableStrict | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/serializer/codec_factory.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/serializer/codec_factory.go | Apache-2.0 |
func DisableStrict(options *CodecFactoryOptions) {
options.Strict = false
} | DisableStrict disables configuring all serializers in strict mode | DisableStrict | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/serializer/codec_factory.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/serializer/codec_factory.go | Apache-2.0 |
func NewCodecFactory(scheme *runtime.Scheme, mutators ...CodecFactoryOptionsMutator) CodecFactory {
options := CodecFactoryOptions{Pretty: true}
for _, fn := range mutators {
fn(&options)
}
serializers := newSerializersForScheme(scheme, json.DefaultMetaFactory, options)
return newCodecFactory(scheme, serializers)
} | NewCodecFactory provides methods for retrieving serializers for the supported wire formats
and conversion wrappers to define preferred internal and external versions. In the future,
as the internal version is used less, callers may instead use a defaulting serializer and
only convert objects which are shared internally (Status, common API machinery).
Mutators can be passed to change the CodecFactoryOptions before construction of the factory.
It is recommended to explicitly pass mutators instead of relying on defaults.
By default, Pretty is enabled -- this is conformant with previously supported behavior.
TODO: allow other codecs to be compiled in?
TODO: accept a scheme interface | NewCodecFactory | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/serializer/codec_factory.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/serializer/codec_factory.go | Apache-2.0 |
func newCodecFactory(scheme *runtime.Scheme, serializers []serializerType) CodecFactory {
decoders := make([]runtime.Decoder, 0, len(serializers))
var accepts []runtime.SerializerInfo
alreadyAccepted := make(map[string]struct{})
var legacySerializer runtime.Serializer
for _, d := range serializers {
decoders = append(decoders, d.Serializer)
for _, mediaType := range d.AcceptContentTypes {
if _, ok := alreadyAccepted[mediaType]; ok {
continue
}
alreadyAccepted[mediaType] = struct{}{}
info := runtime.SerializerInfo{
MediaType: d.ContentType,
EncodesAsText: d.EncodesAsText,
Serializer: d.Serializer,
PrettySerializer: d.PrettySerializer,
StrictSerializer: d.StrictSerializer,
}
mediaType, _, err := mime.ParseMediaType(info.MediaType)
if err != nil {
panic(err)
}
parts := strings.SplitN(mediaType, "/", 2)
info.MediaTypeType = parts[0]
info.MediaTypeSubType = parts[1]
if d.StreamSerializer != nil {
info.StreamSerializer = &runtime.StreamSerializerInfo{
Serializer: d.StreamSerializer,
EncodesAsText: d.EncodesAsText,
Framer: d.Framer,
}
}
accepts = append(accepts, info)
if mediaType == runtime.ContentTypeJSON {
legacySerializer = d.Serializer
}
}
}
if legacySerializer == nil {
legacySerializer = serializers[0].Serializer
}
return CodecFactory{
scheme: scheme,
universal: recognizer.NewDecoder(decoders...),
accepts: accepts,
legacySerializer: legacySerializer,
}
} | newCodecFactory is a helper for testing that allows a different metafactory to be specified. | newCodecFactory | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/serializer/codec_factory.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/serializer/codec_factory.go | Apache-2.0 |
func (f CodecFactory) WithoutConversion() runtime.NegotiatedSerializer {
return WithoutConversionCodecFactory{f}
} | WithoutConversion returns a NegotiatedSerializer that performs no conversion, even if the
caller requests it. | WithoutConversion | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/serializer/codec_factory.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/serializer/codec_factory.go | Apache-2.0 |
func (f CodecFactory) SupportedMediaTypes() []runtime.SerializerInfo {
return f.accepts
} | SupportedMediaTypes returns the RFC2046 media types that this factory has serializers for. | SupportedMediaTypes | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/serializer/codec_factory.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/serializer/codec_factory.go | Apache-2.0 |
func (f CodecFactory) LegacyCodec(version ...schema.GroupVersion) runtime.Codec {
return versioning.NewDefaultingCodecForScheme(f.scheme, f.legacySerializer, f.universal, schema.GroupVersions(version), runtime.InternalGroupVersioner)
} | LegacyCodec encodes output to a given API versions, and decodes output into the internal form from
any recognized source. The returned codec will always encode output to JSON. If a type is not
found in the list of versions an error will be returned.
This method is deprecated - clients and servers should negotiate a serializer by mime-type and
invoke CodecForVersions. Callers that need only to read data should use UniversalDecoder().
TODO: make this call exist only in pkg/api, and initialize it with the set of default versions.
All other callers will be forced to request a Codec directly. | LegacyCodec | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/serializer/codec_factory.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/serializer/codec_factory.go | Apache-2.0 |
func (f CodecFactory) UniversalDeserializer() runtime.Decoder {
return f.universal
} | UniversalDeserializer can convert any stored data recognized by this factory into a Go object that satisfies
runtime.Object. It does not perform conversion. It does not perform defaulting. | UniversalDeserializer | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/serializer/codec_factory.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/serializer/codec_factory.go | Apache-2.0 |
func (f CodecFactory) UniversalDecoder(versions ...schema.GroupVersion) runtime.Decoder {
var versioner runtime.GroupVersioner
if len(versions) == 0 {
versioner = runtime.InternalGroupVersioner
} else {
versioner = schema.GroupVersions(versions)
}
return f.CodecForVersions(nil, f.universal, nil, versioner)
} | UniversalDecoder returns a runtime.Decoder capable of decoding all known API objects in all known formats. Used
by clients that do not need to encode objects but want to deserialize API objects stored on disk. Only decodes
objects in groups registered with the scheme. The GroupVersions passed may be used to select alternate
versions of objects to return - by default, runtime.APIVersionInternal is used. If any versions are specified,
unrecognized groups will be returned in the version they are encoded as (no conversion). This decoder performs
defaulting.
TODO: the decoder will eventually be removed in favor of dealing with objects in their versioned form
TODO: only accept a group versioner | UniversalDecoder | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/serializer/codec_factory.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/serializer/codec_factory.go | Apache-2.0 |
func (f CodecFactory) CodecForVersions(encoder runtime.Encoder, decoder runtime.Decoder, encode runtime.GroupVersioner, decode runtime.GroupVersioner) runtime.Codec {
// TODO: these are for backcompat, remove them in the future
if encode == nil {
encode = runtime.DisabledGroupVersioner
}
if decode == nil {
decode = runtime.InternalGroupVersioner
}
return versioning.NewDefaultingCodecForScheme(f.scheme, encoder, decoder, encode, decode)
} | CodecForVersions creates a codec with the provided serializer. If an object is decoded and its group is not in the list,
it will default to runtime.APIVersionInternal. If encode is not specified for an object's group, the object is not
converted. If encode or decode are nil, no conversion is performed. | CodecForVersions | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/serializer/codec_factory.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/serializer/codec_factory.go | Apache-2.0 |
func (f CodecFactory) DecoderToVersion(decoder runtime.Decoder, gv runtime.GroupVersioner) runtime.Decoder {
return f.CodecForVersions(nil, decoder, nil, gv)
} | DecoderToVersion returns a decoder that targets the provided group version. | DecoderToVersion | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/serializer/codec_factory.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/serializer/codec_factory.go | Apache-2.0 |
func (f CodecFactory) EncoderForVersion(encoder runtime.Encoder, gv runtime.GroupVersioner) runtime.Encoder {
return f.CodecForVersions(encoder, nil, gv, nil)
} | EncoderForVersion returns an encoder that targets the provided group version. | EncoderForVersion | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/serializer/codec_factory.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/serializer/codec_factory.go | Apache-2.0 |
func (f WithoutConversionCodecFactory) EncoderForVersion(serializer runtime.Encoder, version runtime.GroupVersioner) runtime.Encoder {
return runtime.WithVersionEncoder{
Version: version,
Encoder: serializer,
ObjectTyper: f.CodecFactory.scheme,
}
} | EncoderForVersion returns an encoder that does not do conversion, but does set the group version kind of the object
when serialized. | EncoderForVersion | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/serializer/codec_factory.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/serializer/codec_factory.go | Apache-2.0 |
func (f WithoutConversionCodecFactory) DecoderToVersion(serializer runtime.Decoder, _ runtime.GroupVersioner) runtime.Decoder {
return runtime.WithoutVersionDecoder{
Decoder: serializer,
}
} | DecoderToVersion returns an decoder that does not do conversion. | DecoderToVersion | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/serializer/codec_factory.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/serializer/codec_factory.go | Apache-2.0 |
func NewDecoder(r io.ReadCloser, d runtime.Decoder) Decoder {
return &decoder{
reader: r,
decoder: d,
buf: make([]byte, 1024),
maxBytes: 16 * 1024 * 1024,
}
} | NewDecoder creates a streaming decoder that reads object chunks from r and decodes them with d.
The reader is expected to return ErrShortRead if the provided buffer is not large enough to read
an entire object. | NewDecoder | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/serializer/streaming/streaming.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/serializer/streaming/streaming.go | Apache-2.0 |
func (d *decoder) Decode(defaults *schema.GroupVersionKind, into runtime.Object) (runtime.Object, *schema.GroupVersionKind, error) {
base := 0
for {
n, err := d.reader.Read(d.buf[base:])
if err == io.ErrShortBuffer {
if n == 0 {
return nil, nil, fmt.Errorf("got short buffer with n=0, base=%d, cap=%d", base, cap(d.buf))
}
if d.resetRead {
continue
}
// double the buffer size up to maxBytes
if len(d.buf) < d.maxBytes {
base += n
d.buf = append(d.buf, make([]byte, len(d.buf))...)
continue
}
// must read the rest of the frame (until we stop getting ErrShortBuffer)
d.resetRead = true
return nil, nil, ErrObjectTooLarge
}
if err != nil {
return nil, nil, err
}
if d.resetRead {
// now that we have drained the large read, continue
d.resetRead = false
continue
}
base += n
break
}
return d.decoder.Decode(d.buf[:base], defaults, into)
} | Decode reads the next object from the stream and decodes it. | Decode | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/serializer/streaming/streaming.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/serializer/streaming/streaming.go | Apache-2.0 |
func NewEncoder(w io.Writer, e runtime.Encoder) Encoder {
return &encoder{
writer: w,
encoder: e,
buf: &bytes.Buffer{},
}
} | NewEncoder returns a new streaming encoder. | NewEncoder | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/serializer/streaming/streaming.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/serializer/streaming/streaming.go | Apache-2.0 |
func (e *encoder) Encode(obj runtime.Object) error {
if err := e.encoder.Encode(obj, e.buf); err != nil {
return err
}
_, err := e.writer.Write(e.buf.Bytes())
e.buf.Reset()
return err
} | Encode writes the provided object to the nested writer. | Encode | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/serializer/streaming/streaming.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/serializer/streaming/streaming.go | Apache-2.0 |
func IsNotMarshalable(err error) bool {
_, ok := err.(errNotMarshalable)
return err != nil && ok
} | IsNotMarshalable checks the type of error, returns a boolean true if error is not nil and not marshalable false otherwise | IsNotMarshalable | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/serializer/protobuf/protobuf.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/serializer/protobuf/protobuf.go | Apache-2.0 |
func NewSerializer(creater runtime.ObjectCreater, typer runtime.ObjectTyper) *Serializer {
return &Serializer{
prefix: protoEncodingPrefix,
creater: creater,
typer: typer,
}
} | NewSerializer creates a Protobuf serializer that handles encoding versioned objects into the proper wire form. If a typer
is passed, the encoded object will have group, version, and kind fields set. If typer is nil, the objects will be written
as-is (any type info passed with the object will be used). | NewSerializer | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/serializer/protobuf/protobuf.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/serializer/protobuf/protobuf.go | Apache-2.0 |
func (s *Serializer) Decode(originalData []byte, gvk *schema.GroupVersionKind, into runtime.Object) (runtime.Object, *schema.GroupVersionKind, error) {
prefixLen := len(s.prefix)
switch {
case len(originalData) == 0:
// TODO: treat like decoding {} from JSON with defaulting
return nil, nil, fmt.Errorf("empty data")
case len(originalData) < prefixLen || !bytes.Equal(s.prefix, originalData[:prefixLen]):
return nil, nil, fmt.Errorf("provided data does not appear to be a protobuf message, expected prefix %v", s.prefix)
case len(originalData) == prefixLen:
// TODO: treat like decoding {} from JSON with defaulting
return nil, nil, fmt.Errorf("empty body")
}
data := originalData[prefixLen:]
unk := runtime.Unknown{}
if err := unk.Unmarshal(data); err != nil {
return nil, nil, err
}
actual := unk.GroupVersionKind()
copyKindDefaults(&actual, gvk)
if intoUnknown, ok := into.(*runtime.Unknown); ok && intoUnknown != nil {
*intoUnknown = unk
if ok, _, _ := s.RecognizesData(unk.Raw); ok {
intoUnknown.ContentType = runtime.ContentTypeProtobuf
}
return intoUnknown, &actual, nil
}
if into != nil {
types, _, err := s.typer.ObjectKinds(into)
switch {
case runtime.IsNotRegisteredError(err):
pb, ok := into.(proto.Message)
if !ok {
return nil, &actual, errNotMarshalable{reflect.TypeOf(into)}
}
if err := proto.Unmarshal(unk.Raw, pb); err != nil {
return nil, &actual, err
}
return into, &actual, nil
case err != nil:
return nil, &actual, err
default:
copyKindDefaults(&actual, &types[0])
// if the result of defaulting did not set a version or group, ensure that at least group is set
// (copyKindDefaults will not assign Group if version is already set). This guarantees that the group
// of into is set if there is no better information from the caller or object.
if len(actual.Version) == 0 && len(actual.Group) == 0 {
actual.Group = types[0].Group
}
}
}
if len(actual.Kind) == 0 {
return nil, &actual, runtime.NewMissingKindErr(fmt.Sprintf("%#v", unk.TypeMeta))
}
if len(actual.Version) == 0 {
return nil, &actual, runtime.NewMissingVersionErr(fmt.Sprintf("%#v", unk.TypeMeta))
}
return unmarshalToObject(s.typer, s.creater, &actual, into, unk.Raw)
} | Decode attempts to convert the provided data into a protobuf message, 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 protobuf unmarshalling (the MarshalTo interface). 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. | Decode | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/serializer/protobuf/protobuf.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/serializer/protobuf/protobuf.go | Apache-2.0 |
func (s *Serializer) EncodeWithAllocator(obj runtime.Object, w io.Writer, memAlloc runtime.MemoryAllocator) error {
return s.encode(obj, w, memAlloc)
} | EncodeWithAllocator writes an object to the provided writer.
In addition, it allows for providing a memory allocator for efficient memory usage during object serialization. | EncodeWithAllocator | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/serializer/protobuf/protobuf.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/serializer/protobuf/protobuf.go | Apache-2.0 |
func (s *Serializer) Encode(obj runtime.Object, w io.Writer) error {
return s.encode(obj, w, &runtime.SimpleAllocator{})
} | Encode serializes the provided object to the given writer. | Encode | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/serializer/protobuf/protobuf.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/serializer/protobuf/protobuf.go | Apache-2.0 |
func NewDecoder(decoders ...runtime.Decoder) runtime.Decoder {
return &decoder{
decoders: decoders,
}
} | NewDecoder creates a decoder that will attempt multiple decoders in an order defined
by:
1. The decoder implements RecognizingDecoder and identifies the data
2. All other decoders, and any decoder that returned true for unknown.
The order passed to the constructor is preserved within those priorities. | NewDecoder | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/serializer/recognizer/recognizer.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/serializer/recognizer/recognizer.go | Apache-2.0 |
func NewSerializer(meta MetaFactory, creater runtime.ObjectCreater, typer runtime.ObjectTyper, pretty bool) *Serializer {
return NewSerializerWithOptions(meta, creater, typer, SerializerOptions{false, pretty, false})
} | NewSerializer creates a JSON serializer that handles encoding versioned objects into the proper JSON form. If typer
is not nil, the object has the group, version, and kind fields set.
Deprecated: use NewSerializerWithOptions instead. | NewSerializer | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/serializer/json/json.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/serializer/json/json.go | Apache-2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.