From b17d037f5a7a703410fc2eb6de11ae74010f3f16 Mon Sep 17 00:00:00 2001 From: cPu1 Date: Thu, 25 Apr 2024 21:26:59 +0530 Subject: [PATCH 1/2] Fix creating pod identities Replaces usage of a per-loop variable with a per-iteration variable. --- pkg/actions/podidentityassociation/creator.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/actions/podidentityassociation/creator.go b/pkg/actions/podidentityassociation/creator.go index aa49ce7838..f79878010d 100644 --- a/pkg/actions/podidentityassociation/creator.go +++ b/pkg/actions/podidentityassociation/creator.go @@ -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, @@ -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, }) } @@ -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) From 3a18083eb7ba0e4021fb45a55955c37b1206b8fb Mon Sep 17 00:00:00 2001 From: cPu1 Date: Thu, 25 Apr 2024 22:27:00 +0530 Subject: [PATCH 2/2] Fix deleting pod identities --- pkg/actions/podidentityassociation/deleter.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pkg/actions/podidentityassociation/deleter.go b/pkg/actions/podidentityassociation/deleter.go index 12c3ffe564..01cebbaca0 100644 --- a/pkg/actions/podidentityassociation/deleter.go +++ b/pkg/actions/podidentityassociation/deleter.go @@ -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 },