blob: eb284eac279029aa3afd747967b2ddbb7432cdde [file] [log] [blame]
sslobodrd046be82019-01-16 10:02:22 -05001/*
2Copyright 2014 The Kubernetes Authors.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17package 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 (obj *MyAwesomeAPIObject) SetGroupVersionKind(gvk *metav1.GroupVersionKind) { metav1.UpdateTypeMeta(obj,gvk) }; GroupVersionKind() *GroupVersionKind
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// +k8s:deepcopy-gen=false
34// +protobuf=true
35// +k8s:openapi-gen=true
36type TypeMeta struct {
37 // +optional
38 APIVersion string `json:"apiVersion,omitempty" yaml:"apiVersion,omitempty" protobuf:"bytes,1,opt,name=apiVersion"`
39 // +optional
40 Kind string `json:"kind,omitempty" yaml:"kind,omitempty" protobuf:"bytes,2,opt,name=kind"`
41}
42
43const (
44 ContentTypeJSON string = "application/json"
Stephane Barbarie260a5632019-02-26 16:12:49 -050045 ContentTypeYAML string = "application/yaml"
William Kurkiandaa6bb22019-03-07 12:26:28 -050046
47 ContentTypeProtobuf string = "application/vnd.kubernetes.protobuf"
sslobodrd046be82019-01-16 10:02:22 -050048)
49
50// RawExtension is used to hold extensions in external versions.
51//
52// To use this, make a field which has RawExtension as its type in your external, versioned
53// struct, and Object in your internal struct. You also need to register your
54// various plugin types.
55//
56// // Internal package:
57// type MyAPIObject struct {
58// runtime.TypeMeta `json:",inline"`
59// MyPlugin runtime.Object `json:"myPlugin"`
60// }
61// type PluginA struct {
62// AOption string `json:"aOption"`
63// }
64//
65// // External package:
66// type MyAPIObject struct {
67// runtime.TypeMeta `json:",inline"`
68// MyPlugin runtime.RawExtension `json:"myPlugin"`
69// }
70// type PluginA struct {
71// AOption string `json:"aOption"`
72// }
73//
74// // On the wire, the JSON will look something like this:
75// {
76// "kind":"MyAPIObject",
77// "apiVersion":"v1",
78// "myPlugin": {
79// "kind":"PluginA",
80// "aOption":"foo",
81// },
82// }
83//
84// So what happens? Decode first uses json or yaml to unmarshal the serialized data into
85// your external MyAPIObject. That causes the raw JSON to be stored, but not unpacked.
86// The next step is to copy (using pkg/conversion) into the internal struct. The runtime
87// package's DefaultScheme has conversion functions installed which will unpack the
88// JSON stored in RawExtension, turning it into the correct object type, and storing it
89// in the Object. (TODO: In the case where the object is of an unknown type, a
90// runtime.Unknown object will be created and stored.)
91//
92// +k8s:deepcopy-gen=true
93// +protobuf=true
94// +k8s:openapi-gen=true
95type RawExtension struct {
96 // Raw is the underlying serialization of this object.
97 //
98 // TODO: Determine how to detect ContentType and ContentEncoding of 'Raw' data.
99 Raw []byte `protobuf:"bytes,1,opt,name=raw"`
100 // Object can hold a representation of this extension - useful for working with versioned
101 // structs.
102 Object Object `json:"-"`
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//
111// +k8s:deepcopy-gen=true
112// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
113// +protobuf=true
114// +k8s:openapi-gen=true
115type Unknown struct {
116 TypeMeta `json:",inline" protobuf:"bytes,1,opt,name=typeMeta"`
117 // Raw will hold the complete serialized object which couldn't be matched
118 // with a registered type. Most likely, nothing should be done with this
119 // except for passing it through the system.
120 Raw []byte `protobuf:"bytes,2,opt,name=raw"`
121 // ContentEncoding is encoding used to encode 'Raw' data.
122 // Unspecified means no encoding.
123 ContentEncoding string `protobuf:"bytes,3,opt,name=contentEncoding"`
124 // ContentType is serialization method used to serialize 'Raw'.
125 // Unspecified means ContentTypeJSON.
126 ContentType string `protobuf:"bytes,4,opt,name=contentType"`
127}
128
129// VersionedObjects is used by Decoders to give callers a way to access all versions
130// of an object during the decoding process.
131//
132// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
133// +k8s:deepcopy-gen=true
134type VersionedObjects struct {
135 // Objects is the set of objects retrieved during decoding, in order of conversion.
136 // The 0 index is the object as serialized on the wire. If conversion has occurred,
137 // other objects may be present. The right most object is the same as would be returned
138 // by a normal Decode call.
139 Objects []Object
140}