@@ -19,7 +19,6 @@ package parse
19
19
import (
20
20
"fmt"
21
21
"log"
22
- "path/filepath"
23
22
"strings"
24
23
25
24
"github.com/kubernetes-sigs/kubebuilder/cmd/internal/codegen"
@@ -71,8 +70,9 @@ func (b *APIs) parseIndex() {
71
70
72
71
rt := parseResourceTag (b .getResourceTag (c ))
73
72
r .Resource = rt .Resource
74
- r .REST = rt .REST
75
- r .Strategy = rt .Strategy
73
+ r .ShortName = rt .ShortName
74
+ //r.REST = rt.REST
75
+ //r.Strategy = rt.Strategy
76
76
77
77
// Copy the Status strategy to mirror the non-status strategy
78
78
r .StatusStrategy = strings .TrimSuffix (r .Strategy , "Strategy" )
@@ -96,85 +96,86 @@ func (b *APIs) parseIndex() {
96
96
b.ByGroupKindVersion [r.Group ][r.Kind ][r .Version ] = r
97
97
b.ByGroupVersionKind [r.Group ][r.Version ][r .Kind ] = r
98
98
99
- if ! HasSubresource (c ) {
100
- continue
101
- }
99
+ // if !HasSubresource(c) {
100
+ // continue
101
+ // }
102
102
r .Type = c
103
- r .Subresources = b .getSubresources (r )
103
+ // r.Subresources = b.getSubresources(r)
104
104
}
105
105
}
106
106
107
- func (b * APIs ) getSubresources (c * codegen.APIResource ) map [string ]* codegen.APISubresource {
108
- r := map [string ]* codegen.APISubresource {}
109
- subresources := b .getSubresourceTags (c .Type )
110
-
111
- if len (subresources ) == 0 {
112
- // Not a subresource
113
- return r
114
- }
115
- for _ , subresource := range subresources {
116
- // Parse the values for each subresource
117
- tags := parseSubresourceTag (c , subresource )
118
- sr := & codegen.APISubresource {
119
- Kind : tags .Kind ,
120
- Request : tags .RequestKind ,
121
- Path : tags .Path ,
122
- REST : tags .REST ,
123
- Domain : b .Domain ,
124
- Version : c .Version ,
125
- Resource : c .Resource ,
126
- Group : c .Group ,
127
- }
128
- if ! b .isInPackage (tags ) {
129
- // Out of package Request types require an import and are prefixed with the
130
- // package name - e.g. v1.Scale
131
- sr .Request , sr .ImportPackage = b .getNameAndImport (tags )
132
- }
133
- if v , found := r [sr .Path ]; found {
134
- log .Fatalf ("Multiple subresources registered for path %s: %v %v" ,
135
- sr .Path , v , subresource )
136
- }
137
- r [sr .Path ] = sr
138
- }
139
- return r
140
- }
107
+ // func (b *APIs) getSubresources(c *codegen.APIResource) map[string]*codegen.APISubresource {
108
+ // r := map[string]*codegen.APISubresource{}
109
+ // subresources := b.getSubresourceTags(c.Type)
110
+ //
111
+ // if len(subresources) == 0 {
112
+ // // Not a subresource
113
+ // return r
114
+ // }
115
+ // for _, subresource := range subresources {
116
+ // // Parse the values for each subresource
117
+ // tags := parseSubresourceTag(c, subresource)
118
+ // sr := &codegen.APISubresource{
119
+ // Kind: tags.Kind,
120
+ // Request: tags.RequestKind,
121
+ // Path: tags.Path,
122
+ // REST: tags.REST,
123
+ // Domain: b.Domain,
124
+ // Version: c.Version,
125
+ // Resource: c.Resource,
126
+ // Group: c.Group,
127
+ // }
128
+ // if !b.isInPackage(tags) {
129
+ // // Out of package Request types require an import and are prefixed with the
130
+ // // package name - e.g. v1.Scale
131
+ // sr.Request, sr.ImportPackage = b.getNameAndImport(tags)
132
+ // }
133
+ // if v, found := r[sr.Path]; found {
134
+ // log.Fatalf("Multiple subresources registered for path %s: %v %v",
135
+ // sr.Path, v, subresource)
136
+ // }
137
+ // r[sr.Path] = sr
138
+ // }
139
+ // return r
140
+ // }
141
141
142
142
// subresourceTags contains the tags present in a "+subresource=" comment
143
- type subresourceTags struct {
144
- Path string
145
- Kind string
146
- RequestKind string
147
- REST string
148
- }
149
-
150
- func (b * APIs ) getSubresourceTags (c * types.Type ) []string {
151
- comments := Comments (c .CommentLines )
152
- return comments .getTags ("subresource" , ":" )
153
- }
143
+ // type subresourceTags struct {
144
+ // Path string
145
+ // Kind string
146
+ // RequestKind string
147
+ // REST string
148
+ // }
149
+ //
150
+ // func (b *APIs) getSubresourceTags(c *types.Type) []string {
151
+ // comments := Comments(c.CommentLines)
152
+ // return comments.getTags("subresource", ":")
153
+ // }
154
154
155
155
// Returns true if the subresource Request type is in the same package as the resource type
156
- func (b * APIs ) isInPackage (tags subresourceTags ) bool {
157
- return ! strings .Contains (tags .RequestKind , "." )
158
- }
159
-
160
- // GetNameAndImport converts
161
- func (b * APIs ) getNameAndImport (tags subresourceTags ) (string , string ) {
162
- last := strings .LastIndex (tags .RequestKind , "." )
163
- importPackage := tags .RequestKind [:last ]
164
-
165
- // Set the request kind to the struct name
166
- tags .RequestKind = tags .RequestKind [last + 1 :]
167
- // Find the package
168
- pkg := filepath .Base (importPackage )
169
- // Prefix the struct name with the package it is in
170
- return strings .Join ([]string {pkg , tags .RequestKind }, "." ), importPackage
171
- }
156
+ // func (b *APIs) isInPackage(tags subresourceTags) bool {
157
+ // return !strings.Contains(tags.RequestKind, ".")
158
+ // }
159
+ //
160
+ //// GetNameAndImport converts
161
+ // func (b *APIs) getNameAndImport(tags subresourceTags) (string, string) {
162
+ // last := strings.LastIndex(tags.RequestKind, ".")
163
+ // importPackage := tags.RequestKind[:last]
164
+ //
165
+ // // Set the request kind to the struct name
166
+ // tags.RequestKind = tags.RequestKind[last+1:]
167
+ // // Find the package
168
+ // pkg := filepath.Base(importPackage)
169
+ // // Prefix the struct name with the package it is in
170
+ // return strings.Join([]string{pkg, tags.RequestKind}, "."), importPackage
171
+ // }
172
172
173
173
// resourceTags contains the tags present in a "+resource=" comment
174
174
type resourceTags struct {
175
- Resource string
176
- REST string
177
- Strategy string
175
+ Resource string
176
+ REST string
177
+ Strategy string
178
+ ShortName string
178
179
}
179
180
180
181
// ParseResourceTag parses the tags in a "+resource=" comment into a resourceTags struct
@@ -189,40 +190,42 @@ func parseResourceTag(tag string) resourceTags {
189
190
}
190
191
value := kv [1 ]
191
192
switch kv [0 ] {
192
- case "rest" :
193
- result .REST = value
193
+ // case "rest":
194
+ // result.REST = value
194
195
case "path" :
195
196
result .Resource = value
196
- case "strategy" :
197
- result .Strategy = value
197
+ //case "strategy":
198
+ // result.Strategy = value
199
+ case "shortName" :
200
+ result .ShortName = value
198
201
}
199
202
}
200
203
return result
201
204
}
202
205
203
206
// ParseSubresourceTag parses the tags in a "+subresource=" comment into a subresourceTags struct
204
- func parseSubresourceTag (c * codegen.APIResource , tag string ) subresourceTags {
205
- result := subresourceTags {}
206
- for _ , elem := range strings .Split (tag , "," ) {
207
- kv := strings .Split (elem , "=" )
208
- if len (kv ) != 2 {
209
- log .Fatalf ("// +subresource: tags must be key value pairs. Expected " +
210
- "keys [request=<requestType>,rest=<restImplType>,path=<subresourcepath>] " +
211
- "Got string: [%s]" , tag )
212
- }
213
- value := kv [1 ]
214
- switch kv [0 ] {
215
- case "request" :
216
- result .RequestKind = value
217
- case "rest" :
218
- result .REST = value
219
- case "path" :
220
- // Strip the parent resource
221
- result .Path = strings .Replace (value , c .Resource + "/" , "" , - 1 )
222
- }
223
- }
224
- return result
225
- }
207
+ // func parseSubresourceTag(c *codegen.APIResource, tag string) subresourceTags {
208
+ // result := subresourceTags{}
209
+ // for _, elem := range strings.Split(tag, ",") {
210
+ // kv := strings.Split(elem, "=")
211
+ // if len(kv) != 2 {
212
+ // log.Fatalf("// +subresource: tags must be key value pairs. Expected "+
213
+ // "keys [request=<requestType>,rest=<restImplType>,path=<subresourcepath>] "+
214
+ // "Got string: [%s]", tag)
215
+ // }
216
+ // value := kv[1]
217
+ // switch kv[0] {
218
+ // case "request":
219
+ // result.RequestKind = value
220
+ // case "rest":
221
+ // result.REST = value
222
+ // case "path":
223
+ // // Strip the parent resource
224
+ // result.Path = strings.Replace(value, c.Resource+"/", "", -1)
225
+ // }
226
+ // }
227
+ // return result
228
+ // }
226
229
227
230
// getResourceTag returns the value of the "+resource=" comment tag
228
231
func (b * APIs ) getResourceTag (c * types.Type ) string {
0 commit comments