@@ -19,7 +19,6 @@ package parse
1919import (
2020 "fmt"
2121 "log"
22- "path/filepath"
2322 "strings"
2423
2524 "github.com/kubernetes-sigs/kubebuilder/cmd/internal/codegen"
@@ -71,8 +70,9 @@ func (b *APIs) parseIndex() {
7170
7271 rt := parseResourceTag (b .getResourceTag (c ))
7372 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
7676
7777 // Copy the Status strategy to mirror the non-status strategy
7878 r .StatusStrategy = strings .TrimSuffix (r .Strategy , "Strategy" )
@@ -96,85 +96,86 @@ func (b *APIs) parseIndex() {
9696 b.ByGroupKindVersion [r.Group ][r.Kind ][r .Version ] = r
9797 b.ByGroupVersionKind [r.Group ][r.Version ][r .Kind ] = r
9898
99- if ! HasSubresource (c ) {
100- continue
101- }
99+ // if !HasSubresource(c) {
100+ // continue
101+ // }
102102 r .Type = c
103- r .Subresources = b .getSubresources (r )
103+ // r.Subresources = b.getSubresources(r)
104104 }
105105}
106106
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+ // }
141141
142142// 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+ // }
154154
155155// 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+ // }
172172
173173// resourceTags contains the tags present in a "+resource=" comment
174174type resourceTags struct {
175- Resource string
176- REST string
177- Strategy string
175+ Resource string
176+ REST string
177+ Strategy string
178+ ShortName string
178179}
179180
180181// ParseResourceTag parses the tags in a "+resource=" comment into a resourceTags struct
@@ -189,40 +190,42 @@ func parseResourceTag(tag string) resourceTags {
189190 }
190191 value := kv [1 ]
191192 switch kv [0 ] {
192- case "rest" :
193- result .REST = value
193+ // case "rest":
194+ // result.REST = value
194195 case "path" :
195196 result .Resource = value
196- case "strategy" :
197- result .Strategy = value
197+ //case "strategy":
198+ // result.Strategy = value
199+ case "shortName" :
200+ result .ShortName = value
198201 }
199202 }
200203 return result
201204}
202205
203206// 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+ // }
226229
227230// getResourceTag returns the value of the "+resource=" comment tag
228231func (b * APIs ) getResourceTag (c * types.Type ) string {
0 commit comments