@@ -168,6 +168,7 @@ func (o *options) validate() error {
168168
169169// run runs the flare command
170170func (o * options ) run (cmd * cobra.Command ) error {
171+ ctx := cmd .Context ()
171172 // Prepare base directory
172173 baseDir := filepath .Join (os .TempDir (), "datadog-operator" )
173174 if err := os .MkdirAll (baseDir , os .ModePerm ); err != nil {
@@ -206,7 +207,7 @@ func (o *options) run(cmd *cobra.Command) error {
206207 }
207208
208209 // Collect operator version
209- if err = o .createVersionFile (leaderPod , baseDir , cmd ); err != nil {
210+ if err = o .createVersionFile (ctx , leaderPod , baseDir , cmd ); err != nil {
210211 cmd .Println (fmt .Sprintf ("Couldn't collect operator version: %v" , err ))
211212 }
212213
@@ -217,7 +218,7 @@ func (o *options) run(cmd *cobra.Command) error {
217218 }
218219
219220 // Get the operator version
220- version , err := o .getVersion (leaderPod )
221+ version , err := o .getVersion (ctx , leaderPod )
221222 if err != nil {
222223 cmd .Println (fmt .Sprintf ("Couldn't get operator version: %v" , err ))
223224
@@ -358,14 +359,14 @@ func (o *options) createStatusFile(pod *corev1.Pod, dir string, cmd *cobra.Comma
358359}
359360
360361// createVersionFile gets the version from the operator pod and stores it in a file
361- func (o * options ) createVersionFile (pod * corev1.Pod , dir string , cmd * cobra.Command ) error {
362+ func (o * options ) createVersionFile (ctx context. Context , pod * corev1.Pod , dir string , cmd * cobra.Command ) error {
362363 if pod == nil {
363364 return errors .New ("nil leader pod" )
364365 }
365366
366367 // Prepare command and execute it
367368 versionCmd := []string {"bash" , "-c" , "/usr/local/bin/datadog-operator --version --version-format text" }
368- version , err := o .execInPod (versionCmd , pod )
369+ version , err := o .execInPod (ctx , versionCmd , pod )
369370 if err != nil {
370371 return err
371372 }
@@ -374,14 +375,14 @@ func (o *options) createVersionFile(pod *corev1.Pod, dir string, cmd *cobra.Comm
374375}
375376
376377// getOperatorVersion gets the version from the operator pod
377- func (o * options ) getVersion (pod * corev1.Pod ) (string , error ) {
378+ func (o * options ) getVersion (ctx context. Context , pod * corev1.Pod ) (string , error ) {
378379 if pod == nil {
379380 return "" , errors .New ("nil leader pod" )
380381 }
381382
382383 // Prepare command and execute it
383384 versionCmd := []string {"bash" , "-c" , "/usr/local/bin/datadog-operator --version --version-format json" }
384- versionJSON , err := o .execInPod (versionCmd , pod )
385+ versionJSON , err := o .execInPod (ctx , versionCmd , pod )
385386 if err != nil {
386387 return "" , err
387388 }
@@ -425,7 +426,7 @@ func (o *options) getLeader() (*corev1.Pod, error) {
425426}
426427
427428// execInPod execs a given command in a given pod
428- func (o * options ) execInPod (command []string , pod * corev1.Pod ) ([]byte , error ) {
429+ func (o * options ) execInPod (ctx context. Context , command []string , pod * corev1.Pod ) ([]byte , error ) {
429430 req := o .Clientset .CoreV1 ().RESTClient ().Post ().
430431 Resource ("pods" ).
431432 Name (pod .Name ).
@@ -458,7 +459,7 @@ func (o *options) execInPod(command []string, pod *corev1.Pod) ([]byte, error) {
458459 }
459460
460461 var stdout bytes.Buffer
461- if err := exec .StreamWithContext (context . TODO () , remotecommand.StreamOptions {Stdout : & stdout }); err != nil {
462+ if err := exec .StreamWithContext (ctx , remotecommand.StreamOptions {Stdout : & stdout }); err != nil {
462463 return []byte {}, err
463464 }
464465
0 commit comments