Skip to content

Commit

Permalink
Remove ambiguious name
Browse files Browse the repository at this point in the history
  • Loading branch information
qbart committed Dec 13, 2022
1 parent 2fa0141 commit 905f68e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
32 changes: 16 additions & 16 deletions awscmd/ecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ type InputEcsDeploy struct {
}

type OuputEcsDeploy struct {
Service string
PrimaryDeploymentID string
Service string
MonitoredDeploymentID string
}

func EcsDeploy(ctx context.Context, input *InputEcsDeploy) (*OuputEcsDeploy, error) {
Expand Down Expand Up @@ -84,23 +84,23 @@ func EcsDeploy(ctx context.Context, input *InputEcsDeploy) (*OuputEcsDeploy, err
if err != nil {
return nil, fmt.Errorf("Failed to update service with new task revision: %w", err)
}
var primaryDeployment *ecs.Deployment = nil
var monitoredDeployment *ecs.Deployment = nil
for _, deployment := range updateOut.Service.Deployments {
if *deployment.Status == "PRIMARY" {
primaryDeployment = deployment
monitoredDeployment = deployment
break
}
}

if primaryDeployment == nil {
if monitoredDeployment == nil {
return &OuputEcsDeploy{
Service: *updateOut.Service.ServiceName,
}, fmt.Errorf("Service %s deployed but couldn't fetch primary deployment status", *updateOut.Service.ServiceName)
}

return &OuputEcsDeploy{
Service: *updateOut.Service.ServiceName,
PrimaryDeploymentID: *primaryDeployment.Id,
Service: *updateOut.Service.ServiceName,
MonitoredDeploymentID: *monitoredDeployment.Id,
}, nil
}

Expand Down Expand Up @@ -139,27 +139,27 @@ func EcsDeployWait(ctx context.Context, input *InputEcsDeployWait, w io.Writer)
return nil, fmt.Errorf("Ambigious match, found more than 1 service")
}

var primaryDeployment *ecs.Deployment = nil
var monitoredDeployment *ecs.Deployment = nil
for _, deployment := range serviceOut.Services[0].Deployments {
if *deployment.Id == input.DeploymentID {
primaryDeployment = deployment
monitoredDeployment = deployment
break
}
}

if primaryDeployment == nil {
if monitoredDeployment == nil {
return nil, fmt.Errorf("Failed to monitor service deployment")
}

fmt.Fprintf(w, "%s%d%s Running | %s%d%s Pending | %s%d%s Desired (Attempt %d, retrying in 10s)\n",
ctc.ForegroundGreen, *primaryDeployment.RunningCount, ctc.Reset,
ctc.ForegroundYellow, *primaryDeployment.PendingCount, ctc.Reset,
ctc.ForegroundRed, *primaryDeployment.DesiredCount, ctc.Reset,
fmt.Fprintf(w, "%s%d%s Running | %s%d%s Pending | %s%d%s Desired (Check %d, retrying in 10s)\n",
ctc.ForegroundGreen, *monitoredDeployment.RunningCount, ctc.Reset,
ctc.ForegroundYellow, *monitoredDeployment.PendingCount, ctc.Reset,
ctc.ForegroundRed, *monitoredDeployment.DesiredCount, ctc.Reset,
attempt,
)

if *primaryDeployment.RolloutState != "IN_PROGRESS" {
completed := (*primaryDeployment.RolloutState == "COMPLETED")
if *monitoredDeployment.RolloutState != "IN_PROGRESS" {
completed := (*monitoredDeployment.RolloutState == "COMPLETED")
if completed {
return &OuputEcsDeployWait{}, nil
} else {
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func main() {
Region: c.String("region"),
Cluster: c.String("cluster"),
Service: c.String("service"),
DeploymentID: out.PrimaryDeploymentID,
DeploymentID: out.MonitoredDeploymentID,
}
_, err = awscmd.EcsDeployWait(context.TODO(), waitInput, c.App.Writer)
if err != nil {
Expand All @@ -187,7 +187,7 @@ func main() {

fmt.Fprintf(
c.App.Writer,
"%sDeployment for service `%s` finished%s\n",
"%sDeployment for service `%s` reached stable state%s\n",
ctc.ForegroundGreen,
out.Service,
ctc.Reset,
Expand Down

0 comments on commit 905f68e

Please sign in to comment.