Skip to content

Commit e564978

Browse files
committed
Fix role cleanup
1 parent ae2681e commit e564978

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

gitpod-network-check/cmd/common.go

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -74,30 +74,29 @@ func cleanup(ctx context.Context, svc *ec2.Client, iamsvc *iam.Client) {
7474
}
7575

7676
if len(Roles) == 0 {
77-
roles, err := iamsvc.ListRoles(ctx, &iam.ListRolesInput{
78-
PathPrefix: aws.String("/GitpodNetworkCheck"),
79-
})
80-
if err != nil {
81-
log.WithError(err).Warn("Failed to list roles, please cleanup manually")
82-
} else if len(roles.Roles) == 0 {
83-
log.Info("No roles found.")
84-
}
85-
86-
for _, role := range roles.Roles {
87-
if role.RoleName == nil {
88-
continue
77+
paginator := iam.NewListInstanceProfilesPaginator(iamsvc, &iam.ListInstanceProfilesInput{})
78+
for paginator.HasMorePages() {
79+
output, err := paginator.NextPage(ctx)
80+
if err != nil {
81+
log.WithError(err).Warn("Failed to list roles, please cleanup manually")
82+
break
8983
}
9084

91-
if *role.RoleName == gitpodRoleName {
92-
Roles = append(Roles, *role.RoleName)
85+
for _, ip := range output.InstanceProfiles {
86+
if *ip.InstanceProfileName == gitpodInstanceProfile {
87+
{
88+
InstanceProfile = *ip.InstanceProfileName
89+
if len(ip.Roles) > 0 {
90+
for _, role := range ip.Roles {
91+
Roles = append(Roles, *role.RoleName)
92+
}
93+
}
94+
}
95+
}
9396
}
9497
}
9598
}
9699

97-
if InstanceProfile == "" {
98-
InstanceProfile = gitpodInstanceProfile
99-
}
100-
101100
if len(Roles) > 0 {
102101
for _, role := range Roles {
103102
_, err := iamsvc.DetachRolePolicy(ctx, &iam.DetachRolePolicyInput{PolicyArn: aws.String("arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore"), RoleName: aws.String(role)})

0 commit comments

Comments
 (0)