@@ -33,6 +33,7 @@ import (
33
33
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/k8s"
34
34
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/util/repo"
35
35
apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
36
+ "k8s.io/apimachinery/pkg/util/sets"
36
37
"k8s.io/klog/v2"
37
38
)
38
39
@@ -74,7 +75,7 @@ type svkMap struct {
74
75
}
75
76
76
77
func main () {
77
- resources := make ( map [ string ]* resourceDefinition )
78
+ var resources [ ]* resourceDefinition
78
79
registerKinds := make (map [string ]* svkMap )
79
80
crdsDir := repo .GetCRDsPath ()
80
81
crdsPath , err := filepath .Abs (crdsDir )
@@ -87,8 +88,7 @@ func main() {
87
88
}
88
89
89
90
for _ , crdFile := range crdFiles {
90
- fileName := strings .TrimSuffix (crdFile .Name (), ".yaml" )
91
- resources [fileName ] = constructResourceDefinition (crdsPath , crdFile .Name ())
91
+ resources = append (resources , constructResourceDefinitions (crdsPath , crdFile .Name ())... )
92
92
}
93
93
94
94
for _ , rd := range resources {
@@ -261,8 +261,7 @@ func checkAndCreateFolder(dir string) {
261
261
}
262
262
}
263
263
264
- func constructResourceDefinition (crdsPath , crdFile string ) * resourceDefinition {
265
- r := & resourceDefinition {}
264
+ func constructResourceDefinitions (crdsPath , crdFile string ) []* resourceDefinition {
266
265
crdFilePath , err := filepath .Abs (path .Join (crdsPath , crdFile ))
267
266
if err != nil {
268
267
log .Fatalf ("error getting the absolute representation of path for directory '%v': %v" , crdFile , err )
@@ -272,25 +271,40 @@ func constructResourceDefinition(crdsPath, crdFile string) *resourceDefinition {
272
271
log .Fatalf ("error loading crd from filepath %v: %v" , crdFilePath , err )
273
272
}
274
273
275
- r .CRD = crd
276
- r .Name = crd .Spec .Names .Kind
277
- if err = buildFieldProperties (r , crd ); err != nil {
278
- log .Fatalf ("error building field properties for %v: %v" , r .Name , err )
274
+ versionNames := sets .NewString ()
275
+ for _ , crdVersion := range crd .Spec .Versions {
276
+ versionNames .Insert (crdVersion .Name )
279
277
}
280
- r .Service = strings .TrimSuffix (crd .Spec .Group , k8s .APIDomainSuffix )
281
- r .Kind = strings .ToLower (crd .Spec .Names .Kind )
282
278
283
- // TODO: Should we handle multiple versions?
284
- r .Version = k8s .PreferredVersion (crd )
285
- return r
279
+ var resources []* resourceDefinition
280
+ for _ , versionName := range versionNames .List () {
281
+ // Don't generate alpha version if we have a beta
282
+ if versionName == "v1alpha1" && versionNames .Has ("v1beta1" ) {
283
+ continue
284
+ }
285
+ crdVersionDefinition := k8s .GetCRDVersionDefinition (crd , versionName )
286
+
287
+ r := & resourceDefinition {}
288
+ r .CRD = crd
289
+ r .Name = crd .Spec .Names .Kind
290
+ if err = buildFieldProperties (r , crd , crdVersionDefinition .Name ); err != nil {
291
+ log .Fatalf ("error building field properties for %v: %v" , r .Name , err )
292
+ }
293
+ r .Service = strings .TrimSuffix (crd .Spec .Group , k8s .APIDomainSuffix )
294
+ r .Kind = strings .ToLower (crd .Spec .Names .Kind )
295
+
296
+ r .Version = crdVersionDefinition
297
+ resources = append (resources , r )
298
+ }
299
+ return resources
286
300
}
287
301
288
- func buildFieldProperties (r * resourceDefinition , crd * apiextensions.CustomResourceDefinition ) error {
289
- specDesc := fielddesc .GetSpecDescription (crd )
302
+ func buildFieldProperties (r * resourceDefinition , crd * apiextensions.CustomResourceDefinition , version string ) error {
303
+ specDesc := fielddesc .GetSpecDescription (crd , version )
290
304
specDescriptions := dropRootAndFlattenChildrenDescriptions (specDesc )
291
305
r .SpecNestedStructs = make (map [string ][]* fieldProperties )
292
306
organizeSpecFieldDescriptions (specDescriptions , r )
293
- statusDesc , err := fielddesc .GetStatusDescription (crd )
307
+ statusDesc , err := fielddesc .GetStatusDescription (crd , version )
294
308
if err != nil {
295
309
return fmt .Errorf ("error getting status descriptions: %w" , err )
296
310
}
0 commit comments