@@ -23,7 +23,6 @@ import (
2323 "k8s.io/kubectl/pkg/util/i18n"
2424 "k8s.io/kubectl/pkg/util/templates"
2525
26- retinacmd "github.com/microsoft/retina/cli/cmd"
2726 retinav1alpha1 "github.com/microsoft/retina/crd/api/v1alpha1"
2827 "github.com/microsoft/retina/internal/buildinfo"
2928 pkgcapture "github.com/microsoft/retina/pkg/capture"
@@ -109,47 +108,47 @@ func create(kubeClient kubernetes.Interface) error {
109108
110109 jobsCreated , err := createJobs (ctx , kubeClient , capture )
111110 if err != nil {
112- retinacmd . Logger .Error ("Failed to create job" , zap .Error (err ))
111+ opts . logger .Error ("Failed to create job" , zap .Error (err ))
113112 return err
114113 }
115114 if opts .nowait {
116- retinacmd . Logger .Info ("Please manually delete all capture jobs" )
115+ opts . logger .Info ("Please manually delete all capture jobs" )
117116 if capture .Spec .OutputConfiguration .BlobUpload != nil {
118- retinacmd . Logger .Info ("Please manually delete capture secret" , zap .String ("namespace" , * opts .Namespace ), zap .String ("secret name" , * capture .Spec .OutputConfiguration .BlobUpload ))
117+ opts . logger .Info ("Please manually delete capture secret" , zap .String ("namespace" , * opts .Namespace ), zap .String ("secret name" , * capture .Spec .OutputConfiguration .BlobUpload ))
119118 }
120119 if capture .Spec .OutputConfiguration .S3Upload != nil && capture .Spec .OutputConfiguration .S3Upload .SecretName != "" {
121- retinacmd . Logger .Info ("Please manually delete capture secret" , zap .String ("namespace" , * opts .Namespace ), zap .String ("secret name" , capture .Spec .OutputConfiguration .S3Upload .SecretName ))
120+ opts . logger .Info ("Please manually delete capture secret" , zap .String ("namespace" , * opts .Namespace ), zap .String ("secret name" , capture .Spec .OutputConfiguration .S3Upload .SecretName ))
122121 }
123122 printCaptureResult (jobsCreated )
124123 return nil
125124 }
126125
127126 // Wait until all jobs finish then delete the jobs before the timeout, otherwise print jobs created to
128127 // let the customer recycle them.
129- retinacmd . Logger .Info ("Waiting for capture jobs to finish" )
128+ opts . logger .Info ("Waiting for capture jobs to finish" )
130129
131130 allJobsCompleted := waitUntilJobsComplete (ctx , kubeClient , jobsCreated )
132131
133132 // Delete all jobs created only if they all completed, otherwise keep the jobs for debugging.
134133 if allJobsCompleted {
135- retinacmd . Logger .Info ("Deleting jobs as all jobs are completed" )
134+ opts . logger .Info ("Deleting jobs as all jobs are completed" )
136135 jobsFailedToDelete := deleteJobs (ctx , kubeClient , jobsCreated )
137136 if len (jobsFailedToDelete ) != 0 {
138- retinacmd . Logger .Info ("Please manually delete capture jobs failed to delete" , zap .String ("namespace" , * opts .Namespace ), zap .String ("job list" , strings .Join (jobsFailedToDelete , "," )))
137+ opts . logger .Info ("Please manually delete capture jobs failed to delete" , zap .String ("namespace" , * opts .Namespace ), zap .String ("job list" , strings .Join (jobsFailedToDelete , "," )))
139138 }
140139
141140 if capture .Spec .OutputConfiguration .BlobUpload != nil {
142141 err = deleteSecret (ctx , kubeClient , capture .Spec .OutputConfiguration .BlobUpload )
143142 if err != nil {
144- retinacmd . Logger .Error ("Failed to delete capture secret, please manually delete it" ,
143+ opts . logger .Error ("Failed to delete capture secret, please manually delete it" ,
145144 zap .String ("namespace" , * opts .Namespace ), zap .String ("secret name" , * capture .Spec .OutputConfiguration .BlobUpload ), zap .Error (err ))
146145 }
147146 }
148147
149148 if capture .Spec .OutputConfiguration .S3Upload != nil && capture .Spec .OutputConfiguration .S3Upload .SecretName != "" {
150149 err = deleteSecret (ctx , kubeClient , & capture .Spec .OutputConfiguration .S3Upload .SecretName )
151150 if err != nil {
152- retinacmd . Logger .Error ("Failed to delete capture secret, please manually delete it" ,
151+ opts . logger .Error ("Failed to delete capture secret, please manually delete it" ,
153152 zap .String ("namespace" , * opts .Namespace ),
154153 zap .String ("secret name" , capture .Spec .OutputConfiguration .S3Upload .SecretName ),
155154 zap .Error (err ),
@@ -158,13 +157,13 @@ func create(kubeClient kubernetes.Interface) error {
158157 }
159158
160159 if len (jobsFailedToDelete ) == 0 && err == nil {
161- retinacmd . Logger .Info ("Done for deleting jobs" )
160+ opts . logger .Info ("Done for deleting jobs" )
162161 }
163162 return nil
164163 }
165164
166- retinacmd . Logger .Info ("Not all job are completed in the given time" )
167- retinacmd . Logger .Info ("Please manually delete the Capture" )
165+ opts . logger .Info ("Not all job are completed in the given time" )
166+ opts . logger .Info ("Please manually delete the Capture" )
168167
169168 return getCaptureAndPrintCaptureResult (ctx , kubeClient , capture .Name , * opts .Namespace )
170169}
@@ -299,17 +298,17 @@ func createCaptureF(ctx context.Context, kubeClient kubernetes.Interface) (*reti
299298 },
300299 }
301300
302- retinacmd . Logger .Info (fmt .Sprintf ("Capture timestamp: %s" , timestamp ))
301+ opts . logger .Info (fmt .Sprintf ("Capture timestamp: %s" , timestamp ))
303302
304303 if opts .duration != 0 {
305- retinacmd . Logger .Info (fmt .Sprintf ("The capture duration is set to %s" , opts .duration ))
304+ opts . logger .Info (fmt .Sprintf ("The capture duration is set to %s" , opts .duration ))
306305 capture .Spec .CaptureConfiguration .CaptureOption .Duration = & metav1.Duration {Duration : opts .duration }
307306 }
308307
309308 if opts .namespaceSelectors != "" || opts .podSelectors != "" || opts .podNames != "" {
310309 // if node selector is using the default value (aka hasn't been set by user), set it to nil to prevent clash with namespace and pod selector
311310 if opts .nodeSelectors == DefaultNodeSelectors {
312- retinacmd . Logger .Info ("Overriding default node selectors value and setting it to nil. Using namespace, pod selectors, or pod names. " +
311+ opts . logger .Info ("Overriding default node selectors value and setting it to nil. Using namespace, pod selectors, or pod names. " +
313312 "To use node selector, please remove namespace and pod selectors." )
314313 opts .nodeSelectors = ""
315314 }
@@ -365,17 +364,17 @@ func createCaptureF(ctx context.Context, kubeClient kubernetes.Interface) (*reti
365364 for i := range podNameSlice {
366365 podNameSlice [i ] = strings .TrimSpace (podNameSlice [i ])
367366 }
368- retinacmd . Logger .Info (fmt .Sprintf ("Capturing on specific pods: %v" , podNameSlice ))
367+ opts . logger .Info (fmt .Sprintf ("Capturing on specific pods: %v" , podNameSlice ))
369368 capture .Spec .CaptureConfiguration .CaptureTarget .PodNames = podNameSlice
370369 }
371370
372371 if opts .maxSize != 0 {
373- retinacmd . Logger .Info (fmt .Sprintf ("The capture file max size is set to %dMB" , opts .maxSize ))
372+ opts . logger .Info (fmt .Sprintf ("The capture file max size is set to %dMB" , opts .maxSize ))
374373 capture .Spec .CaptureConfiguration .CaptureOption .MaxCaptureSize = & opts .maxSize
375374 }
376375
377376 if opts .packetSize != 0 {
378- retinacmd . Logger .Info (fmt .Sprintf ("The capture packet size is set to %d bytes" , opts .packetSize ))
377+ opts . logger .Info (fmt .Sprintf ("The capture packet size is set to %d bytes" , opts .packetSize ))
379378 capture .Spec .CaptureConfiguration .CaptureOption .PacketSize = & opts .packetSize
380379 }
381380
@@ -384,7 +383,7 @@ func createCaptureF(ctx context.Context, kubeClient kubernetes.Interface) (*reti
384383 for i := range interfaceSlice {
385384 interfaceSlice [i ] = strings .TrimSpace (interfaceSlice [i ])
386385 }
387- retinacmd . Logger .Info (fmt .Sprintf ("Capturing on specific interfaces: %v" , interfaceSlice ))
386+ opts . logger .Info (fmt .Sprintf ("Capturing on specific interfaces: %v" , interfaceSlice ))
388387 capture .Spec .CaptureConfiguration .CaptureOption .Interfaces = interfaceSlice
389388 }
390389
@@ -446,7 +445,7 @@ func getCLICaptureConfig() config.CaptureConfig {
446445}
447446
448447func createJobs (ctx context.Context , kubeClient kubernetes.Interface , capture * retinav1alpha1.Capture ) ([]batchv1.Job , error ) {
449- translator := pkgcapture .NewCaptureToPodTranslator (kubeClient , retinacmd . Logger , getCLICaptureConfig ())
448+ translator := pkgcapture .NewCaptureToPodTranslator (kubeClient , opts . logger , getCLICaptureConfig ())
450449 jobs , err := translator .TranslateCaptureToJobs (ctx , capture )
451450 if err != nil {
452451 return nil , err
@@ -459,7 +458,7 @@ func createJobs(ctx context.Context, kubeClient kubernetes.Interface, capture *r
459458 return nil , err
460459 }
461460 jobsCreated = append (jobsCreated , * jobCreated )
462- retinacmd . Logger .Info ("Packet capture job is created" , zap .String ("namespace" , * opts .Namespace ), zap .String ("capture job" , jobCreated .Name ))
461+ opts . logger .Info ("Packet capture job is created" , zap .String ("namespace" , * opts .Namespace ), zap .String ("capture job" , jobCreated .Name ))
463462 }
464463 return jobsCreated , nil
465464}
@@ -478,7 +477,7 @@ func waitUntilJobsComplete(ctx context.Context, kubeClient kubernetes.Interface,
478477 if period < opts .duration / 10 {
479478 period = opts .duration / 10
480479 }
481- retinacmd . Logger .Info (fmt .Sprintf ("Waiting timeout is set to %s" , deadline ))
480+ opts . logger .Info (fmt .Sprintf ("Waiting timeout is set to %s" , deadline ))
482481
483482 ctx , cancel := context .WithTimeout (ctx , deadline )
484483 defer cancel ()
@@ -490,7 +489,7 @@ func waitUntilJobsComplete(ctx context.Context, kubeClient kubernetes.Interface,
490489 for _ , job := range jobs {
491490 jobRet , err := kubeClient .BatchV1 ().Jobs (job .Namespace ).Get (ctx , job .Name , metav1.GetOptions {})
492491 if err != nil {
493- retinacmd . Logger .Error ("Failed to get job" , zap .String ("namespace" , job .Namespace ), zap .String ("job name" , job .Name ), zap .Error (err ))
492+ opts . logger .Error ("Failed to get job" , zap .String ("namespace" , job .Namespace ), zap .String ("job name" , job .Name ), zap .Error (err ))
494493 jobsIncompleted = append (jobsIncompleted , job .Name )
495494 continue
496495 }
@@ -502,7 +501,7 @@ func waitUntilJobsComplete(ctx context.Context, kubeClient kubernetes.Interface,
502501 }
503502
504503 if len (jobsIncompleted ) != 0 {
505- retinacmd . Logger .Info ("Not all jobs are completed" ,
504+ opts . logger .Info ("Not all jobs are completed" ,
506505 zap .String ("namespace" , * opts .Namespace ),
507506 zap .String ("Completed jobs" , strings .Join (jobsCompleted , "," )),
508507 zap .String ("Uncompleted packet capture jobs" , strings .Join (jobsIncompleted , "," )),
@@ -528,7 +527,7 @@ func deleteJobs(ctx context.Context, kubeClient kubernetes.Interface, jobs []bat
528527 })
529528 if err != nil {
530529 jobsFailedtoDelete = append (jobsFailedtoDelete , job .Name )
531- retinacmd . Logger .Error ("Failed to delete job" , zap .String ("namespace" , job .Namespace ), zap .String ("job name" , job .Name ), zap .Error (err ))
530+ opts . logger .Error ("Failed to delete job" , zap .String ("namespace" , job .Namespace ), zap .String ("job name" , job .Name ), zap .Error (err ))
532531 }
533532 }
534533 return jobsFailedtoDelete
0 commit comments