From 98f96d20647129bf84073d65b9fed1521499f10e Mon Sep 17 00:00:00 2001 From: Usman Date: Mon, 12 Dec 2022 10:08:52 +0100 Subject: [PATCH] Fix parsing kubectl output with warnings (#470) * Fix for getting deployments Don't parse error output (e.g. deprecation warnings) when trying to list deployments. Signed-off-by: Usman * Fix more output parsing Signed-off-by: usmonster Signed-off-by: Usman Signed-off-by: usmonster --- pkg/tool/kubectl.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/tool/kubectl.go b/pkg/tool/kubectl.go index 5ad72f0..2a32817 100644 --- a/pkg/tool/kubectl.go +++ b/pkg/tool/kubectl.go @@ -70,7 +70,7 @@ func (k Kubectl) DeleteNamespace(namespace string) { func (k Kubectl) forceNamespaceDeletion(namespace string) error { // Getting the namespace json to remove the finalizer - cmdOutput, err := k.exec.RunProcessAndCaptureOutput("kubectl", + cmdOutput, err := k.exec.RunProcessAndCaptureStdout("kubectl", fmt.Sprintf("--request-timeout=%s", k.timeout), "get", "namespace", namespace, "--output=json") if err != nil { @@ -146,7 +146,7 @@ func (k Kubectl) forceNamespaceDeletion(namespace string) error { } func (k Kubectl) WaitForDeployments(namespace string, selector string) error { - output, err := k.exec.RunProcessAndCaptureOutput("kubectl", + output, err := k.exec.RunProcessAndCaptureStdout("kubectl", fmt.Sprintf("--request-timeout=%s", k.timeout), "get", "deployments", "--namespace", namespace, "--selector", selector, "--output", "jsonpath={.items[*].metadata.name}") @@ -169,7 +169,7 @@ func (k Kubectl) WaitForDeployments(namespace string, selector string) error { // // Just after rollout, pods from the previous deployment revision may still be in a // terminating state. - unavailable, err := k.exec.RunProcessAndCaptureOutput("kubectl", + unavailable, err := k.exec.RunProcessAndCaptureStdout("kubectl", fmt.Sprintf("--request-timeout=%s", k.timeout), "get", "deployment", deployment, "--namespace", namespace, "--output", `jsonpath={.status.unavailableReplicas}`) @@ -185,7 +185,7 @@ func (k Kubectl) WaitForDeployments(namespace string, selector string) error { } func (k Kubectl) GetPodsforDeployment(namespace string, deployment string) ([]string, error) { - jsonString, _ := k.exec.RunProcessAndCaptureOutput("kubectl", + jsonString, _ := k.exec.RunProcessAndCaptureStdout("kubectl", fmt.Sprintf("--request-timeout=%s", k.timeout), "get", "deployment", deployment, "--namespace", namespace, "--output=json") var deploymentMap map[string]interface{} @@ -211,7 +211,7 @@ func (k Kubectl) GetPodsforDeployment(namespace string, deployment string) ([]st func (k Kubectl) GetPods(args ...string) ([]string, error) { kubectlArgs := []string{"get", "pods"} kubectlArgs = append(kubectlArgs, args...) - pods, err := k.exec.RunProcessAndCaptureOutput("kubectl", + pods, err := k.exec.RunProcessAndCaptureStdout("kubectl", fmt.Sprintf("--request-timeout=%s", k.timeout), kubectlArgs) if err != nil { return nil, err