Skip to content

Commit

Permalink
add runtime null check
Browse files Browse the repository at this point in the history
  • Loading branch information
daeho-ro committed Mar 26, 2024
1 parent 0c9057d commit a78390a
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions internal/ecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (p *execs) getTask() {

var taskArns []string
pager := ecs.NewListTasksPaginator(&p.client, &ecs.ListTasksInput{
Cluster: &p.cluster,
Cluster: &p.cluster,
DesiredStatus: types.DesiredStatusRunning,
})

Expand Down Expand Up @@ -193,10 +193,15 @@ func (p *execs) getTask() {
}

for _, task := range listTaskDetails.Tasks {
createdDt := task.CreatedAt.Format("2006-01-02 15:04:05")
taskID := strings.Split(*task.TaskArn, "/")[2]
taskDefinition := strings.Split(*task.TaskDefinitionArn, "/")[1]
tasks = append(tasks, fmt.Sprintf("%s | %s | %s", createdDt, taskID, taskDefinition))
for _, container := range task.Containers {
createdDt := task.CreatedAt.Format("2006-01-02 15:04:05")
runtime := container.RuntimeId
if runtime != nil {
taskId := *container.RuntimeId
taskDefinition := strings.Split(*task.TaskDefinitionArn, "/")[1]
tasks = append(tasks, fmt.Sprintf("%s | %-43s | %s", createdDt, taskId, taskDefinition))
}
}
}
}
if len(tasks) == 0 {
Expand All @@ -211,8 +216,8 @@ func (p *execs) getTask() {
return
}
var taskInfo = strings.Split(selected, " | ")
p.task = taskInfo[0]
p.runtime = fmt.Sprintf("%s-%s", p.task, taskInfo[2])
p.task = strings.Split(taskInfo[1], "_")[0]
p.runtime = taskInfo[1]
p.step <- "runExecuteCommand"
}

Expand All @@ -224,6 +229,7 @@ func (p *execs) runExecuteCommand() {
output, err := p.client.ExecuteCommand(context.TODO(), &ecs.ExecuteCommandInput{
Cluster: &p.cluster,
Task: &p.task,
Container: &p.runtime,
Interactive: true,
Command: &p.command,
})
Expand Down

0 comments on commit a78390a

Please sign in to comment.