2 Copyright 2015 The Kubernetes Authors.
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
8 http://www.apache.org/licenses/LICENSE-2.0
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.
24 "k8s.io/apimachinery/pkg/runtime/schema"
27 // GroupResource specifies a Group and a Resource, but does not force a version. This is useful for identifying
28 // concepts during lookup stages without having partially valid types
30 // +protobuf.options.(gogoproto.goproto_stringer)=false
31 type GroupResource struct {
32 Group string `json:"group" protobuf:"bytes,1,opt,name=group"`
33 Resource string `json:"resource" protobuf:"bytes,2,opt,name=resource"`
36 func (gr *GroupResource) String() string {
37 if len(gr.Group) == 0 {
40 return gr.Resource + "." + gr.Group
43 // GroupVersionResource unambiguously identifies a resource. It doesn't anonymously include GroupVersion
44 // to avoid automatic coersion. It doesn't use a GroupVersion to avoid custom marshalling
46 // +protobuf.options.(gogoproto.goproto_stringer)=false
47 type GroupVersionResource struct {
48 Group string `json:"group" protobuf:"bytes,1,opt,name=group"`
49 Version string `json:"version" protobuf:"bytes,2,opt,name=version"`
50 Resource string `json:"resource" protobuf:"bytes,3,opt,name=resource"`
53 func (gvr *GroupVersionResource) String() string {
54 return strings.Join([]string{gvr.Group, "/", gvr.Version, ", Resource=", gvr.Resource}, "")
57 // GroupKind specifies a Group and a Kind, but does not force a version. This is useful for identifying
58 // concepts during lookup stages without having partially valid types
60 // +protobuf.options.(gogoproto.goproto_stringer)=false
61 type GroupKind struct {
62 Group string `json:"group" protobuf:"bytes,1,opt,name=group"`
63 Kind string `json:"kind" protobuf:"bytes,2,opt,name=kind"`
66 func (gk *GroupKind) String() string {
67 if len(gk.Group) == 0 {
70 return gk.Kind + "." + gk.Group
73 // GroupVersionKind unambiguously identifies a kind. It doesn't anonymously include GroupVersion
74 // to avoid automatic coersion. It doesn't use a GroupVersion to avoid custom marshalling
76 // +protobuf.options.(gogoproto.goproto_stringer)=false
77 type GroupVersionKind struct {
78 Group string `json:"group" protobuf:"bytes,1,opt,name=group"`
79 Version string `json:"version" protobuf:"bytes,2,opt,name=version"`
80 Kind string `json:"kind" protobuf:"bytes,3,opt,name=kind"`
83 func (gvk GroupVersionKind) String() string {
84 return gvk.Group + "/" + gvk.Version + ", Kind=" + gvk.Kind
87 // GroupVersion contains the "group" and the "version", which uniquely identifies the API.
89 // +protobuf.options.(gogoproto.goproto_stringer)=false
90 type GroupVersion struct {
91 Group string `json:"group" protobuf:"bytes,1,opt,name=group"`
92 Version string `json:"version" protobuf:"bytes,2,opt,name=version"`
95 // Empty returns true if group and version are empty
96 func (gv GroupVersion) Empty() bool {
97 return len(gv.Group) == 0 && len(gv.Version) == 0
100 // String puts "group" and "version" into a single "group/version" string. For the legacy v1
102 func (gv GroupVersion) String() string {
103 // special case the internal apiVersion for the legacy kube types
108 // special case of "v1" for backward compatibility
109 if len(gv.Group) == 0 && gv.Version == "v1" {
112 if len(gv.Group) > 0 {
113 return gv.Group + "/" + gv.Version
118 // MarshalJSON implements the json.Marshaller interface.
119 func (gv GroupVersion) MarshalJSON() ([]byte, error) {
121 if strings.Count(s, "/") > 1 {
122 return []byte{}, fmt.Errorf("illegal GroupVersion %v: contains more than one /", s)
124 return json.Marshal(s)
127 func (gv *GroupVersion) unmarshal(value []byte) error {
129 if err := json.Unmarshal(value, &s); err != nil {
132 parsed, err := schema.ParseGroupVersion(s)
136 gv.Group, gv.Version = parsed.Group, parsed.Version
140 // UnmarshalJSON implements the json.Unmarshaller interface.
141 func (gv *GroupVersion) UnmarshalJSON(value []byte) error {
142 return gv.unmarshal(value)
145 // UnmarshalTEXT implements the Ugorji's encoding.TextUnmarshaler interface.
146 func (gv *GroupVersion) UnmarshalText(value []byte) error {
147 return gv.unmarshal(value)