2014-08-29 22:48:41 +00:00
|
|
|
/*
|
2016-06-03 00:25:58 +00:00
|
|
|
Copyright 2014 The Kubernetes Authors.
|
2014-08-29 22:48:41 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2014-09-02 17:55:27 +00:00
|
|
|
package runtime
|
2014-08-29 22:48:41 +00:00
|
|
|
|
2014-09-02 17:55:27 +00:00
|
|
|
// Note that the types provided in this file are not versioned and are intended to be
|
|
|
|
// safe to use from within all versions of every API object.
|
|
|
|
|
2014-10-07 15:12:16 +00:00
|
|
|
// TypeMeta is shared by all top level objects. The proper way to use it is to inline it in your type,
|
2014-08-29 22:48:41 +00:00
|
|
|
// like this:
|
|
|
|
// type MyAwesomeAPIObject struct {
|
2014-12-01 05:31:52 +00:00
|
|
|
// runtime.TypeMeta `json:",inline"`
|
2014-10-23 02:28:06 +00:00
|
|
|
// ... // other fields
|
2014-08-29 22:48:41 +00:00
|
|
|
// }
|
2016-12-03 18:57:26 +00:00
|
|
|
// func (obj *MyAwesomeAPIObject) SetGroupVersionKind(gvk *metav1.GroupVersionKind) { metav1.UpdateTypeMeta(obj,gvk) }; GroupVersionKind() *GroupVersionKind
|
2014-08-29 22:48:41 +00:00
|
|
|
//
|
2014-10-07 15:12:16 +00:00
|
|
|
// TypeMeta is provided here for convenience. You may use it directly from this package or define
|
2014-08-29 22:48:41 +00:00
|
|
|
// your own with the same fields.
|
|
|
|
//
|
2016-06-16 06:43:13 +00:00
|
|
|
// +k8s:deepcopy-gen=true
|
2015-11-26 23:45:43 +00:00
|
|
|
// +protobuf=true
|
2016-08-25 21:58:23 +00:00
|
|
|
// +k8s:openapi-gen=true
|
2014-10-07 15:12:16 +00:00
|
|
|
type TypeMeta struct {
|
2016-10-14 22:37:37 +00:00
|
|
|
// +optional
|
2016-04-16 05:02:27 +00:00
|
|
|
APIVersion string `json:"apiVersion,omitempty" yaml:"apiVersion,omitempty" protobuf:"bytes,1,opt,name=apiVersion"`
|
2016-10-14 22:37:37 +00:00
|
|
|
// +optional
|
|
|
|
Kind string `json:"kind,omitempty" yaml:"kind,omitempty" protobuf:"bytes,2,opt,name=kind"`
|
2014-08-29 22:48:41 +00:00
|
|
|
}
|
|
|
|
|
2016-03-17 10:32:14 +00:00
|
|
|
const (
|
|
|
|
ContentTypeJSON string = "application/json"
|
|
|
|
)
|
|
|
|
|
2015-12-21 05:08:33 +00:00
|
|
|
// RawExtension is used to hold extensions in external versions.
|
2014-09-11 00:28:07 +00:00
|
|
|
//
|
|
|
|
// To use this, make a field which has RawExtension as its type in your external, versioned
|
2015-12-21 05:08:33 +00:00
|
|
|
// struct, and Object in your internal struct. You also need to register your
|
2014-09-11 00:28:07 +00:00
|
|
|
// various plugin types.
|
|
|
|
//
|
|
|
|
// // Internal package:
|
|
|
|
// type MyAPIObject struct {
|
2014-12-01 05:31:52 +00:00
|
|
|
// runtime.TypeMeta `json:",inline"`
|
2015-12-21 05:08:33 +00:00
|
|
|
// MyPlugin runtime.Object `json:"myPlugin"`
|
2014-09-11 00:28:07 +00:00
|
|
|
// }
|
|
|
|
// type PluginA struct {
|
2014-12-01 05:31:52 +00:00
|
|
|
// AOption string `json:"aOption"`
|
2014-09-11 00:28:07 +00:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// // External package:
|
|
|
|
// type MyAPIObject struct {
|
2014-12-01 05:31:52 +00:00
|
|
|
// runtime.TypeMeta `json:",inline"`
|
|
|
|
// MyPlugin runtime.RawExtension `json:"myPlugin"`
|
2014-09-11 00:28:07 +00:00
|
|
|
// }
|
|
|
|
// type PluginA struct {
|
2014-12-01 05:31:52 +00:00
|
|
|
// AOption string `json:"aOption"`
|
2014-09-11 00:28:07 +00:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// // On the wire, the JSON will look something like this:
|
|
|
|
// {
|
|
|
|
// "kind":"MyAPIObject",
|
2015-11-05 10:48:03 +00:00
|
|
|
// "apiVersion":"v1",
|
2014-09-11 00:28:07 +00:00
|
|
|
// "myPlugin": {
|
|
|
|
// "kind":"PluginA",
|
|
|
|
// "aOption":"foo",
|
|
|
|
// },
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// So what happens? Decode first uses json or yaml to unmarshal the serialized data into
|
|
|
|
// your external MyAPIObject. That causes the raw JSON to be stored, but not unpacked.
|
|
|
|
// The next step is to copy (using pkg/conversion) into the internal struct. The runtime
|
|
|
|
// package's DefaultScheme has conversion functions installed which will unpack the
|
|
|
|
// JSON stored in RawExtension, turning it into the correct object type, and storing it
|
2015-12-21 05:08:33 +00:00
|
|
|
// in the Object. (TODO: In the case where the object is of an unknown type, a
|
2014-09-11 00:28:07 +00:00
|
|
|
// runtime.Unknown object will be created and stored.)
|
2015-11-26 23:45:43 +00:00
|
|
|
//
|
2016-06-16 06:43:13 +00:00
|
|
|
// +k8s:deepcopy-gen=true
|
2015-11-26 23:45:43 +00:00
|
|
|
// +protobuf=true
|
2016-08-25 21:58:23 +00:00
|
|
|
// +k8s:openapi-gen=true
|
2014-09-11 00:28:07 +00:00
|
|
|
type RawExtension struct {
|
2016-03-17 10:32:14 +00:00
|
|
|
// Raw is the underlying serialization of this object.
|
|
|
|
//
|
|
|
|
// TODO: Determine how to detect ContentType and ContentEncoding of 'Raw' data.
|
2016-04-16 05:02:27 +00:00
|
|
|
Raw []byte `protobuf:"bytes,1,opt,name=raw"`
|
2015-12-21 05:08:33 +00:00
|
|
|
// Object can hold a representation of this extension - useful for working with versioned
|
|
|
|
// structs.
|
|
|
|
Object Object `json:"-"`
|
2014-09-11 00:28:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Unknown allows api objects with unknown types to be passed-through. This can be used
|
|
|
|
// to deal with the API objects from a plug-in. Unknown objects still have functioning
|
2015-01-27 23:56:38 +00:00
|
|
|
// TypeMeta features-- kind, version, etc.
|
|
|
|
// TODO: Make this object have easy access to field based accessors and settors for
|
|
|
|
// metadata and field mutatation.
|
2015-11-26 23:45:43 +00:00
|
|
|
//
|
2016-06-16 06:43:13 +00:00
|
|
|
// +k8s:deepcopy-gen=true
|
2015-11-26 23:45:43 +00:00
|
|
|
// +protobuf=true
|
2016-08-25 21:58:23 +00:00
|
|
|
// +k8s:openapi-gen=true
|
2014-09-11 00:28:07 +00:00
|
|
|
type Unknown struct {
|
2016-04-16 05:02:27 +00:00
|
|
|
TypeMeta `json:",inline" protobuf:"bytes,1,opt,name=typeMeta"`
|
2016-03-16 08:03:33 +00:00
|
|
|
// Raw will hold the complete serialized object which couldn't be matched
|
2014-09-11 00:28:07 +00:00
|
|
|
// with a registered type. Most likely, nothing should be done with this
|
|
|
|
// except for passing it through the system.
|
2016-04-16 05:02:27 +00:00
|
|
|
Raw []byte `protobuf:"bytes,2,opt,name=raw"`
|
2016-03-16 08:03:33 +00:00
|
|
|
// ContentEncoding is encoding used to encode 'Raw' data.
|
2016-03-17 10:32:14 +00:00
|
|
|
// Unspecified means no encoding.
|
2016-04-16 05:02:27 +00:00
|
|
|
ContentEncoding string `protobuf:"bytes,3,opt,name=contentEncoding"`
|
2016-03-16 08:03:33 +00:00
|
|
|
// ContentType is serialization method used to serialize 'Raw'.
|
2016-03-17 10:32:14 +00:00
|
|
|
// Unspecified means ContentTypeJSON.
|
2016-04-16 05:02:27 +00:00
|
|
|
ContentType string `protobuf:"bytes,4,opt,name=contentType"`
|
2014-08-29 22:48:41 +00:00
|
|
|
}
|
2014-09-05 23:11:30 +00:00
|
|
|
|
2015-12-21 05:08:33 +00:00
|
|
|
// VersionedObjects is used by Decoders to give callers a way to access all versions
|
|
|
|
// of an object during the decoding process.
|
|
|
|
type VersionedObjects struct {
|
|
|
|
// Objects is the set of objects retrieved during decoding, in order of conversion.
|
2016-02-12 19:33:32 +00:00
|
|
|
// The 0 index is the object as serialized on the wire. If conversion has occurred,
|
2015-12-21 05:08:33 +00:00
|
|
|
// other objects may be present. The right most object is the same as would be returned
|
|
|
|
// by a normal Decode call.
|
|
|
|
Objects []Object
|
|
|
|
}
|