From f7e150b84f5065e3c36af217f1cdd81d455ec7ab Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Wed, 28 Jul 2021 09:19:33 +0530 Subject: [PATCH] e2e: pass variadic argument to kubectl helper function this provides caller ability to pass the arguments like ignore-not-found=true etc when executing the kubectl commands. Signed-off-by: Madhu Rajanna (cherry picked from commit 2071c535fa32bc83f4189ed6dce55d2a2892371f) --- e2e/utils.go | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/e2e/utils.go b/e2e/utils.go index e51874af7..ac639f97d 100644 --- a/e2e/utils.go +++ b/e2e/utils.go @@ -1227,13 +1227,19 @@ func (ka kubectlAction) String() string { // retryKubectlInput takes a namespace and action telling kubectl what to do, // it then feeds data through stdin to the process. This function retries until // no error occurred, or the timeout passed. -func retryKubectlInput(namespace string, action kubectlAction, data string, t int) error { +func retryKubectlInput(namespace string, action kubectlAction, data string, t int, args ...string) error { timeout := time.Duration(t) * time.Minute - e2elog.Logf("waiting for kubectl (%s) to finish", action) + e2elog.Logf("waiting for kubectl (%s -f %q args %s) to finish", action, args) start := time.Now() return wait.PollImmediate(poll, timeout, func() (bool, error) { - _, err := framework.RunKubectlInput(namespace, data, string(action), "-f", "-") + cmd := []string{} + if len(args) != 0 { + cmd = append(cmd, strings.Join(args, "")) + } + cmd = append(cmd, []string{string(action), "-f", "-"}...) + + _, err := framework.RunKubectlInput(namespace, data, cmd...) if err != nil { if isRetryableAPIError(err) { return false, nil @@ -1242,8 +1248,9 @@ func retryKubectlInput(namespace string, action kubectlAction, data string, t in return true, nil } e2elog.Logf( - "will run kubectl (%s) again (%d seconds elapsed)", + "will run kubectl (%s) args (%s) again (%d seconds elapsed)", action, + args, int(time.Since(start).Seconds())) return false, fmt.Errorf("failed to run kubectl: %w", err) @@ -1254,15 +1261,21 @@ func retryKubectlInput(namespace string, action kubectlAction, data string, t in } // retryKubectlFile takes a namespace and action telling kubectl what to do -// with the passed filename. This function retries until no error occurred, or -// the timeout passed. -func retryKubectlFile(namespace string, action kubectlAction, filename string, t int) error { +// with the passed filename and arguments. This function retries until no error +// occurred, or the timeout passed. +func retryKubectlFile(namespace string, action kubectlAction, filename string, t int, args ...string) error { timeout := time.Duration(t) * time.Minute - e2elog.Logf("waiting for kubectl (%s -f %q) to finish", action, filename) + e2elog.Logf("waiting for kubectl (%s -f %q args %s) to finish", action, filename, args) start := time.Now() return wait.PollImmediate(poll, timeout, func() (bool, error) { - _, err := framework.RunKubectl(namespace, string(action), "-f", filename) + cmd := []string{} + if len(args) != 0 { + cmd = append(cmd, strings.Join(args, "")) + } + cmd = append(cmd, []string{string(action), "-f", filename}...) + + _, err := framework.RunKubectl(namespace, cmd...) if err != nil { if isRetryableAPIError(err) { return false, nil @@ -1271,9 +1284,10 @@ func retryKubectlFile(namespace string, action kubectlAction, filename string, t return true, nil } e2elog.Logf( - "will run kubectl (%s -f %q) again (%d seconds elapsed)", + "will run kubectl (%s -f %q args %s) again (%d seconds elapsed)", action, filename, + args, int(time.Since(start).Seconds())) return false, fmt.Errorf("failed to run kubectl: %w", err)