mirror of
https://github.com/fluxcd/flagger.git
synced 2026-04-15 06:57:34 +00:00
Add generic bash blocking command
This commit is contained in:
@@ -10,7 +10,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
var VERSION = "0.4.0-beta.2"
|
||||
var VERSION = "0.4.0-beta.5"
|
||||
var (
|
||||
logLevel string
|
||||
port string
|
||||
|
||||
@@ -6,19 +6,19 @@ import (
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
const TaskTypeBats = "bats"
|
||||
const TaskTypeBash = "bash"
|
||||
|
||||
type BatsTask struct {
|
||||
type BashTask struct {
|
||||
TaskBase
|
||||
command string
|
||||
logCmdOutput bool
|
||||
}
|
||||
|
||||
func (task *BatsTask) Hash() string {
|
||||
func (task *BashTask) Hash() string {
|
||||
return hash(task.canary + task.command)
|
||||
}
|
||||
|
||||
func (task *BatsTask) Run(ctx context.Context) (bool, error) {
|
||||
func (task *BashTask) Run(ctx context.Context) (bool, error) {
|
||||
cmd := exec.CommandContext(ctx, "bash", "-c", task.command)
|
||||
out, err := cmd.CombinedOutput()
|
||||
|
||||
@@ -34,6 +34,6 @@ func (task *BatsTask) Run(ctx context.Context) (bool, error) {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (task *BatsTask) String() string {
|
||||
func (task *BashTask) String() string {
|
||||
return task.command
|
||||
}
|
||||
@@ -46,10 +46,12 @@ func ListenAndServe(port string, timeout time.Duration, logger *zap.SugaredLogge
|
||||
}
|
||||
|
||||
// run bats command (blocking task)
|
||||
if typ == TaskTypeBats {
|
||||
bats := BatsTask{
|
||||
if typ == TaskTypeBash {
|
||||
logger.With("canary", payload.Name).Infof("bats command %s", payload.Metadata["cmd"])
|
||||
|
||||
bats := BashTask{
|
||||
command: payload.Metadata["cmd"],
|
||||
logCmdOutput: taskRunner.logCmdOutput,
|
||||
logCmdOutput: true,
|
||||
TaskBase: TaskBase{
|
||||
canary: fmt.Sprintf("%s.%s", payload.Name, payload.Namespace),
|
||||
logger: logger,
|
||||
@@ -63,6 +65,7 @@ func ListenAndServe(port string, timeout time.Duration, logger *zap.SugaredLogge
|
||||
if !ok {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write([]byte(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
@@ -73,7 +76,7 @@ func ListenAndServe(port string, timeout time.Duration, logger *zap.SugaredLogge
|
||||
if typ == TaskTypeHelm {
|
||||
helm := HelmTask{
|
||||
command: payload.Metadata["cmd"],
|
||||
logCmdOutput: taskRunner.logCmdOutput,
|
||||
logCmdOutput: true,
|
||||
TaskBase: TaskBase{
|
||||
canary: fmt.Sprintf("%s.%s", payload.Name, payload.Namespace),
|
||||
logger: logger,
|
||||
@@ -87,6 +90,7 @@ func ListenAndServe(port string, timeout time.Duration, logger *zap.SugaredLogge
|
||||
if !ok {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write([]byte(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
||||
Reference in New Issue
Block a user