@@ -10,7 +10,6 @@ import (
10
10
"time"
11
11
12
12
"github.com/aws/aws-sdk-go-v2/aws"
13
- "github.com/aws/aws-sdk-go-v2/config"
14
13
"github.com/aws/aws-sdk-go-v2/service/ec2"
15
14
"github.com/aws/aws-sdk-go-v2/service/ec2/types"
16
15
"github.com/aws/aws-sdk-go-v2/service/iam"
@@ -23,28 +22,6 @@ import (
23
22
"k8s.io/apimachinery/pkg/util/wait"
24
23
)
25
24
26
- const gitpodRoleName = "GitpodNetworkCheck"
27
- const gitpodInstanceProfile = "GitpodNetworkCheck"
28
-
29
- var networkCheckTag = []iam_types.Tag {
30
- {
31
- Key : aws .String ("gitpod.io/network-check" ),
32
- Value : aws .String ("true" ),
33
- },
34
- }
35
-
36
- func initAwsConfig (ctx context.Context , region string ) (aws.Config , error ) {
37
- return config .LoadDefaultConfig (ctx , config .WithRegion (region ))
38
- }
39
-
40
- // this will be useful when we are cleaning up things at the end
41
- var (
42
- InstanceIds []string
43
- SecurityGroups []string
44
- Roles []string
45
- InstanceProfile string
46
- )
47
-
48
25
var checkCommand = & cobra.Command { // nolint:gochecknoglobals
49
26
PersistentPreRunE : validateSubnets ,
50
27
Use : "diagnose" ,
@@ -272,7 +249,7 @@ func launchInstances(ctx context.Context, ec2Client *ec2.Client, subnets []strin
272
249
for _ , subnet := range subnets {
273
250
secGroup , err := createSecurityGroups (ctx , ec2Client , subnet )
274
251
if err != nil {
275
- return nil , fmt .Errorf ("❌ failed to create security group: %v" , err )
252
+ return nil , fmt .Errorf ("❌ failed to create security group for subnet '%v' : %v" , subnet , err )
276
253
}
277
254
SecurityGroups = append (SecurityGroups , secGroup )
278
255
instanceId , err := launchInstanceInSubnet (ctx , ec2Client , subnet , secGroup , profileArn )
@@ -486,64 +463,6 @@ func createSecurityGroups(ctx context.Context, svc *ec2.Client, subnetID string)
486
463
return * sgID , nil
487
464
}
488
465
489
- func cleanup (ctx context.Context , svc * ec2.Client , iamsvc * iam.Client ) {
490
- if len (InstanceIds ) > 0 {
491
- _ , err := svc .TerminateInstances (ctx , & ec2.TerminateInstancesInput {
492
- InstanceIds : InstanceIds ,
493
- })
494
- if err != nil {
495
- log .WithError (err ).WithField ("instanceIds" , InstanceIds ).Warnf ("Failed to cleanup instances, please cleanup manually" )
496
- }
497
- }
498
- if len (Roles ) > 0 {
499
- for _ , role := range Roles {
500
- _ , err := iamsvc .DetachRolePolicy (ctx , & iam.DetachRolePolicyInput {PolicyArn : aws .String ("arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore" ), RoleName : aws .String (role )})
501
- if err != nil {
502
- log .WithError (err ).WithField ("rolename" , role ).Warnf ("Failed to cleanup role, please cleanup manually" )
503
- }
504
-
505
- _ , err = iamsvc .RemoveRoleFromInstanceProfile (ctx , & iam.RemoveRoleFromInstanceProfileInput {
506
- RoleName : aws .String (role ),
507
- InstanceProfileName : aws .String (InstanceProfile ),
508
- })
509
- if err != nil {
510
- log .WithError (err ).WithField ("roleName" , role ).WithField ("profileName" , InstanceProfile ).Warnf ("Failed to remove role from instance profile" )
511
- }
512
-
513
- _ , err = iamsvc .DeleteRole (ctx , & iam.DeleteRoleInput {RoleName : aws .String (role )})
514
- if err != nil {
515
- log .WithError (err ).WithField ("rolename" , role ).Warnf ("Failed to cleanup role, please cleanup manaullay" )
516
- }
517
- }
518
-
519
- _ , err := iamsvc .DeleteInstanceProfile (ctx , & iam.DeleteInstanceProfileInput {
520
- InstanceProfileName : aws .String (InstanceProfile ),
521
- })
522
-
523
- if err != nil {
524
- log .WithError (err ).WithField ("instanceProfile" , InstanceProfile ).Warnf ("Failed to clean up instance profile, please cleanup manually" )
525
- }
526
- }
527
-
528
- log .Info ("Cleaning up: Waiting for 1 minute so network interfaces are deleted" )
529
- time .Sleep (time .Minute )
530
-
531
- if len (SecurityGroups ) > 0 {
532
- for _ , sg := range SecurityGroups {
533
- deleteSGInput := & ec2.DeleteSecurityGroupInput {
534
- GroupId : aws .String (sg ),
535
- }
536
-
537
- _ , err := svc .DeleteSecurityGroup (ctx , deleteSGInput )
538
- if err != nil {
539
- log .WithError (err ).WithField ("securityGroup" , sg ).Warnf ("Failed to clean up security group, please cleanup manually" )
540
- }
541
-
542
- }
543
-
544
- }
545
- }
546
-
547
466
func createIAMRoleAndAttachPolicy (ctx context.Context , svc * iam.Client ) (* iam_types.Role , error ) {
548
467
// Define the trust relationship
549
468
trustPolicy := `{
0 commit comments