Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update iamserviceaccount role policies #3064

Merged
merged 19 commits into from Jan 22, 2021
Merged

Update iamserviceaccount role policies #3064

merged 19 commits into from Jan 22, 2021

Conversation

aclevername
Copy link
Contributor

@aclevername aclevername commented Jan 12, 2021

Description

Adds support for updating the policies to an existing IAMServiceAccount.

The implementation flow is very similar to create, but rather than creating a stack & service account it just applys a change set to the existing stack.

Related issue: #1497

Checklist

  • Added tests that cover your change (if possible)
  • Added/modified documentation as required (such as the README.md, or the userdocs directory)
  • Manually tested
  • Made sure the title of the PR is a good description that can go into the release notes
  • (Core team) Added labels for change area (e.g. area/nodegroup), target version (e.g. version/0.12.0) and kind (e.g. kind/improvement)

BONUS POINTS checklist: complete for good vibes and maybe prizes?! 馃く

  • Backfilled missing tests for code in same general area 馃帀
  • Refactored something and made the world a better place 馃専

@aclevername aclevername added area/aws-iam kind/feature New feature or request labels Jan 13, 2021
pkg/eks/tasks.go Outdated Show resolved Hide resolved
@aclevername
Copy link
Contributor Author

As part of moving everything into actions/iam the refactor was getting too large and messy for this PR, I'm going to split it out into another PR to make the diff easier to understand

Comment on lines 1 to 18
package iam

import (
api "github.com/weaveworks/eksctl/pkg/apis/eksctl.io/v1alpha5"
"github.com/weaveworks/eksctl/pkg/ctl/cmdutils"
"github.com/weaveworks/eksctl/pkg/kubernetes"
)

func (a *Manager) CreateIAMServiceAccount(iamServiceAccounts []*api.ClusterIAMServiceAccount, plan bool) error {
taskTree := a.stackManager.NewTasksToCreateIAMServiceAccounts(iamServiceAccounts, a.oidcManager, kubernetes.NewCachedClientSet(a.clientSet))
taskTree.PlanMode = plan

err := doTasks(taskTree)

cmdutils.LogPlanModeWarning(plan && len(iamServiceAccounts) > 0)

return err
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've left this here for now, if folks want me to remove this small refactor and put it into the refactor PR let me know.

@aclevername aclevername marked this pull request as ready for review January 14, 2021 14:55
@aclevername aclevername requested a review from a team January 14, 2021 14:55
Copy link
Contributor

@Callisto13 Callisto13 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 馃憤


func doTasks(taskTree *tasks.TaskTree) error {
logger.Info(taskTree.Describe())
if errs := taskTree.DoAllSync(); len(errs) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm doesn't this exist in some form in the tasks package?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't see anything 馃

func (t *updateIAMServiceAccountTask) Do(errorCh chan error) error {
stackName := makeIAMServiceAccountStackName(t.clusterName, t.sa.Namespace, t.sa.Name)
go func() {
errorCh <- nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see this is done elsewhere in the code with tasks, is this necessary? I'm assuming something won't make progress but I feel like functions should be EITHER only returning synchronous errors OR only sending errors over a channel. Making a note to myself

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I was unsure regarding this too. I don't know why we have two ways of returning errors, I understand that we need the channel for when the Do sends off a go routine and returns, but when its just a single process it could just return the err down the channel anyway, removing the need for the returning error completely

is this necessary

I believe we have to otherwise it will block?

}

var templateBody manager.TemplateBody = template
taskTree := UpdateIAMServiceAccountTask(a.clusterName, iamServiceAccount, a.stackManager, templateBody)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't this whole loop body be done async inside the task?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the top part of the loop that checks if the SA exists should remain here to ensure it gets checked when --approve is false. Your right though the resource set part can get moved, I will move it.

Copy link
Contributor

@michaelbeaumont michaelbeaumont left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above


if len(stacks) == 0 {
logger.Info("Cannot update IAMServiceAccount %s/%s as it does not exist", iamServiceAccount.Namespace, iamServiceAccount.Name)
nonExistingSAs = append(nonExistingSAs, fmt.Sprintf("%s/%s", iamServiceAccount.Namespace, iamServiceAccount.Name))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be handled by the exclude/include filters?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't spot that we used filtering for create iamserviceaccount, I'll update it so we use that here too on second thought the filtering code looks to be a bit more complicated than needed, here we only care about stacks that exist and were listed, we don't need a more robust exclude/include functionality. I also like this business logic sitting here

Copy link
Collaborator

@cPu1 cPu1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 馃帀

pkg/actions/iam/update.go Outdated Show resolved Hide resolved
pkg/actions/iam/update.go Outdated Show resolved Hide resolved
aclevername and others added 2 commits January 20, 2021 11:45
Co-authored-by: Chetan Patwal <cPu1@users.noreply.github.com>
Co-authored-by: Chetan Patwal <cPu1@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/aws-iam kind/feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants