Skip to content

Commit

Permalink
tt
Browse files Browse the repository at this point in the history
  • Loading branch information
hirenko-v committed Oct 1, 2024
1 parent 9706361 commit 9c06e33
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions cmd/job/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,25 @@ func (MsgExecutor) Metadata(context.Context) (api.MetadataOutput, error) {

// Execute returns a given command as a response.
func (e *MsgExecutor) Execute(ctx context.Context, in executor.ExecuteInput) (executor.ExecuteOutput, error) {

// Kubernetes client setup
kubeConfigPath, deleteFn, err := plugin.PersistKubeConfig(ctx, in.Context.KubeConfig)
if err != nil {
log.Fatalf("Error writing kubeconfig file: %v", err)
}
defer func() {
if deleteErr := deleteFn(ctx); deleteErr != nil {
fmt.Fprintf(os.Stderr, "failed to delete kubeconfig file %s: %v", kubeConfigPath, deleteErr)
}
}()
envs := map[string]string{
"KUBECONFIG": kubeConfigPath,
}
if err != nil {
log.Fatalf("Error creating Kubernetes client: %v", err)
}
slackState := in.Context.SlackState
details := e.extractStateDetails(slackState)
envs, _ := generateKubeconfigEnvs(ctx, in)

// Parse the action and value from the command
action, value := parseCommand(in.Command)
Expand Down Expand Up @@ -193,25 +209,6 @@ func (e *MsgExecutor) extractStateDetails(state *slack.BlockActionStates) stateD
return details
}

func generateKubeconfigEnvs(ctx context.Context, in executor.ExecuteInput) (map[string]string, error) {
// Kubernetes client setup
kubeConfigPath, deleteFn, err := plugin.PersistKubeConfig(ctx, in.Context.KubeConfig)
if err != nil {
log.Fatalf("Error writing kubeconfig file: %v", err)
}
defer func() {
if deleteErr := deleteFn(ctx); deleteErr != nil {
fmt.Fprintf(os.Stderr, "failed to delete kubeconfig file %s: %v", kubeConfigPath, deleteErr)
}
}()
envs := map[string]string{
"KUBECONFIG": kubeConfigPath,
}
if err != nil {
log.Fatalf("Error creating Kubernetes client: %v", err)
}
return envs, nil
}

// parseCommand parses the input command into action and value
func parseCommand(cmd string) (action, value string) {
Expand Down

0 comments on commit 9c06e33

Please sign in to comment.