blob: 3d3ebe5f9d1b44c60ad4a161c19a62c276910890 [file] [log] [blame]
Zack Williamse940c7a2019-08-21 14:25:39 -07001/*
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 (
David Bainbridge86971522019-09-26 22:09:39 +000044 ContentTypeJSON string = "application/json"
45 ContentTypeYAML string = "application/yaml"
46 ContentTypeProtobuf string = "application/vnd.kubernetes.protobuf"
Zack Williamse940c7a2019-08-21 14:25:39 -070047)
48
49// RawExtension is used to hold extensions in external versions.
50//
51// To use this, make a field which has RawExtension as its type in your external, versioned
52// struct, and Object in your internal struct. You also need to register your
53// various plugin types.
54//
55// // Internal package:
56// type MyAPIObject struct {
57// runtime.TypeMeta `json:",inline"`
58// MyPlugin runtime.Object `json:"myPlugin"`
59// }
60// type PluginA struct {
61// AOption string `json:"aOption"`
62// }
63//
64// // External package:
65// type MyAPIObject struct {
66// runtime.TypeMeta `json:",inline"`
67// MyPlugin runtime.RawExtension `json:"myPlugin"`
68// }
69// type PluginA struct {
70// AOption string `json:"aOption"`
71// }
72//
73// // On the wire, the JSON will look something like this:
74// {
75// "kind":"MyAPIObject",
76// "apiVersion":"v1",
77// "myPlugin": {
78// "kind":"PluginA",
79// "aOption":"foo",
80// },
81// }
82//
83// So what happens? Decode first uses json or yaml to unmarshal the serialized data into
84// your external MyAPIObject. That causes the raw JSON to be stored, but not unpacked.
85// The next step is to copy (using pkg/conversion) into the internal struct. The runtime
86// package's DefaultScheme has conversion functions installed which will unpack the
87// JSON stored in RawExtension, turning it into the correct object type, and storing it
88// in the Object. (TODO: In the case where the object is of an unknown type, a
89// runtime.Unknown object will be created and stored.)
90//
91// +k8s:deepcopy-gen=true
92// +protobuf=true
93// +k8s:openapi-gen=true
94type RawExtension struct {
95 // Raw is the underlying serialization of this object.
96 //
97 // TODO: Determine how to detect ContentType and ContentEncoding of 'Raw' data.
98 Raw []byte `protobuf:"bytes,1,opt,name=raw"`
99 // Object can hold a representation of this extension - useful for working with versioned
100 // structs.
101 Object Object `json:"-"`
102}
103
104// Unknown allows api objects with unknown types to be passed-through. This can be used
105// to deal with the API objects from a plug-in. Unknown objects still have functioning
106// TypeMeta features-- kind, version, etc.
107// TODO: Make this object have easy access to field based accessors and settors for
108// metadata and field mutatation.
109//
110// +k8s:deepcopy-gen=true
111// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
112// +protobuf=true
113// +k8s:openapi-gen=true
114type Unknown struct {
115 TypeMeta `json:",inline" protobuf:"bytes,1,opt,name=typeMeta"`
116 // Raw will hold the complete serialized object which couldn't be matched
117 // with a registered type. Most likely, nothing should be done with this
118 // except for passing it through the system.
119 Raw []byte `protobuf:"bytes,2,opt,name=raw"`
120 // ContentEncoding is encoding used to encode 'Raw' data.
121 // Unspecified means no encoding.
122 ContentEncoding string `protobuf:"bytes,3,opt,name=contentEncoding"`
123 // ContentType is serialization method used to serialize 'Raw'.
124 // Unspecified means ContentTypeJSON.
125 ContentType string `protobuf:"bytes,4,opt,name=contentType"`
126}
127
128// VersionedObjects is used by Decoders to give callers a way to access all versions
129// of an object during the decoding process.
130//
131// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
132// +k8s:deepcopy-gen=true
133type VersionedObjects struct {
134 // Objects is the set of objects retrieved during decoding, in order of conversion.
135 // The 0 index is the object as serialized on the wire. If conversion has occurred,
136 // other objects may be present. The right most object is the same as would be returned
137 // by a normal Decode call.
138 Objects []Object
139}