From b8eaba79ce9c9e39ffdfb576e6beabb7ef23304b Mon Sep 17 00:00:00 2001 From: miyamo2 Date: Sat, 30 Nov 2024 19:26:41 +0900 Subject: [PATCH] refactor: `wait job` handling --- cmd/create_transient_configmap.go | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/cmd/create_transient_configmap.go b/cmd/create_transient_configmap.go index 655b74d..8dd8d80 100644 --- a/cmd/create_transient_configmap.go +++ b/cmd/create_transient_configmap.go @@ -267,11 +267,11 @@ func (o *TransientConfigMapOptions) Run(cmd *cobra.Command) (err error) { go func() { waitJobCompleteArgs := append(waitJobArgs, jobName, "--for=condition=complete") _, wErr := executeKubectlCommand(waitJobContext, waitJobCompleteArgs...) - if wErr != nil { - select { - case <-waitJobContext.Done(): - return - default: + select { + case <-waitJobContext.Done(): + return + default: + if wErr != nil { if err == nil { err = wErr } @@ -284,14 +284,12 @@ func (o *TransientConfigMapOptions) Run(cmd *cobra.Command) (err error) { go func() { waitJobFailedArgs := append(waitJobArgs, jobName, "--for=condition=failed") _, wErr := executeKubectlCommand(waitJobContext, waitJobFailedArgs...) - if wErr != nil { - select { - case <-waitJobContext.Done(): - return - default: - if err == nil { - err = wErr - } + select { + case <-waitJobContext.Done(): + return + default: + if wErr != nil && err == nil { + err = wErr } } complete <- false