Skip to content

Commit

Permalink
Merge pull request #7727 from cPu1/fix-podidentity-creation
Browse files Browse the repository at this point in the history
Fix creating pod identities
  • Loading branch information
cPu1 authored Apr 25, 2024
2 parents dfd89d8 + 3a18083 commit c9ee358
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
7 changes: 4 additions & 3 deletions pkg/actions/podidentityassociation/creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ func (c *Creator) CreateTasks(ctx context.Context, podIdentityAssociations []api
taskTree := &tasks.TaskTree{
Parallel: true,
}
for i, pia := range podIdentityAssociations {
for _, pia := range podIdentityAssociations {
pia := pia
piaCreationTasks := &tasks.TaskTree{
Parallel: false,
IsSubTask: true,
Expand All @@ -55,7 +56,7 @@ func (c *Creator) CreateTasks(ctx context.Context, podIdentityAssociations []api
ctx: ctx,
info: fmt.Sprintf("create IAM role for pod identity association for service account %q", pia.NameString()),
clusterName: c.clusterName,
podIdentityAssociation: &podIdentityAssociations[i],
podIdentityAssociation: &pia,
stackCreator: c.stackCreator,
})
}
Expand All @@ -75,7 +76,7 @@ func (c *Creator) CreateTasks(ctx context.Context, podIdentityAssociations []api
ctx: ctx,
info: fmt.Sprintf("create pod identity association for service account %q", pia.NameString()),
clusterName: c.clusterName,
podIdentityAssociation: &podIdentityAssociations[i],
podIdentityAssociation: &pia,
eksAPI: c.eksAPI,
})
taskTree.Append(piaCreationTasks)
Expand Down
13 changes: 7 additions & 6 deletions pkg/actions/podidentityassociation/deleter.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,21 @@ func (d *Deleter) DeleteTasks(ctx context.Context, podIDs []Identifier) (*tasks.
return taskTree, nil
}

for _, p := range podIDs {
for _, podID := range podIDs {
podID := podID
piaDeletionTasks := &tasks.TaskTree{
Parallel: false,
IsSubTask: true,
}
piaDeletionTasks.Append(d.makeDeleteTask(ctx, p, roleStackNames))
piaDeletionTasks.Append(d.makeDeleteTask(ctx, podID, roleStackNames))
piaDeletionTasks.Append(&tasks.GenericTask{
Description: fmt.Sprintf("delete service account %q", p.IDString()),
Description: fmt.Sprintf("delete service account %q", podID.IDString()),
Doer: func() error {
if err := kubernetes.MaybeDeleteServiceAccount(d.ClientSet, v1.ObjectMeta{
Name: p.ServiceAccountName,
Namespace: p.Namespace,
Name: podID.ServiceAccountName,
Namespace: podID.Namespace,
}); err != nil {
return fmt.Errorf("failed to delete service account %q: %w", p.IDString(), err)
return fmt.Errorf("failed to delete service account %q: %w", podID.IDString(), err)
}
return nil
},
Expand Down

0 comments on commit c9ee358

Please sign in to comment.