github.com/spotmaxtech/k8s-apimachinery-v0260@v0.0.1/pkg/runtime/types.go (about) 1 /* 2 Copyright 2014 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package runtime 18 19 // Note that the types provided in this file are not versioned and are intended to be 20 // safe to use from within all versions of every API object. 21 22 // TypeMeta is shared by all top level objects. The proper way to use it is to inline it in your type, 23 // like this: 24 // 25 // type MyAwesomeAPIObject struct { 26 // runtime.TypeMeta `json:",inline"` 27 // ... // other fields 28 // } 29 // 30 // func (obj *MyAwesomeAPIObject) SetGroupVersionKind(gvk *metav1.GroupVersionKind) { metav1.UpdateTypeMeta(obj,gvk) }; GroupVersionKind() *GroupVersionKind 31 // 32 // TypeMeta is provided here for convenience. You may use it directly from this package or define 33 // your own with the same fields. 34 // 35 // +k8s:deepcopy-gen=false 36 // +protobuf=true 37 // +k8s:openapi-gen=true 38 type TypeMeta struct { 39 // +optional 40 APIVersion string `json:"apiVersion,omitempty" yaml:"apiVersion,omitempty" protobuf:"bytes,1,opt,name=apiVersion"` 41 // +optional 42 Kind string `json:"kind,omitempty" yaml:"kind,omitempty" protobuf:"bytes,2,opt,name=kind"` 43 } 44 45 const ( 46 ContentTypeJSON string = "application/json" 47 ContentTypeYAML string = "application/yaml" 48 ContentTypeProtobuf string = "application/vnd.kubernetes.protobuf" 49 ) 50 51 // RawExtension is used to hold extensions in external versions. 52 // 53 // To use this, make a field which has RawExtension as its type in your external, versioned 54 // struct, and Object in your internal struct. You also need to register your 55 // various plugin types. 56 // 57 // // Internal package: 58 // 59 // type MyAPIObject struct { 60 // runtime.TypeMeta `json:",inline"` 61 // MyPlugin runtime.Object `json:"myPlugin"` 62 // } 63 // 64 // type PluginA struct { 65 // AOption string `json:"aOption"` 66 // } 67 // 68 // // External package: 69 // 70 // type MyAPIObject struct { 71 // runtime.TypeMeta `json:",inline"` 72 // MyPlugin runtime.RawExtension `json:"myPlugin"` 73 // } 74 // 75 // type PluginA struct { 76 // AOption string `json:"aOption"` 77 // } 78 // 79 // // On the wire, the JSON will look something like this: 80 // 81 // { 82 // "kind":"MyAPIObject", 83 // "apiVersion":"v1", 84 // "myPlugin": { 85 // "kind":"PluginA", 86 // "aOption":"foo", 87 // }, 88 // } 89 // 90 // So what happens? Decode first uses json or yaml to unmarshal the serialized data into 91 // your external MyAPIObject. That causes the raw JSON to be stored, but not unpacked. 92 // The next step is to copy (using pkg/conversion) into the internal struct. The runtime 93 // package's DefaultScheme has conversion functions installed which will unpack the 94 // JSON stored in RawExtension, turning it into the correct object type, and storing it 95 // in the Object. (TODO: In the case where the object is of an unknown type, a 96 // runtime.Unknown object will be created and stored.) 97 // 98 // +k8s:deepcopy-gen=true 99 // +protobuf=true 100 // +k8s:openapi-gen=true 101 type RawExtension struct { 102 // Raw is the underlying serialization of this object. 103 // 104 // TODO: Determine how to detect ContentType and ContentEncoding of 'Raw' data. 105 Raw []byte `json:"-" protobuf:"bytes,1,opt,name=raw"` 106 // Object can hold a representation of this extension - useful for working with versioned 107 // structs. 108 Object Object `json:"-"` 109 } 110 111 // Unknown allows api objects with unknown types to be passed-through. This can be used 112 // to deal with the API objects from a plug-in. Unknown objects still have functioning 113 // TypeMeta features-- kind, version, etc. 114 // TODO: Make this object have easy access to field based accessors and settors for 115 // metadata and field mutatation. 116 // 117 // +k8s:deepcopy-gen=true 118 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 119 // +protobuf=true 120 // +k8s:openapi-gen=true 121 type Unknown struct { 122 TypeMeta `json:",inline" protobuf:"bytes,1,opt,name=typeMeta"` 123 // Raw will hold the complete serialized object which couldn't be matched 124 // with a registered type. Most likely, nothing should be done with this 125 // except for passing it through the system. 126 Raw []byte `protobuf:"bytes,2,opt,name=raw"` 127 // ContentEncoding is encoding used to encode 'Raw' data. 128 // Unspecified means no encoding. 129 ContentEncoding string `protobuf:"bytes,3,opt,name=contentEncoding"` 130 // ContentType is serialization method used to serialize 'Raw'. 131 // Unspecified means ContentTypeJSON. 132 ContentType string `protobuf:"bytes,4,opt,name=contentType"` 133 }