mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #65729 from cfork/comments
Automatic merge from submit-queue (batch tested with PRs 64599, 65729). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. apimachinery: cleanup code and comments fix golint issues /kind cleanup ```release-note NONE ```
This commit is contained in:
commit
036434583f
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// Defines conversions between generic types and structs to map query strings
|
||||
// Package runtime defines conversions between generic types and structs to map query strings
|
||||
// to struct objects.
|
||||
package runtime
|
||||
|
||||
@ -27,7 +27,7 @@ import (
|
||||
"k8s.io/apimachinery/pkg/conversion"
|
||||
)
|
||||
|
||||
// DefaultFieldSelectorConversion auto-accepts metav1 values for name and 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.
|
||||
func DefaultMetaV1FieldSelectorConversion(label, value string) (string, string, error) {
|
||||
|
@ -41,5 +41,4 @@ limitations under the License.
|
||||
//
|
||||
// As a bonus, a few common types useful from all api objects and versions
|
||||
// are provided in types.go.
|
||||
|
||||
package runtime // import "k8s.io/apimachinery/pkg/runtime"
|
||||
|
@ -31,7 +31,7 @@ type encodable struct {
|
||||
|
||||
func (e encodable) GetObjectKind() schema.ObjectKind { return e.obj.GetObjectKind() }
|
||||
func (e encodable) DeepCopyObject() Object {
|
||||
var out encodable = e
|
||||
out := e
|
||||
out.obj = e.obj.DeepCopyObject()
|
||||
copy(out.versions, e.versions)
|
||||
return out
|
||||
@ -46,14 +46,14 @@ func NewEncodable(e Encoder, obj Object, versions ...schema.GroupVersion) Object
|
||||
return encodable{e, obj, versions}
|
||||
}
|
||||
|
||||
func (re encodable) UnmarshalJSON(in []byte) error {
|
||||
func (e encodable) UnmarshalJSON(in []byte) error {
|
||||
return errors.New("runtime.encodable cannot be unmarshalled from JSON")
|
||||
}
|
||||
|
||||
// Marshal may get called on pointers or values, so implement MarshalJSON on value.
|
||||
// http://stackoverflow.com/questions/21390979/custom-marshaljson-never-gets-called-in-go
|
||||
func (re encodable) MarshalJSON() ([]byte, error) {
|
||||
return Encode(re.E, re.obj)
|
||||
func (e encodable) MarshalJSON() ([]byte, error) {
|
||||
return Encode(e.E, e.obj)
|
||||
}
|
||||
|
||||
// NewEncodableList creates an object that will be encoded with the provided codec on demand.
|
||||
@ -70,28 +70,28 @@ func NewEncodableList(e Encoder, objects []Object, versions ...schema.GroupVersi
|
||||
return out
|
||||
}
|
||||
|
||||
func (re *Unknown) UnmarshalJSON(in []byte) error {
|
||||
if re == nil {
|
||||
func (e *Unknown) UnmarshalJSON(in []byte) error {
|
||||
if e == nil {
|
||||
return errors.New("runtime.Unknown: UnmarshalJSON on nil pointer")
|
||||
}
|
||||
re.TypeMeta = TypeMeta{}
|
||||
re.Raw = append(re.Raw[0:0], in...)
|
||||
re.ContentEncoding = ""
|
||||
re.ContentType = ContentTypeJSON
|
||||
e.TypeMeta = TypeMeta{}
|
||||
e.Raw = append(e.Raw[0:0], in...)
|
||||
e.ContentEncoding = ""
|
||||
e.ContentType = ContentTypeJSON
|
||||
return nil
|
||||
}
|
||||
|
||||
// Marshal may get called on pointers or values, so implement MarshalJSON on value.
|
||||
// http://stackoverflow.com/questions/21390979/custom-marshaljson-never-gets-called-in-go
|
||||
func (re Unknown) MarshalJSON() ([]byte, error) {
|
||||
func (e Unknown) MarshalJSON() ([]byte, error) {
|
||||
// If ContentType is unset, we assume this is JSON.
|
||||
if re.ContentType != "" && re.ContentType != ContentTypeJSON {
|
||||
if e.ContentType != "" && e.ContentType != ContentTypeJSON {
|
||||
return nil, errors.New("runtime.Unknown: MarshalJSON on non-json data")
|
||||
}
|
||||
if re.Raw == nil {
|
||||
if e.Raw == nil {
|
||||
return []byte("null"), nil
|
||||
}
|
||||
return re.Raw, nil
|
||||
return e.Raw, nil
|
||||
}
|
||||
|
||||
func Convert_runtime_Object_To_runtime_RawExtension(in *Object, out *RawExtension, s conversion.Scope) error {
|
||||
|
@ -32,7 +32,7 @@ func (re *RawExtension) UnmarshalJSON(in []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Marshal may get called on pointers or values, so implement MarshalJSON on value.
|
||||
// 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
|
||||
func (re RawExtension) MarshalJSON() ([]byte, error) {
|
||||
if re.Raw == nil {
|
||||
|
@ -87,7 +87,7 @@ func Field(v reflect.Value, fieldName string, dest interface{}) error {
|
||||
return fmt.Errorf("couldn't assign/convert %v to %v", field.Type(), destValue.Type())
|
||||
}
|
||||
|
||||
// fieldPtr puts the address of fieldName, which must be a member of v,
|
||||
// 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.
|
||||
func FieldPtr(v reflect.Value, fieldName string, dest interface{}) error {
|
||||
|
@ -39,14 +39,14 @@ type GroupVersioner interface {
|
||||
KindForGroupVersionKinds(kinds []schema.GroupVersionKind) (target schema.GroupVersionKind, ok bool)
|
||||
}
|
||||
|
||||
// Encoders write objects to a serialized form
|
||||
// Encoder writes objects to a serialized form
|
||||
type Encoder interface {
|
||||
// Encode writes an object to a stream. Implementations may return errors if the versions are
|
||||
// incompatible, or if no conversion is defined.
|
||||
Encode(obj Object, w io.Writer) error
|
||||
}
|
||||
|
||||
// Decoders attempt to load an object from data.
|
||||
// Decoder attempts to load an object from data.
|
||||
type Decoder interface {
|
||||
// Decode attempts to deserialize the provided data using either the innate typing of the scheme or the
|
||||
// default kind, group, and version provided. It returns a decoded object as well as the kind, group, and
|
||||
@ -224,7 +224,7 @@ type SelfLinker interface {
|
||||
Namespace(obj Object) (string, error)
|
||||
}
|
||||
|
||||
// All API types registered with Scheme must support the Object interface. Since objects in a scheme are
|
||||
// Object interface must be supported by all API types registered with Scheme. Since objects in a scheme are
|
||||
// expected to be serialized to the wire, the interface an Object must provide to the Scheme allows
|
||||
// serializers to set the kind, version, and group the object is represented as. An Object may choose
|
||||
// to return a no-op ObjectKindAccessor in cases where it is not expected to be serialized.
|
||||
|
@ -85,11 +85,10 @@ func ParseGroupKind(gk string) GroupKind {
|
||||
// ParseGroupResource turns "resource.group" string into a GroupResource struct. Empty strings are allowed
|
||||
// for each field.
|
||||
func ParseGroupResource(gr string) GroupResource {
|
||||
if i := strings.Index(gr, "."); i == -1 {
|
||||
return GroupResource{Resource: gr}
|
||||
} else {
|
||||
if i := strings.Index(gr, "."); i >= 0 {
|
||||
return GroupResource{Group: gr[i+1:], Resource: gr[:i]}
|
||||
}
|
||||
return GroupResource{Resource: gr}
|
||||
}
|
||||
|
||||
// GroupVersionResource unambiguously identifies a resource. It doesn't anonymously include GroupVersion
|
||||
|
@ -81,7 +81,7 @@ type Scheme struct {
|
||||
observedVersions []schema.GroupVersion
|
||||
}
|
||||
|
||||
// Function to convert a field selector to internal representation.
|
||||
// FieldLabelConversionFunc converts a field selector to internal representation.
|
||||
type FieldLabelConversionFunc func(label, value string) (internalLabel, internalValue string, err error)
|
||||
|
||||
// NewScheme creates a new Scheme. This scheme is pluggable by default.
|
||||
@ -388,7 +388,7 @@ func (s *Scheme) RegisterInputDefaults(in interface{}, fn conversion.FieldMappin
|
||||
return s.converter.RegisterInputDefaults(in, fn, defaultFlags)
|
||||
}
|
||||
|
||||
// AddTypeDefaultingFuncs registers a function that is passed a pointer to an
|
||||
// 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
|
||||
|
@ -273,7 +273,7 @@ func (jsonFramer) NewFrameReader(r io.ReadCloser) io.ReadCloser {
|
||||
return framer.NewJSONFramedReader(r)
|
||||
}
|
||||
|
||||
// Framer is the default JSON framing behavior, with newlines delimiting individual objects.
|
||||
// YAMLFramer is the default JSON framing behavior, with newlines delimiting individual objects.
|
||||
var YAMLFramer = yamlFramer{}
|
||||
|
||||
type yamlFramer struct{}
|
||||
|
Loading…
Reference in New Issue
Block a user