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 <madhupr007@gmail.com>
This commit is contained in:
Madhu Rajanna 2021-07-28 09:19:33 +05:30 committed by mergify[bot]
parent 9f0af30735
commit 2071c535fa

View File

@ -1241,13 +1241,19 @@ func (ka kubectlAction) String() string {
// retryKubectlInput takes a namespace and action telling kubectl what to do, // retryKubectlInput takes a namespace and action telling kubectl what to do,
// it then feeds data through stdin to the process. This function retries until // it then feeds data through stdin to the process. This function retries until
// no error occurred, or the timeout passed. // 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 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() start := time.Now()
return wait.PollImmediate(poll, timeout, func() (bool, error) { 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 err != nil {
if isRetryableAPIError(err) { if isRetryableAPIError(err) {
return false, nil return false, nil
@ -1256,8 +1262,9 @@ func retryKubectlInput(namespace string, action kubectlAction, data string, t in
return true, nil return true, nil
} }
e2elog.Logf( e2elog.Logf(
"will run kubectl (%s) again (%d seconds elapsed)", "will run kubectl (%s) args (%s) again (%d seconds elapsed)",
action, action,
args,
int(time.Since(start).Seconds())) int(time.Since(start).Seconds()))
return false, fmt.Errorf("failed to run kubectl: %w", err) return false, fmt.Errorf("failed to run kubectl: %w", err)
@ -1268,15 +1275,21 @@ func retryKubectlInput(namespace string, action kubectlAction, data string, t in
} }
// retryKubectlFile takes a namespace and action telling kubectl what to do // retryKubectlFile takes a namespace and action telling kubectl what to do
// with the passed filename. This function retries until no error occurred, or // with the passed filename and arguments. This function retries until no error
// the timeout passed. // occurred, or the timeout passed.
func retryKubectlFile(namespace string, action kubectlAction, filename string, t int) error { func retryKubectlFile(namespace string, action kubectlAction, filename string, t int, args ...string) error {
timeout := time.Duration(t) * time.Minute 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() start := time.Now()
return wait.PollImmediate(poll, timeout, func() (bool, error) { 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 err != nil {
if isRetryableAPIError(err) { if isRetryableAPIError(err) {
return false, nil return false, nil
@ -1285,9 +1298,10 @@ func retryKubectlFile(namespace string, action kubectlAction, filename string, t
return true, nil return true, nil
} }
e2elog.Logf( 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, action,
filename, filename,
args,
int(time.Since(start).Seconds())) int(time.Since(start).Seconds()))
return false, fmt.Errorf("failed to run kubectl: %w", err) return false, fmt.Errorf("failed to run kubectl: %w", err)