Skip to content

Commit

Permalink
Parse output for KubeExecAll (#4532)
Browse files Browse the repository at this point in the history
  • Loading branch information
SupriyaKasten authored and Ilya Kislenko committed Dec 8, 2018
1 parent ff5051d commit 7296ec8
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions pkg/function/kube_exec_all.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,17 @@ func (*kubeExecAllFunc) Exec(ctx context.Context, tp param.TemplateParams, args
}
ps := strings.Fields(pods)
cs := strings.Fields(containers)
return nil, execAll(cli, namespace, ps, cs, cmd)
return execAll(cli, namespace, ps, cs, cmd)
}

func (*kubeExecAllFunc) RequiredArgs() []string {
return []string{KubeExecAllNamespaceArg, KubeExecAllPodsNameArg, KubeExecAllContainersNameArg, KubeExecAllCommandArg}
}

func execAll(cli kubernetes.Interface, namespace string, ps []string, cs []string, cmd []string) error {
func execAll(cli kubernetes.Interface, namespace string, ps []string, cs []string, cmd []string) (map[string]interface{}, error) {
numContainers := len(ps) * len(cs)
errChan := make(chan error, numContainers)
output := ""
// Run the command
for _, p := range ps {
for _, c := range cs {
Expand All @@ -73,6 +74,7 @@ func execAll(cli kubernetes.Interface, namespace string, ps []string, cs []strin
format.Log(p, c, stdout)
format.Log(p, c, stderr)
errChan <- err
output = output + "\n" + stdout
}(p, c)
}
}
Expand All @@ -84,7 +86,11 @@ func execAll(cli kubernetes.Interface, namespace string, ps []string, cs []strin
}
}
if len(errs) != 0 {
return errors.New(strings.Join(errs, "\n"))
return nil, errors.New(strings.Join(errs, "\n"))
}
return nil
out, err := parseLogAndCreateOutput(output)
if err != nil {
return nil, err
}
return out, nil
}

0 comments on commit 7296ec8

Please sign in to comment.