@@ -60,7 +60,7 @@ import (
60
60
opv1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
61
61
sfv1 "github.com/softwarefactory-project/sf-operator/api/v1"
62
62
controllers "github.com/softwarefactory-project/sf-operator/controllers"
63
- ctrlutils "github.com/softwarefactory-project/sf-operator/controllers/libs/utils "
63
+ "github.com/softwarefactory-project/sf-operator/controllers/libs/logging "
64
64
65
65
"k8s.io/client-go/kubernetes"
66
66
@@ -167,10 +167,10 @@ func GetCLIContext(command *cobra.Command) (SoftwareFactoryConfigContext, error)
167
167
if configPath != "" {
168
168
ctxName , cliContext , err = getContextFromFile (command )
169
169
if err != nil {
170
- ctrlutils .LogE (err , "Could not load config file" )
170
+ logging .LogE (err , "Could not load config file" )
171
171
os .Exit (1 )
172
172
} else {
173
- ctrlutils .LogD ("Using configuration context " + ctxName )
173
+ logging .LogD ("Using configuration context " + ctxName )
174
174
}
175
175
}
176
176
// Override with defaults
@@ -217,12 +217,12 @@ func GetCLIContext(command *cobra.Command) (SoftwareFactoryConfigContext, error)
217
217
if cliContext .Dev .SFOperatorRepositoryPath == "" {
218
218
defaultSFOperatorRepositoryPath , getwdErr := os .Getwd ()
219
219
if getwdErr != nil {
220
- ctrlutils .LogE (getwdErr ,
220
+ logging .LogE (getwdErr ,
221
221
"sf-operator-repository-path is not set in `dev` section of the configuration file and unable to determine the current working directory" )
222
222
os .Exit (1 )
223
223
}
224
224
cliContext .Dev .SFOperatorRepositoryPath = defaultSFOperatorRepositoryPath
225
- ctrlutils .LogD ("Using current working directory for sf-operator-repository-path: " + cliContext .Dev .SFOperatorRepositoryPath )
225
+ logging .LogD ("Using current working directory for sf-operator-repository-path: " + cliContext .Dev .SFOperatorRepositoryPath )
226
226
}
227
227
return cliContext , nil
228
228
}
@@ -267,7 +267,7 @@ func CreateKubernetesClient(contextName string) (client.Client, error) {
267
267
func CreateKubernetesClientOrDie (contextName string ) client.Client {
268
268
cli , err := CreateKubernetesClient (contextName )
269
269
if err != nil {
270
- ctrlutils .LogE (err , "Error creating Kubernetes client" )
270
+ logging .LogE (err , "Error creating Kubernetes client" )
271
271
os .Exit (1 )
272
272
}
273
273
return cli
@@ -277,7 +277,7 @@ func GetCLIENV(kmd *cobra.Command) (string, ENV) {
277
277
278
278
cliCtx , err := GetCLIContext (kmd )
279
279
if err != nil {
280
- ctrlutils .LogE (err , "Error initializing CLI:" )
280
+ logging .LogE (err , "Error initializing CLI:" )
281
281
os .Exit (1 )
282
282
}
283
283
@@ -311,7 +311,7 @@ func DeleteOrDie(env *ENV, obj client.Object, opts ...client.DeleteOption) bool
311
311
return false
312
312
} else if err != nil {
313
313
msg := fmt .Sprintf ("Error while deleting %s \" %s\" " , reflect .TypeOf (obj ).Name (), obj .GetName ())
314
- ctrlutils .LogE (err , msg )
314
+ logging .LogE (err , msg )
315
315
os .Exit (1 )
316
316
}
317
317
return true
@@ -323,49 +323,49 @@ func GetMOrDie(env *ENV, name string, obj client.Object) bool {
323
323
return false
324
324
} else if err != nil {
325
325
msg := fmt .Sprintf ("Error while fetching %s \" %s\" " , reflect .TypeOf (obj ).Name (), name )
326
- ctrlutils .LogE (err , msg )
326
+ logging .LogE (err , msg )
327
327
os .Exit (1 )
328
328
}
329
329
return true
330
330
}
331
331
332
332
func UpdateROrDie (env * ENV , obj client.Object ) {
333
333
var msg = fmt .Sprintf ("Updating %s \" %s\" in %s" , reflect .TypeOf (obj ).Name (), obj .GetName (), env .Ns )
334
- ctrlutils .LogI (msg )
334
+ logging .LogI (msg )
335
335
if err := env .Cli .Update (env .Ctx , obj ); err != nil {
336
336
msg = fmt .Sprintf ("Error while updating %s \" %s\" " , reflect .TypeOf (obj ).Name (), obj .GetName ())
337
- ctrlutils .LogE (err , msg )
337
+ logging .LogE (err , msg )
338
338
os .Exit (1 )
339
339
}
340
340
msg = fmt .Sprintf ("%s \" %s\" updated" , reflect .TypeOf (obj ).Name (), obj .GetName ())
341
- ctrlutils .LogI (msg )
341
+ logging .LogI (msg )
342
342
}
343
343
344
344
func CreateROrDie (env * ENV , obj client.Object ) {
345
345
var msg = fmt .Sprintf ("Creating %s \" %s\" in %s" , reflect .TypeOf (obj ).Name (), obj .GetName (), env .Ns )
346
- ctrlutils .LogI (msg )
346
+ logging .LogI (msg )
347
347
obj .SetNamespace (env .Ns )
348
348
if err := env .Cli .Create (env .Ctx , obj ); err != nil {
349
349
msg = fmt .Sprintf ("Error while creating %s \" %s\" " , reflect .TypeOf (obj ).Name (), obj .GetName ())
350
- ctrlutils .LogE (err , msg )
350
+ logging .LogE (err , msg )
351
351
os .Exit (1 )
352
352
}
353
353
msg = fmt .Sprintf ("%s \" %s\" created" , reflect .TypeOf (obj ).Name (), obj .GetName ())
354
- ctrlutils .LogI (msg )
354
+ logging .LogI (msg )
355
355
}
356
356
357
357
func DeleteAllOfOrDie (env * ENV , obj client.Object , opts ... client.DeleteAllOfOption ) {
358
358
if err := env .Cli .DeleteAllOf (env .Ctx , obj , opts ... ); err != nil {
359
359
var msg = "Error while deleting"
360
- ctrlutils .LogE (err , msg )
360
+ logging .LogE (err , msg )
361
361
os .Exit (1 )
362
362
}
363
363
}
364
364
365
365
func GetCLIctxOrDie (kmd * cobra.Command , args []string , allowedArgs []string ) SoftwareFactoryConfigContext {
366
366
cliCtx , err := GetCLIContext (kmd )
367
367
if err != nil {
368
- ctrlutils .LogE (err , "Error initializing:" )
368
+ logging .LogE (err , "Error initializing:" )
369
369
os .Exit (1 )
370
370
}
371
371
if len (allowedArgs ) == 0 {
@@ -374,15 +374,15 @@ func GetCLIctxOrDie(kmd *cobra.Command, args []string, allowedArgs []string) Sof
374
374
} else {
375
375
argumentError := errors .New ("argument must be in: " + strings .Join (allowedArgs , ", " ))
376
376
if len (args ) != 1 {
377
- ctrlutils .LogE (argumentError , "Need one argument" )
377
+ logging .LogE (argumentError , "Need one argument" )
378
378
os .Exit (1 )
379
379
}
380
380
for _ , a := range allowedArgs {
381
381
if args [0 ] == a {
382
382
return cliCtx
383
383
}
384
384
}
385
- ctrlutils .LogE (argumentError , "Unknown argument " + args [0 ])
385
+ logging .LogE (argumentError , "Unknown argument " + args [0 ])
386
386
os .Exit (1 )
387
387
}
388
388
return SoftwareFactoryConfigContext {}
@@ -408,8 +408,8 @@ func RunCmdWithEnvOrDie(environ []string, cmd string, args ...string) string {
408
408
kmd .Env = append (os .Environ (), environ ... )
409
409
out , err := kmd .CombinedOutput ()
410
410
if err != nil {
411
- ctrlutils .LogE (err , "Could not run command '" + cmd + "'" )
412
- ctrlutils .LogI ("Captured output:\n " + string (out ))
411
+ logging .LogE (err , "Could not run command '" + cmd + "'" )
412
+ logging .LogI ("Captured output:\n " + string (out ))
413
413
os .Exit (1 )
414
414
}
415
415
return string (out )
@@ -425,7 +425,7 @@ func EnsureNamespaceOrDie(env *ENV, name string) {
425
425
ns .Name = name
426
426
CreateROrDie (env , & ns )
427
427
} else if err != nil {
428
- ctrlutils .LogE (err , "Error checking namespace " + name )
428
+ logging .LogE (err , "Error checking namespace " + name )
429
429
os .Exit (1 )
430
430
}
431
431
}
@@ -440,7 +440,7 @@ func EnsureServiceAccountOrDie(env *ENV, name string) {
440
440
func WriteContentToFile (filePath string , content []byte , mode fs.FileMode ) {
441
441
err := os .WriteFile (filePath , content , mode )
442
442
if err != nil {
443
- ctrlutils .LogE (err , "Can not write a file " + filePath )
443
+ logging .LogE (err , "Can not write a file " + filePath )
444
444
os .Exit (1 )
445
445
}
446
446
}
@@ -453,7 +453,7 @@ func VarListToMap(varsList []string) map[string]string {
453
453
tokens := strings .Split (v , "=" )
454
454
455
455
if len (tokens ) != 2 {
456
- ctrlutils .LogE (errors .New ("parse error" ), "parsed value `" + v + "` needs to be defined as 'foo=bar'" )
456
+ logging .LogE (errors .New ("parse error" ), "parsed value `" + v + "` needs to be defined as 'foo=bar'" )
457
457
os .Exit (1 )
458
458
}
459
459
vars [tokens [0 ]] = tokens [1 ]
@@ -464,7 +464,7 @@ func VarListToMap(varsList []string) map[string]string {
464
464
func CreateDirectory (dirPath string , mode fs.FileMode ) {
465
465
err := os .MkdirAll (dirPath , mode )
466
466
if err != nil {
467
- ctrlutils .LogE (err , "Can not create directory " + dirPath )
467
+ logging .LogE (err , "Can not create directory " + dirPath )
468
468
os .Exit (1 )
469
469
}
470
470
}
@@ -482,7 +482,7 @@ func GetClientset(kubeContext string) (*rest.Config, *kubernetes.Clientset) {
482
482
restConfig := controllers .GetConfigContextOrDie (kubeContext )
483
483
kubeClientset , err := kubernetes .NewForConfig (restConfig )
484
484
if err != nil {
485
- ctrlutils .LogE (err , "Could not instantiate Clientset" )
485
+ logging .LogE (err , "Could not instantiate Clientset" )
486
486
os .Exit (1 )
487
487
}
488
488
return restConfig , kubeClientset
@@ -510,7 +510,7 @@ func RunRemoteCmd(kubeContext string, namespace string, podName string, containe
510
510
if err != nil {
511
511
errMsg := fmt .Sprintf ("Command \" %s\" [Pod: %s - Container: %s] failed with the following stderr: %s" ,
512
512
strings .Join (cmdArgs , " " ), podName , containerName , errorBuffer .String ())
513
- ctrlutils .LogE (err , errMsg )
513
+ logging .LogE (err , errMsg )
514
514
os .Exit (1 )
515
515
}
516
516
return buffer
@@ -521,10 +521,10 @@ func ReadYAMLToMapOrDie(filePath string) map[string]interface{} {
521
521
secretContent := make (map [string ]interface {})
522
522
err := yaml .Unmarshal (readFile , & secretContent )
523
523
if err != nil {
524
- ctrlutils .LogE (err , "Problem on reading the file content" )
524
+ logging .LogE (err , "Problem on reading the file content" )
525
525
}
526
526
if len (secretContent ) == 0 {
527
- ctrlutils .LogE (errors .New ("file is empty" ), "The file is empty or it does not exist!" )
527
+ logging .LogE (errors .New ("file is empty" ), "The file is empty or it does not exist!" )
528
528
os .Exit (1 )
529
529
}
530
530
return secretContent
@@ -533,7 +533,7 @@ func ReadYAMLToMapOrDie(filePath string) map[string]interface{} {
533
533
func GetKubectlPath () string {
534
534
kubectlPath , err := exec .LookPath ("kubectl" )
535
535
if err != nil {
536
- ctrlutils .LogE (errors .New ("no kubectl binary" ),
536
+ logging .LogE (errors .New ("no kubectl binary" ),
537
537
"No 'kubectl' binary found. Please install the 'kubectl' binary before attempting a restore" )
538
538
os .Exit (1 )
539
539
}
@@ -547,7 +547,7 @@ func ExecuteKubectlClient(ns string, podName string, containerName string, execu
547
547
548
548
err := cmd .Run ()
549
549
if err != nil {
550
- ctrlutils .LogE (err , "There is an issue on executing command: " + executeCommand )
550
+ logging .LogE (err , "There is an issue on executing command: " + executeCommand )
551
551
os .Exit (1 )
552
552
}
553
553
@@ -556,7 +556,7 @@ func ExecuteKubectlClient(ns string, podName string, containerName string, execu
556
556
func GetKubeConfig () * clientcmdapi.Config {
557
557
clientCfg , err := clientcmd .NewDefaultClientConfigLoadingRules ().Load ()
558
558
if err != nil {
559
- ctrlutils .LogE (err , "Could not find the kubeconfig" )
559
+ logging .LogE (err , "Could not find the kubeconfig" )
560
560
os .Exit (1 )
561
561
}
562
562
return clientCfg
@@ -580,7 +580,7 @@ func GetKubeConfigContextByName(contextName string) (*clientcmdapi.Context, stri
580
580
// Load the context
581
581
context , err := clientCfg .Contexts [contextName ]
582
582
if ! err {
583
- ctrlutils .LogD ("could not find the context " + contextName )
583
+ logging .LogD ("could not find the context " + contextName )
584
584
}
585
585
return context , contextName
586
586
}
0 commit comments