14
14
package model
15
15
16
16
import (
17
- "fmt"
18
17
"sort"
19
18
"strings"
20
19
@@ -58,14 +57,6 @@ func (ops Ops) IterOps() []*awssdkmodel.Operation {
58
57
return res
59
58
}
60
59
61
- // PrinterColumn represents a single field in the CRD's Spec or Status objects
62
- type PrinterColumn struct {
63
- CRD * CRD
64
- Name string
65
- Type string
66
- JSONPath string
67
- }
68
-
69
60
// CRD describes a single top-level resource in an AWS service API
70
61
type CRD struct {
71
62
sdkAPI * SDKAPI
@@ -75,10 +66,9 @@ type CRD struct {
75
66
Plural string
76
67
// Ops are the CRUD operations controlling this resource
77
68
Ops Ops
78
- // AdditionalPrinterColumns is an array of PrinterColumn objects
69
+ // additionalPrinterColumns is an array of PrinterColumn objects
79
70
// representing the printer column settings for the CRD
80
- // AdditionalPrinterColumns field.
81
- AdditionalPrinterColumns []* PrinterColumn
71
+ additionalPrinterColumns []* PrinterColumn
82
72
// SpecFields is a map, keyed by the **original SDK member name** of
83
73
// Field objects representing those fields in the CRD's Spec struct
84
74
// field.
@@ -178,22 +168,29 @@ func (r *CRD) InputFieldRename(
178
168
func (r * CRD ) AddSpecField (
179
169
memberNames names.Names ,
180
170
shapeRef * awssdkmodel.ShapeRef ,
181
- ) * Field {
182
- fieldConfigs := r .cfg .ResourceFields (r .Names .Original )
183
- f := newField (r , memberNames , shapeRef , fieldConfigs [memberNames .Original ])
171
+ ) {
172
+ fConfigs := r .cfg .ResourceFields (r .Names .Original )
173
+ fConfig := fConfigs [memberNames .Original ]
174
+ f := newField (r , memberNames , shapeRef , fConfig )
175
+ if fConfig != nil && fConfig .IsPrintable {
176
+ r .addSpecPrintableColumn (f )
177
+ }
184
178
r .SpecFields [memberNames .Original ] = f
185
- return f
186
179
}
187
180
188
181
// AddStatusField adds a new Field of a given name and shape into the Status
189
182
// field of a CRD
190
183
func (r * CRD ) AddStatusField (
191
184
memberNames names.Names ,
192
185
shapeRef * awssdkmodel.ShapeRef ,
193
- ) * Field {
194
- f := newField (r , memberNames , shapeRef , nil )
186
+ ) {
187
+ fConfigs := r .cfg .ResourceFields (r .Names .Original )
188
+ fConfig := fConfigs [memberNames .Original ]
189
+ f := newField (r , memberNames , shapeRef , fConfig )
190
+ if fConfig != nil && fConfig .IsPrintable {
191
+ r .addStatusPrintableColumn (f )
192
+ }
195
193
r .StatusFields [memberNames .Original ] = f
196
- return f
197
194
}
198
195
199
196
// AddTypeImport adds an entry in the CRD's TypeImports map for an import line
@@ -218,80 +215,6 @@ func (r *CRD) SpecFieldNames() []string {
218
215
return res
219
216
}
220
217
221
- // AddPrintableColumn adds an entry to the list of additional printer columns
222
- // using the given path and field types.
223
- func (r * CRD ) AddPrintableColumn (
224
- field * Field ,
225
- jsonPath string ,
226
- ) * PrinterColumn {
227
- fieldColumnType := field .GoTypeElem
228
-
229
- // Printable columns must be primitives supported by the OpenAPI list of data
230
- // types as defined by
231
- // https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#data-types
232
- // This maps Go type to OpenAPI type.
233
- acceptableColumnMaps := map [string ]string {
234
- "string" : "string" ,
235
- "boolean" : "boolean" ,
236
- "int" : "integer" ,
237
- "int8" : "integer" ,
238
- "int16" : "integer" ,
239
- "int32" : "integer" ,
240
- "int64" : "integer" ,
241
- "uint" : "integer" ,
242
- "uint8" : "integer" ,
243
- "uint16" : "integer" ,
244
- "uint32" : "integer" ,
245
- "uint64" : "integer" ,
246
- "uintptr" : "integer" ,
247
- "float32" : "number" ,
248
- "float64" : "number" ,
249
- }
250
- printColumnType , exists := acceptableColumnMaps [fieldColumnType ]
251
-
252
- if ! exists {
253
- msg := fmt .Sprintf (
254
- "GENERATION FAILURE! Unable to generate a printer column for the field %s that has type %s." ,
255
- field .Names .Camel , fieldColumnType ,
256
- )
257
- panic (msg )
258
- return nil
259
- }
260
-
261
- column := & PrinterColumn {
262
- CRD : r ,
263
- Name : field .Names .Camel ,
264
- Type : printColumnType ,
265
- JSONPath : jsonPath ,
266
- }
267
- r .AdditionalPrinterColumns = append (r .AdditionalPrinterColumns , column )
268
- return column
269
- }
270
-
271
- // AddSpecPrintableColumn adds an entry to the list of additional printer columns
272
- // using the path of the given spec field.
273
- func (r * CRD ) AddSpecPrintableColumn (
274
- field * Field ,
275
- ) * PrinterColumn {
276
- return r .AddPrintableColumn (
277
- field ,
278
- //TODO(nithomso): Ideally we'd use `r.cfg.PrefixConfig.SpecField` but it uses uppercase
279
- fmt .Sprintf ("%s.%s" , ".spec" , field .Names .CamelLower ),
280
- )
281
- }
282
-
283
- // AddStatusPrintableColumn adds an entry to the list of additional printer columns
284
- // using the path of the given status field.
285
- func (r * CRD ) AddStatusPrintableColumn (
286
- field * Field ,
287
- ) * PrinterColumn {
288
- return r .AddPrintableColumn (
289
- field ,
290
- //TODO(nithomso): Ideally we'd use `r.cfg.PrefixConfig.StatusField` but it uses uppercase
291
- fmt .Sprintf ("%s.%s" , ".status" , field .Names .CamelLower ),
292
- )
293
- }
294
-
295
218
// UnpacksAttributesMap returns true if the underlying API has
296
219
// Get{Resource}Attributes/Set{Resource}Attributes API calls that map real,
297
220
// schema'd fields to a raw `map[string]*string` for this resource (see SNS and
@@ -470,7 +393,7 @@ func NewCRD(
470
393
Kind : kind ,
471
394
Plural : plural ,
472
395
Ops : ops ,
473
- AdditionalPrinterColumns : make ([]* PrinterColumn , 0 ),
396
+ additionalPrinterColumns : make ([]* PrinterColumn , 0 ),
474
397
SpecFields : map [string ]* Field {},
475
398
StatusFields : map [string ]* Field {},
476
399
ShortNames : cfg .ResourceShortNames (kind ),
0 commit comments