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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: check for role attached to instance profile and create if it doe… #372

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions controllers/providers/aws/iam.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,12 @@
createdProfile = out.InstanceProfile
time.Sleep(DefaultInstanceProfilePropagationDelay)

_, err = w.IamClient.AddRoleToInstanceProfile(&iam.AddRoleToInstanceProfileInput{
} else {
createdProfile = instanceProfile

Check warning on line 218 in controllers/providers/aws/iam.go

View check run for this annotation

Codecov / codecov/patch

controllers/providers/aws/iam.go#L217-L218

Added lines #L217 - L218 were not covered by tests
}

if createdProfile != nil && len(createdProfile.Roles) == 0 {
_, err := w.IamClient.AddRoleToInstanceProfile(&iam.AddRoleToInstanceProfileInput{

Check warning on line 222 in controllers/providers/aws/iam.go

View check run for this annotation

Codecov / codecov/patch

controllers/providers/aws/iam.go#L221-L222

Added lines #L221 - L222 were not covered by tests
InstanceProfileName: aws.String(name),
RoleName: aws.String(name),
})
Expand All @@ -224,10 +229,9 @@
return createdRole, createdProfile, errors.Wrap(err, "failed to attach instance-profile")
}
}
} else {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there an indentation problem from line 226?

createdProfile.Roles = append(createdProfile.Roles, createdRole)

Check warning on line 233 in controllers/providers/aws/iam.go

View check run for this annotation

Codecov / codecov/patch

controllers/providers/aws/iam.go#L232-L233

Added lines #L232 - L233 were not covered by tests
}

} else {
createdProfile = instanceProfile
}

return createdRole, createdProfile, nil
Expand Down
1 change: 1 addition & 0 deletions controllers/provisioners/eks/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ func TestCreateManagedRoleNegative(t *testing.T) {
g.Expect(ctx.GetState()).To(gomega.Equal(v1alpha1.ReconcileModifying))
iamMock.WaitUntilInstanceProfileExistsErr = nil
iamMock.CreateInstanceProfileErr = nil
iamMock.InstanceProfile = &iam.InstanceProfile{}

iamMock.AddRoleToInstanceProfileErr = awserr.New(iam.ErrCodeNoSuchEntityException, "", errors.New("some-error"))
err = ctx.Create()
Expand Down
Loading