Skip to content

Commit

Permalink
tt
Browse files Browse the repository at this point in the history
  • Loading branch information
hirenko-v committed Sep 27, 2024
1 parent 5db7951 commit a832561
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions cmd/job/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import (
"fmt"
"log"
"os"
"strconv"
"strings"
"time"

go_plugin "github.com/hashicorp/go-plugin"
"github.com/kubeshop/botkube/pkg/api"
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down

0 comments on commit a832561

Please sign in to comment.