@@ -148,23 +148,23 @@ func changeWorkingDirectory(outputDir string) error {
148
148
}
149
149
150
150
// Initializes the project with Kubebuilder.
151
- func kubebuilderInit (store store.Store ) error {
152
- args := append ([]string {"init" }, getInitArgs (store )... )
151
+ func kubebuilderInit (s store.Store ) error {
152
+ args := append ([]string {"init" }, getInitArgs (s )... )
153
153
return util .RunCmd ("kubebuilder init" , "kubebuilder" , args ... )
154
154
}
155
155
156
156
// Edits the project to enable or disable multigroup layout.
157
- func kubebuilderEdit (store store.Store ) error {
158
- if store .Config ().IsMultiGroup () {
157
+ func kubebuilderEdit (s store.Store ) error {
158
+ if s .Config ().IsMultiGroup () {
159
159
args := []string {"edit" , "--multigroup" }
160
160
return util .RunCmd ("kubebuilder edit" , "kubebuilder" , args ... )
161
161
}
162
162
return nil
163
163
}
164
164
165
165
// Creates APIs and Webhooks for the project.
166
- func kubebuilderCreate (store store.Store ) error {
167
- resources , err := store .Config ().GetResources ()
166
+ func kubebuilderCreate (s store.Store ) error {
167
+ resources , err := s .Config ().GetResources ()
168
168
if err != nil {
169
169
return fmt .Errorf ("failed to get resources: %w" , err )
170
170
}
@@ -188,9 +188,9 @@ func kubebuilderCreate(store store.Store) error {
188
188
}
189
189
190
190
// Migrates the Grafana plugin.
191
- func migrateGrafanaPlugin (store store.Store , src , des string ) error {
191
+ func migrateGrafanaPlugin (s store.Store , src , des string ) error {
192
192
var grafanaPlugin struct {}
193
- err := store .Config ().DecodePluginConfig (plugin .KeyFor (v1alpha.Plugin {}), grafanaPlugin )
193
+ err := s .Config ().DecodePluginConfig (plugin .KeyFor (v1alpha.Plugin {}), grafanaPlugin )
194
194
if errors .As (err , & config.PluginKeyNotFoundError {}) {
195
195
log .Info ("Grafana plugin not found, skipping migration" )
196
196
return nil
@@ -210,9 +210,9 @@ func migrateGrafanaPlugin(store store.Store, src, des string) error {
210
210
}
211
211
212
212
// Migrates the Deploy Image plugin.
213
- func migrateDeployImagePlugin (store store.Store ) error {
213
+ func migrateDeployImagePlugin (s store.Store ) error {
214
214
var deployImagePlugin v1alpha1.PluginConfig
215
- err := store .Config ().DecodePluginConfig (plugin .KeyFor (v1alpha1.Plugin {}), & deployImagePlugin )
215
+ err := s .Config ().DecodePluginConfig (plugin .KeyFor (v1alpha1.Plugin {}), & deployImagePlugin )
216
216
if errors .As (err , & config.PluginKeyNotFoundError {}) {
217
217
log .Info ("Deploy-image plugin not found, skipping migration" )
218
218
return nil
@@ -230,9 +230,9 @@ func migrateDeployImagePlugin(store store.Store) error {
230
230
}
231
231
232
232
// Creates an API with Deploy Image plugin.
233
- func createAPIWithDeployImage (resource v1alpha1.ResourceData ) error {
234
- args := append ([]string {"create" , "api" }, getGVKFlagsFromDeployImage (resource )... )
235
- args = append (args , getDeployImageOptions (resource )... )
233
+ func createAPIWithDeployImage (resourceData v1alpha1.ResourceData ) error {
234
+ args := append ([]string {"create" , "api" }, getGVKFlagsFromDeployImage (resourceData )... )
235
+ args = append (args , getDeployImageOptions (resourceData )... )
236
236
return util .RunCmd ("kubebuilder create api" , "kubebuilder" , args ... )
237
237
}
238
238
@@ -253,9 +253,9 @@ func getInputPath(inputPath string) (string, error) {
253
253
}
254
254
255
255
// Helper function to get Init arguments for Kubebuilder.
256
- func getInitArgs (store store.Store ) []string {
256
+ func getInitArgs (s store.Store ) []string {
257
257
var args []string
258
- plugins := store .Config ().GetPluginChain ()
258
+ plugins := s .Config ().GetPluginChain ()
259
259
260
260
// Define outdated plugin versions that need replacement
261
261
outdatedPlugins := map [string ]string {
@@ -277,96 +277,96 @@ func getInitArgs(store store.Store) []string {
277
277
if len (plugins ) > 0 {
278
278
args = append (args , "--plugins" , strings .Join (plugins , "," ))
279
279
}
280
- if domain := store .Config ().GetDomain (); domain != "" {
280
+ if domain := s .Config ().GetDomain (); domain != "" {
281
281
args = append (args , "--domain" , domain )
282
282
}
283
- if repo := store .Config ().GetRepository (); repo != "" {
283
+ if repo := s .Config ().GetRepository (); repo != "" {
284
284
args = append (args , "--repo" , repo )
285
285
}
286
286
return args
287
287
}
288
288
289
289
// Gets the GVK flags for a resource.
290
- func getGVKFlags (resource resource.Resource ) []string {
290
+ func getGVKFlags (res resource.Resource ) []string {
291
291
var args []string
292
- if resource .Plural != "" {
293
- args = append (args , "--plural" , resource .Plural )
292
+ if res .Plural != "" {
293
+ args = append (args , "--plural" , res .Plural )
294
294
}
295
- if resource .Group != "" {
296
- args = append (args , "--group" , resource .Group )
295
+ if res .Group != "" {
296
+ args = append (args , "--group" , res .Group )
297
297
}
298
- if resource .Version != "" {
299
- args = append (args , "--version" , resource .Version )
298
+ if res .Version != "" {
299
+ args = append (args , "--version" , res .Version )
300
300
}
301
- if resource .Kind != "" {
302
- args = append (args , "--kind" , resource .Kind )
301
+ if res .Kind != "" {
302
+ args = append (args , "--kind" , res .Kind )
303
303
}
304
304
return args
305
305
}
306
306
307
307
// Gets the GVK flags for a Deploy Image resource.
308
- func getGVKFlagsFromDeployImage (resource v1alpha1.ResourceData ) []string {
308
+ func getGVKFlagsFromDeployImage (resourceData v1alpha1.ResourceData ) []string {
309
309
var args []string
310
- if resource .Group != "" {
311
- args = append (args , "--group" , resource .Group )
310
+ if resourceData .Group != "" {
311
+ args = append (args , "--group" , resourceData .Group )
312
312
}
313
- if resource .Version != "" {
314
- args = append (args , "--version" , resource .Version )
313
+ if resourceData .Version != "" {
314
+ args = append (args , "--version" , resourceData .Version )
315
315
}
316
- if resource .Kind != "" {
317
- args = append (args , "--kind" , resource .Kind )
316
+ if resourceData .Kind != "" {
317
+ args = append (args , "--kind" , resourceData .Kind )
318
318
}
319
319
return args
320
320
}
321
321
322
322
// Gets the options for a Deploy Image resource.
323
- func getDeployImageOptions (resource v1alpha1.ResourceData ) []string {
323
+ func getDeployImageOptions (resourceData v1alpha1.ResourceData ) []string {
324
324
var args []string
325
- if resource .Options .Image != "" {
326
- args = append (args , fmt .Sprintf ("--image=%s" , resource .Options .Image ))
325
+ if resourceData .Options .Image != "" {
326
+ args = append (args , fmt .Sprintf ("--image=%s" , resourceData .Options .Image ))
327
327
}
328
- if resource .Options .ContainerCommand != "" {
329
- args = append (args , fmt .Sprintf ("--image-container-command=%s" , resource .Options .ContainerCommand ))
328
+ if resourceData .Options .ContainerCommand != "" {
329
+ args = append (args , fmt .Sprintf ("--image-container-command=%s" , resourceData .Options .ContainerCommand ))
330
330
}
331
- if resource .Options .ContainerPort != "" {
332
- args = append (args , fmt .Sprintf ("--image-container-port=%s" , resource .Options .ContainerPort ))
331
+ if resourceData .Options .ContainerPort != "" {
332
+ args = append (args , fmt .Sprintf ("--image-container-port=%s" , resourceData .Options .ContainerPort ))
333
333
}
334
- if resource .Options .RunAsUser != "" {
335
- args = append (args , fmt .Sprintf ("--run-as-user=%s" , resource .Options .RunAsUser ))
334
+ if resourceData .Options .RunAsUser != "" {
335
+ args = append (args , fmt .Sprintf ("--run-as-user=%s" , resourceData .Options .RunAsUser ))
336
336
}
337
337
args = append (args , fmt .Sprintf ("--plugins=%s" , plugin .KeyFor (v1alpha1.Plugin {})))
338
338
return args
339
339
}
340
340
341
341
// Creates an API resource.
342
- func createAPI (resource resource.Resource ) error {
343
- args := append ([]string {"create" , "api" }, getGVKFlags (resource )... )
344
- args = append (args , getAPIResourceFlags (resource )... )
342
+ func createAPI (res resource.Resource ) error {
343
+ args := append ([]string {"create" , "api" }, getGVKFlags (res )... )
344
+ args = append (args , getAPIResourceFlags (res )... )
345
345
346
346
// Add the external API path flag if the resource is external
347
- if resource .IsExternal () {
348
- args = append (args , "--external-api-path" , resource .Path )
349
- args = append (args , "--external-api-domain" , resource .Domain )
347
+ if res .IsExternal () {
348
+ args = append (args , "--external-api-path" , res .Path )
349
+ args = append (args , "--external-api-domain" , res .Domain )
350
350
}
351
351
352
352
return util .RunCmd ("kubebuilder create api" , "kubebuilder" , args ... )
353
353
}
354
354
355
355
// Gets flags for API resource creation.
356
- func getAPIResourceFlags (resource resource.Resource ) []string {
356
+ func getAPIResourceFlags (res resource.Resource ) []string {
357
357
var args []string
358
358
359
- if resource .API == nil || resource .API .IsEmpty () {
359
+ if res .API == nil || res .API .IsEmpty () {
360
360
args = append (args , "--resource=false" )
361
361
} else {
362
362
args = append (args , "--resource" )
363
- if resource .API .Namespaced {
363
+ if res .API .Namespaced {
364
364
args = append (args , "--namespaced" )
365
365
} else {
366
366
args = append (args , "--namespaced=false" )
367
367
}
368
368
}
369
- if resource .Controller {
369
+ if res .Controller {
370
370
args = append (args , "--controller" )
371
371
} else {
372
372
args = append (args , "--controller=false" )
@@ -375,32 +375,32 @@ func getAPIResourceFlags(resource resource.Resource) []string {
375
375
}
376
376
377
377
// Creates a webhook resource.
378
- func createWebhook (resource resource.Resource ) error {
379
- if resource .Webhooks == nil || resource .Webhooks .IsEmpty () {
378
+ func createWebhook (res resource.Resource ) error {
379
+ if res .Webhooks == nil || res .Webhooks .IsEmpty () {
380
380
return nil
381
381
}
382
- args := append ([]string {"create" , "webhook" }, getGVKFlags (resource )... )
383
- args = append (args , getWebhookResourceFlags (resource )... )
382
+ args := append ([]string {"create" , "webhook" }, getGVKFlags (res )... )
383
+ args = append (args , getWebhookResourceFlags (res )... )
384
384
return util .RunCmd ("kubebuilder create webhook" , "kubebuilder" , args ... )
385
385
}
386
386
387
387
// Gets flags for webhook creation.
388
- func getWebhookResourceFlags (resource resource.Resource ) []string {
388
+ func getWebhookResourceFlags (res resource.Resource ) []string {
389
389
var args []string
390
- if resource .IsExternal () {
391
- args = append (args , "--external-api-path" , resource .Path )
392
- args = append (args , "--external-api-domain" , resource .Domain )
390
+ if res .IsExternal () {
391
+ args = append (args , "--external-api-path" , res .Path )
392
+ args = append (args , "--external-api-domain" , res .Domain )
393
393
}
394
- if resource .HasValidationWebhook () {
394
+ if res .HasValidationWebhook () {
395
395
args = append (args , "--programmatic-validation" )
396
396
}
397
- if resource .HasDefaultingWebhook () {
397
+ if res .HasDefaultingWebhook () {
398
398
args = append (args , "--defaulting" )
399
399
}
400
- if resource .HasConversionWebhook () {
400
+ if res .HasConversionWebhook () {
401
401
args = append (args , "--conversion" )
402
- if len (resource .Webhooks .Spoke ) > 0 {
403
- for _ , spoke := range resource .Webhooks .Spoke {
402
+ if len (res .Webhooks .Spoke ) > 0 {
403
+ for _ , spoke := range res .Webhooks .Spoke {
404
404
args = append (args , "--spoke" , spoke )
405
405
}
406
406
}
0 commit comments