Skip to content

Commit ab1e2af

Browse files
committed
WIP: attempt to make EC2 runner work (again)
Tool: gitpod/catfood.gitpod.cloud
1 parent f47bd71 commit ab1e2af

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

gitpod-network-check/gitpod-network-check.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ log-level: debug # Options: debug, info, warning, error
22
region: eu-central-1
33
main-subnets: subnet-017c6a80f4879d851, subnet-0215744d52cd1c01f
44
https-hosts: accounts.google.com, https://github.com
5+
instance-ami: ami-0a0bfc6462a1bba50
56
# put your custom ami id here if you want to use it, otherwise it will using latest ubuntu AMI from aws
67
#instance-ami:
78
# optional, put your API endpoint regional sub-domain here to test connectivity, like when the execute-api vpc endpoint is not in the same account as Gitpod

gitpod-network-check/pkg/runner/ec2-runner.go

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,18 @@ func (r *EC2TestRunner) isServiceAvailable(ctx context.Context, instanceIds []st
305305

306306
g, ctx := errgroup.WithContext(context.Background())
307307
for _, instanceId := range instanceIds {
308-
id := instanceId // Local variable for the closure
308+
id := instanceId
309309
g.Go(func() error {
310+
// wait up until 30s for each command to actually execute
311+
waiter := ssm.NewCommandExecutedWaiter(r.ssmClient)
312+
err := waiter.Wait(ctx, &ssm.GetCommandInvocationInput{
313+
CommandId: aws.String(commandId),
314+
InstanceId: aws.String(id),
315+
}, *aws.Duration(30 * time.Second))
316+
if err != nil {
317+
return fmt.Errorf("error waiting for command to finish: %v", err)
318+
}
319+
310320
return fetchResultsForInstance(ctx, r.ssmClient, id, commandId)
311321
})
312322
}
@@ -439,11 +449,32 @@ func findUbuntuAMI(ctx context.Context, client *ec2.Client) (string, error) {
439449

440450
func ensureSessionManagerIsUp(ctx context.Context, ssmClient *ssm.Client, instanceIds []string) error {
441451
err := wait.PollUntilContextTimeout(ctx, 500*time.Millisecond, 2*time.Minute, true, func(ctx context.Context) (done bool, err error) {
442-
_, err = sendCommand(ctx, ssmClient, instanceIds, "echo ssm")
452+
commandId, err := sendCommand(ctx, ssmClient, instanceIds, "echo ssm")
443453
if err != nil {
444454
return false, nil
445455
}
446456

457+
// wait for 10s for the command to actually execute
458+
g, ctx := errgroup.WithContext(context.Background())
459+
for _, iid := range instanceIds {
460+
instanceId := iid
461+
g.Go(func() error {
462+
waiter := ssm.NewCommandExecutedWaiter(ssmClient)
463+
err := waiter.Wait(ctx, &ssm.GetCommandInvocationInput{
464+
CommandId: aws.String(commandId),
465+
InstanceId: aws.String(instanceId),
466+
}, *aws.Duration(10 * time.Second))
467+
if err != nil {
468+
return fmt.Errorf("error waiting for command to finish: %v", err)
469+
}
470+
return nil
471+
})
472+
}
473+
err = g.Wait()
474+
if err != nil {
475+
return false, fmt.Errorf("error waiting for SessionManager to run test command: %v", err)
476+
}
477+
447478
return true, nil
448479
})
449480

@@ -675,7 +706,7 @@ func fetchResultsForInstance(ctx context.Context, svc *ssm.Client, instanceId, c
675706
log.Debugf("✅ Instance %s command output:\n%s\n", instanceId, *invocationResult.StandardOutputContent)
676707
return true, nil
677708
} else {
678-
log.Errorf("❌ Instance %s command with status %s not successful:\n%s\n", instanceId, *invocationResult.StatusDetails, *invocationResult.StandardErrorContent)
709+
log.Errorf("❌ Instance %s command with status %s, not successful:\n%s\n", instanceId, *invocationResult.StatusDetails, *invocationResult.StandardErrorContent)
679710
return false, fmt.Errorf("instance %s command failed: %s", instanceId, *invocationResult.StandardErrorContent)
680711
}
681712
})

0 commit comments

Comments
 (0)