github.com/timstclair/heapster@v0.20.0-alpha1/Godeps/_workspace/src/k8s.io/kubernetes/pkg/runtime/types.go (about) 1 /* 2 Copyright 2014 The Kubernetes Authors All rights reserved. 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 // type MyAwesomeAPIObject struct { 25 // runtime.TypeMeta `json:",inline"` 26 // ... // other fields 27 // } 28 // func (*MyAwesomeAPIObject) IsAnAPIObject() {} 29 // 30 // TypeMeta is provided here for convenience. You may use it directly from this package or define 31 // your own with the same fields. 32 // 33 type TypeMeta struct { 34 APIVersion string `json:"apiVersion,omitempty" yaml:"apiVersion,omitempty"` 35 Kind string `json:"kind,omitempty" yaml:"kind,omitempty"` 36 } 37 38 // PluginBase is like TypeMeta, but it's intended for plugin objects that won't ever be encoded 39 // except while embedded in other objects. 40 type PluginBase struct { 41 Kind string `json:"kind,omitempty"` 42 } 43 44 // EmbeddedObject has appropriate encoder and decoder functions, such that on the wire, it's 45 // stored as a []byte, but in memory, the contained object is accessible as an Object 46 // via the Get() function. Only valid API objects may be stored via EmbeddedObject. 47 // The purpose of this is to allow an API object of type known only at runtime to be 48 // embedded within other API objects. 49 // 50 // Note that object assumes that you've registered all of your api types with the api package. 51 // 52 // EmbeddedObject and RawExtension can be used together to allow for API object extensions: 53 // see the comment for RawExtension. 54 type EmbeddedObject struct { 55 Object 56 } 57 58 // RawExtension is used with EmbeddedObject to do a two-phase encoding of extension objects. 59 // 60 // To use this, make a field which has RawExtension as its type in your external, versioned 61 // struct, and EmbeddedObject in your internal struct. You also need to register your 62 // various plugin types. 63 // 64 // // Internal package: 65 // type MyAPIObject struct { 66 // runtime.TypeMeta `json:",inline"` 67 // MyPlugin runtime.EmbeddedObject `json:"myPlugin"` 68 // } 69 // type PluginA struct { 70 // runtime.PluginBase `json:",inline"` 71 // AOption string `json:"aOption"` 72 // } 73 // 74 // // External package: 75 // type MyAPIObject struct { 76 // runtime.TypeMeta `json:",inline"` 77 // MyPlugin runtime.RawExtension `json:"myPlugin"` 78 // } 79 // type PluginA struct { 80 // runtime.PluginBase `json:",inline"` 81 // AOption string `json:"aOption"` 82 // } 83 // 84 // // On the wire, the JSON will look something like this: 85 // { 86 // "kind":"MyAPIObject", 87 // "apiVersion":"v1", 88 // "myPlugin": { 89 // "kind":"PluginA", 90 // "aOption":"foo", 91 // }, 92 // } 93 // 94 // So what happens? Decode first uses json or yaml to unmarshal the serialized data into 95 // your external MyAPIObject. That causes the raw JSON to be stored, but not unpacked. 96 // The next step is to copy (using pkg/conversion) into the internal struct. The runtime 97 // package's DefaultScheme has conversion functions installed which will unpack the 98 // JSON stored in RawExtension, turning it into the correct object type, and storing it 99 // in the EmbeddedObject. (TODO: In the case where the object is of an unknown type, a 100 // runtime.Unknown object will be created and stored.) 101 type RawExtension struct { 102 RawJSON []byte 103 } 104 105 // Unknown allows api objects with unknown types to be passed-through. This can be used 106 // to deal with the API objects from a plug-in. Unknown objects still have functioning 107 // TypeMeta features-- kind, version, etc. 108 // TODO: Make this object have easy access to field based accessors and settors for 109 // metadata and field mutatation. 110 type Unknown struct { 111 TypeMeta `json:",inline"` 112 // RawJSON will hold the complete JSON of the object which couldn't be matched 113 // with a registered type. Most likely, nothing should be done with this 114 // except for passing it through the system. 115 RawJSON []byte 116 } 117 118 func (*Unknown) IsAnAPIObject() {} 119 120 // Unstructured allows objects that do not have Golang structs registered to be manipulated 121 // generically. This can be used to deal with the API objects from a plug-in. Unstructured 122 // objects still have functioning TypeMeta features-- kind, version, etc. 123 // TODO: Make this object have easy access to field based accessors and settors for 124 // metadata and field mutatation. 125 type Unstructured struct { 126 TypeMeta `json:",inline"` 127 // Object is a JSON compatible map with string, float, int, []interface{}, or map[string]interface{} 128 // children. 129 Object map[string]interface{} 130 } 131 132 func (*Unstructured) IsAnAPIObject() {}