forked from fluxcd/flagger
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request fluxcd#1461 from fluxcd/dependabot/github_actions/…
…helm/kind-action-1.8.0 build(deps): bump helm/kind-action from 1.7.0 to 1.8.0 Signed-off-by: bin.hu <[email protected]> flagger load tester support kubectl
- Loading branch information
Showing
4 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package loadtester | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os/exec" | ||
"strings" | ||
) | ||
|
||
const TaskTypeKubectl = "kubectl" | ||
|
||
type KubectlTask struct { | ||
TaskBase | ||
command string | ||
logCmdOutput bool | ||
} | ||
|
||
func (task *KubectlTask) Hash() string { | ||
return hash(task.canary + task.command) | ||
} | ||
|
||
func (task *KubectlTask) Run(ctx context.Context) (*TaskRunResult, error) { | ||
kubectlCmd := fmt.Sprintf("%s %s", TaskTypeKubectl, task.command) | ||
task.logger.With("canary", task.canary).Infof("running command %v", kubectlCmd) | ||
|
||
cmd := exec.CommandContext(ctx, TaskTypeKubectl, strings.Fields(task.command)...) | ||
out, err := cmd.CombinedOutput() | ||
if err != nil { | ||
task.logger.With("canary", task.canary).Errorf("command failed %s %v %s", task.command, err, out) | ||
return &TaskRunResult{false, out}, fmt.Errorf("command %s failed: %s: %w", task.command, out, err) | ||
} else { | ||
if task.logCmdOutput { | ||
task.logger.With("canary", task.canary).Info(string(out)) | ||
} | ||
task.logger.With("canary", task.canary).Infof("command finished %v", kubectlCmd) | ||
} | ||
return &TaskRunResult{true, out}, nil | ||
} | ||
|
||
func (task *KubectlTask) String() string { | ||
return task.command | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters