Skip to content

Commit a1b4f1d

Browse files
authored
Fail if execute-api service is insufficient (#17)
* Fail if execute-api service is insufficient The check must pass if either is true: * a VPC endpoint with private DNS is enabled in this account * the api-endpoint parameter has a value and pases the connectivity test (note: this defers private DNS until the cell tries to connect) * Improve logging * Be consistent with waiter timeouts * Spacing * Spacing
1 parent 9ed4045 commit a1b4f1d

File tree

2 files changed

+28
-19
lines changed

2 files changed

+28
-19
lines changed

gitpod-network-check/cmd/checks.go

+25-16
Original file line numberDiff line numberDiff line change
@@ -66,32 +66,33 @@ var checkCommand = &cobra.Command{ // nolint:gochecknoglobals
6666
log.Infof("ℹ️ Found duplicate subnets. We'll test each subnet '%v' only once.", distinctSubnets)
6767
}
6868

69-
log.Infof("ℹ️ Launching EC2 instances in Main subnets")
69+
log.Info("ℹ️ Launching EC2 instances in Main subnets")
7070
mainInstanceIds, err := launchInstances(cmd.Context(), ec2Client, networkConfig.MainSubnets, instanceProfile.Arn)
7171
if err != nil {
7272
return err
7373
}
7474
log.Infof("ℹ️ Main EC2 instances: %v", mainInstanceIds)
7575
InstanceIds = append(InstanceIds, mainInstanceIds...)
7676

77-
log.Infof("ℹ️ Launching EC2 instances in a Pod subnets")
77+
log.Info("ℹ️ Launching EC2 instances in a Pod subnets")
7878
podInstanceIds, err := launchInstances(cmd.Context(), ec2Client, networkConfig.PodSubnets, instanceProfile.Arn)
7979
if err != nil {
8080
return err
8181
}
8282
log.Infof("ℹ️ Pod EC2 instances: %v", podInstanceIds)
8383
InstanceIds = append(InstanceIds, podInstanceIds...)
8484

85-
log.Infof("ℹ️ Waiting for EC2 instances to become Running (times out in 4 minutes)")
85+
log.Info("ℹ️ Waiting for EC2 instances to become Running (times out in 5 minutes)")
8686
runningWaiter := ec2.NewInstanceRunningWaiter(ec2Client, func(irwo *ec2.InstanceRunningWaiterOptions) {
8787
irwo.MaxDelay = 15 * time.Second
8888
irwo.MinDelay = 5 * time.Second
8989
})
90-
err = runningWaiter.Wait(cmd.Context(), &ec2.DescribeInstancesInput{InstanceIds: InstanceIds}, *aws.Duration(4 * time.Minute))
90+
err = runningWaiter.Wait(cmd.Context(), &ec2.DescribeInstancesInput{InstanceIds: InstanceIds}, *aws.Duration(5 * time.Minute))
9191
if err != nil {
9292
return fmt.Errorf("❌ Nodes never got Running: %v", err)
9393
}
94-
log.Infof("ℹ️ Waiting for EC2 instances to become Healthy (times out in 5 minutes)")
94+
log.Info("✅ EC2 instances are now Running.")
95+
log.Info("ℹ️ Waiting for EC2 instances to become Healthy (times out in 5 minutes)")
9596
waitstatusOK := ec2.NewInstanceStatusOkWaiter(ec2Client, func(isow *ec2.InstanceStatusOkWaiterOptions) {
9697
isow.MaxDelay = 15 * time.Second
9798
isow.MinDelay = 5 * time.Second
@@ -100,7 +101,7 @@ var checkCommand = &cobra.Command{ // nolint:gochecknoglobals
100101
if err != nil {
101102
return fmt.Errorf("❌ Nodes never got Healthy: %v", err)
102103
}
103-
log.Info("✅ EC2 Instances are now running successfully")
104+
log.Info("✅ EC2 Instances are now healthy/Ok")
104105

105106
log.Infof("ℹ️ Connecting to SSM...")
106107
err = ensureSessionManagerIsUp(cmd.Context(), ssmClient)
@@ -199,6 +200,7 @@ func checkSMPrerequisites(ctx context.Context, ec2Client *ec2.Client) error {
199200
},
200201
}
201202

203+
var prereqErrs []string
202204
for _, endpoint := range vpcEndpoints {
203205
response, err := ec2Client.DescribeVpcEndpoints(ctx, &ec2.DescribeVpcEndpointsInput{
204206
Filters: []types.Filter{
@@ -214,31 +216,38 @@ func checkSMPrerequisites(ctx context.Context, ec2Client *ec2.Client) error {
214216
}
215217

216218
if len(response.VpcEndpoints) == 0 {
217-
if strings.Contains(endpoint.Endpoint, "execute-api") {
218-
log.Infof("ℹ️ Deferring connectivity test for %s service until testing main subnet", endpoint.PrivateDnsName)
219+
if strings.Contains(endpoint.Endpoint, "execute-api") && networkConfig.ApiEndpoint != "" {
220+
log.Infof("ℹ️ 'api-endpoint' parameter exists, deferring connectivity test for execute-api VPC endpoint until testing main subnet connectivity")
221+
continue
222+
} else if strings.Contains(endpoint.Endpoint, "execute-api") && networkConfig.ApiEndpoint == "" {
223+
errMsg := "Add a VPC endpoint for execute-api in this account or use the 'api-endpoint' parameter to specify a centralized one in another account, and test again"
224+
log.Errorf("❌ %s", errMsg)
225+
prereqErrs = append(prereqErrs, errMsg)
219226
continue
220227
}
221-
log.Infof("ℹ️ VPC endpoint %s is not configured, testing service connectivity...", endpoint.Endpoint)
222228
_, err := TestServiceConnectivity(ctx, endpoint.PrivateDnsName, 5*time.Second)
223229
if err != nil {
224-
log.Errorf("❌ Service %s connectivity test failed: %v\n", endpoint.PrivateDnsName, err)
225-
} else if endpoint.PrivateDnsRequired {
226-
log.Warnf("✅ Service %s has connectivity, ensure Private DNS is enabled 🙏", endpoint.PrivateDnsName)
227-
} else if !endpoint.PrivateDnsRequired {
228-
log.Infof("✅ Service %s has connectivity", endpoint.PrivateDnsName)
230+
errMsg := fmt.Sprintf("Service %s connectivity test failed: %v\n", endpoint.PrivateDnsName, err)
231+
log.Error("❌ %w", errMsg)
232+
prereqErrs = append(prereqErrs, errMsg)
229233
}
234+
log.Infof("✅ Service %s has connectivity", endpoint.PrivateDnsName)
230235
} else {
231236
for _, e := range response.VpcEndpoints {
232237
if e.PrivateDnsEnabled != nil && !*e.PrivateDnsEnabled && endpoint.PrivateDnsRequired {
233-
log.Errorf("❌ VPC endpoint '%s' has private DNS disabled, it must be enabled", *e.VpcEndpointId)
238+
errMsg := fmt.Sprintf("VPC endpoint '%s' has private DNS disabled, it must be enabled", *e.VpcEndpointId)
239+
log.Errorf("❌ %s", errMsg)
240+
prereqErrs = append(prereqErrs, errMsg)
234241
}
235242
}
236243
log.Infof("✅ VPC endpoint %s is configured", endpoint.Endpoint)
237244
}
238245
}
239246

247+
if len(prereqErrs) > 0 {
248+
return fmt.Errorf("%s", strings.Join(prereqErrs, "; "))
249+
}
240250
return nil
241-
242251
}
243252

244253
func ensureSessionManagerIsUp(ctx context.Context, ssmClient *ssm.Client) error {

gitpod-network-check/cmd/common.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ func cleanup(ctx context.Context, svc *ec2.Client, iamsvc *iam.Client) {
7878
itwo.MaxDelay = 15 * time.Second
7979
itwo.MinDelay = 5 * time.Second
8080
})
81-
log.Info("ℹ️ Waiting for EC2 instances to Terminate (times out in 4 minutes)")
82-
err = terminateWaiter.Wait(ctx, &ec2.DescribeInstancesInput{InstanceIds: InstanceIds}, *aws.Duration(4 * time.Minute))
81+
log.Info("ℹ️ Waiting for EC2 instances to Terminate (times out in 5 minutes)")
82+
err = terminateWaiter.Wait(ctx, &ec2.DescribeInstancesInput{InstanceIds: InstanceIds}, *aws.Duration(5 * time.Minute))
8383
if err != nil {
8484
log.WithError(err).Warn("Failed to wait for instances to terminate")
85-
log.Warn("Waiting 2 minutes so network interfaces are deleted")
85+
log.Warn("ℹ️ Waiting 2 minutes so network interfaces are deleted")
8686
time.Sleep(2 * time.Minute)
8787
} else {
8888
log.Info("✅ Instances terminated")

0 commit comments

Comments
 (0)