From a832561263131fdc9505e37033bccaeaa97551cd Mon Sep 17 00:00:00 2001 From: hirenko-v Date: Fri, 27 Sep 2024 03:11:47 +0300 Subject: [PATCH] tt --- cmd/job/main.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/cmd/job/main.go b/cmd/job/main.go index b5b77fc..589d2b2 100644 --- a/cmd/job/main.go +++ b/cmd/job/main.go @@ -6,9 +6,7 @@ import ( "fmt" "log" "os" - "strconv" "strings" - "time" go_plugin "github.com/hashicorp/go-plugin" "github.com/kubeshop/botkube/pkg/api" @@ -133,9 +131,7 @@ func (e *MsgExecutor) Execute(ctx context.Context, in executor.ExecuteInput) (ex case "run": fields := strings.Fields(value) args := fields[2:] - jobName := fmt.Sprintf("%s-%s",fields[0], strconv.FormatInt(time.Now().Unix(), 10)) - filePath := fmt.Sprintf("/tmp/%s.json",jobName) - runCmd := fmt.Sprintf("kubectl create job --from=cronjob/%s -n %s %s --dry-run -ojson", fields[0], fields[1], jobName) + runCmd := fmt.Sprintf("kubectl create job --from=cronjob/%s -n %s test --dry-run -ojson", fields[0], fields[1]) out, _ := plugin.ExecuteCommand(ctx, runCmd, plugin.ExecuteCommandEnvs(envs)) err = os.WriteFile("/tmp/stdout.json", []byte(out.Stdout), 0644) // Create or overwrite the file if err != nil { @@ -162,14 +158,14 @@ func (e *MsgExecutor) Execute(ctx context.Context, in executor.ExecuteInput) (ex } // // Save the patched JSON to a file - err = os.WriteFile(filePath, modifiedJSON, 0644) // Create or overwrite the file + err = os.WriteFile("/tmp/patched_cronjob.json", modifiedJSON, 0644) // Create or overwrite the file if err != nil { log.Fatalf("error writing patched JSON to file: %w", err) } - createCmd := fmt.Sprintf("kubectl apply -f %s", filePath) + createCmd := fmt.Sprintf("kubectl apply -f /tmp/patched_cronjob.json") plugin.ExecuteCommand(ctx, createCmd, plugin.ExecuteCommandEnvs(envs)) return executor.ExecuteOutput{ - Message: api.NewCodeBlockMessage(fmt.Sprintf("Job, %s started",jobName), true), + Message: api.NewCodeBlockMessage(fmt.Sprintf("saved, %s",args), true), }, nil }