remove support for helmv2 in loadtester

Signed-off-by: Sanskar Jaiswal <sanskar.jaiswal@weave.works>
This commit is contained in:
Sanskar Jaiswal
2022-03-08 19:29:00 +05:30
parent 090329d0c9
commit 5acf189fbe
5 changed files with 8 additions and 108 deletions

View File

@@ -1,58 +0,0 @@
/*
Copyright 2020 The Flux authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package loadtester
import (
"context"
"fmt"
"os/exec"
"strings"
)
const TaskTypeHelm = "helm"
type HelmTask struct {
TaskBase
command string
logCmdOutput bool
}
func (task *HelmTask) Hash() string {
return hash(task.canary + task.command)
}
func (task *HelmTask) Run(ctx context.Context) (*TaskRunResult, error) {
helmCmd := fmt.Sprintf("%s %s", TaskTypeHelm, task.command)
task.logger.With("canary", task.canary).Infof("running command %v", helmCmd)
cmd := exec.CommandContext(ctx, TaskTypeHelm, 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 {
fmt.Printf("%s\n", out)
}
task.logger.With("canary", task.canary).Infof("command finished %v", helmCmd)
}
return &TaskRunResult{true, out}, nil
}
func (task *HelmTask) String() string {
return task.command
}

View File

@@ -1,5 +1,5 @@
/*
Copyright 2020 The Flux authors
Copyright 2020, 2022 The Flux authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -24,6 +24,7 @@ import (
)
const TaskTypeHelmv3 = "helmv3"
const TaskTypeHelm = "helm"
type HelmTaskv3 struct {
TaskBase
@@ -39,7 +40,7 @@ func (task *HelmTaskv3) Run(ctx context.Context) (*TaskRunResult, error) {
helmCmd := fmt.Sprintf("%s %s", TaskTypeHelmv3, task.command)
task.logger.With("canary", task.canary).Infof("running command %v", helmCmd)
cmd := exec.CommandContext(ctx, TaskTypeHelmv3, strings.Fields(task.command)...)
cmd := exec.CommandContext(ctx, TaskTypeHelm, 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)

View File

@@ -1,5 +1,5 @@
/*
Copyright 2020 The Flux authors
Copyright 2020, 2022 The Flux authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -335,36 +335,8 @@ func HandleNewTask(logger *zap.SugaredLogger, taskRunner TaskRunnerInterface, au
return
}
// run helm command (blocking task)
if typ == TaskTypeHelm {
helm := HelmTask{
command: payload.Metadata["cmd"],
logCmdOutput: true,
TaskBase: TaskBase{
canary: fmt.Sprintf("%s.%s", payload.Name, payload.Namespace),
logger: logger,
},
}
ctx, cancel := context.WithTimeout(context.Background(), taskRunner.Timeout())
defer cancel()
result, err := helm.Run(ctx)
if !result.ok {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error()))
return
}
w.WriteHeader(http.StatusOK)
if rtnCmdOutput {
w.Write(result.out)
}
return
}
// run helmv3 command (blocking task)
if typ == TaskTypeHelmv3 {
if typ == TaskTypeHelmv3 || typ == TaskTypeHelm {
helm := HelmTaskv3{
command: payload.Metadata["cmd"],
logCmdOutput: true,