Skip to content

Commit

Permalink
chore: Instance Profile V2 migration (#7097)
Browse files Browse the repository at this point in the history
Co-authored-by: Amanuel Engeda <[email protected]>
  • Loading branch information
edibble21 and engedaam authored Oct 4, 2024
1 parent d6b22ce commit c2be457
Show file tree
Hide file tree
Showing 9 changed files with 257 additions and 98 deletions.
18 changes: 18 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ require (
github.com/PuerkitoBio/goquery v1.10.0
github.com/avast/retry-go v3.0.0+incompatible
github.com/aws/aws-sdk-go v1.55.5
github.com/aws/aws-sdk-go-v2 v1.31.0
github.com/aws/aws-sdk-go-v2/config v1.26.6
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.11
github.com/aws/aws-sdk-go-v2/service/ec2 v1.177.3
github.com/aws/aws-sdk-go-v2/service/iam v1.36.2
github.com/aws/karpenter-provider-aws/tools/kompat v0.0.0-20240410220356-6b868db24881
github.com/aws/smithy-go v1.21.0
github.com/awslabs/amazon-eks-ami/nodeadm v0.0.0-20240229193347-cfab22a10647
github.com/awslabs/operatorpkg v0.0.0-20240920182301-771460b3160b
github.com/go-logr/zapr v1.3.0
Expand Down Expand Up @@ -35,6 +41,18 @@ require (
sigs.k8s.io/yaml v1.4.0
)

require (
github.com/aws/aws-sdk-go-v2/credentials v1.16.16 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.18 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.18 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.7.3 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.4 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.19 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.18.7 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.21.7 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.26.7 // indirect
)

require (
github.com/Masterminds/semver/v3 v3.2.1 // indirect
github.com/andybalholm/cascadia v1.3.2 // indirect
Expand Down
30 changes: 30 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,38 @@ github.com/avast/retry-go v3.0.0+incompatible h1:4SOWQ7Qs+oroOTQOYnAHqelpCO0biHS
github.com/avast/retry-go v3.0.0+incompatible/go.mod h1:XtSnn+n/sHqQIpZ10K1qAevBhOOCWBLXXy3hyiqqBrY=
github.com/aws/aws-sdk-go v1.55.5 h1:KKUZBfBoyqy5d3swXyiC7Q76ic40rYcbqH7qjh59kzU=
github.com/aws/aws-sdk-go v1.55.5/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU=
github.com/aws/aws-sdk-go-v2 v1.31.0 h1:3V05LbxTSItI5kUqNwhJrrrY1BAXxXt0sN0l72QmG5U=
github.com/aws/aws-sdk-go-v2 v1.31.0/go.mod h1:ztolYtaEUtdpf9Wftr31CJfLVjOnD/CVRkKOOYgF8hA=
github.com/aws/aws-sdk-go-v2/config v1.26.6 h1:Z/7w9bUqlRI0FFQpetVuFYEsjzE3h7fpU6HuGmfPL/o=
github.com/aws/aws-sdk-go-v2/config v1.26.6/go.mod h1:uKU6cnDmYCvJ+pxO9S4cWDb2yWWIH5hra+32hVh1MI4=
github.com/aws/aws-sdk-go-v2/credentials v1.16.16 h1:8q6Rliyv0aUFAVtzaldUEcS+T5gbadPbWdV1WcAddK8=
github.com/aws/aws-sdk-go-v2/credentials v1.16.16/go.mod h1:UHVZrdUsv63hPXFo1H7c5fEneoVo9UXiz36QG1GEPi0=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.11 h1:c5I5iH+DZcH3xOIMlz3/tCKJDaHFwYEmxvlh2fAcFo8=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.11/go.mod h1:cRrYDYAMUohBJUtUnOhydaMHtiK/1NZ0Otc9lIb6O0Y=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.18 h1:kYQ3H1u0ANr9KEKlGs/jTLrBFPo8P8NaH/w7A01NeeM=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.18/go.mod h1:r506HmK5JDUh9+Mw4CfGJGSSoqIiLCndAuqXuhbv67Y=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.18 h1:Z7IdFUONvTcvS7YuhtVxN99v2cCoHRXOS4mTr0B/pUc=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.18/go.mod h1:DkKMmksZVVyat+Y+r1dEOgJEfUeA7UngIHWeKsi0yNc=
github.com/aws/aws-sdk-go-v2/internal/ini v1.7.3 h1:n3GDfwqF2tzEkXlv5cuy4iy7LpKDtqDMcNLfZDu9rls=
github.com/aws/aws-sdk-go-v2/internal/ini v1.7.3/go.mod h1:6fQQgfuGmw8Al/3M2IgIllycxV7ZW7WCdVSqfBeUiCY=
github.com/aws/aws-sdk-go-v2/service/ec2 v1.177.3 h1:dqdCh1M8h+j8OGNUpxTs7eBPFr6lOdLpdlE6IPLLSq4=
github.com/aws/aws-sdk-go-v2/service/ec2 v1.177.3/go.mod h1:TFSALWR7Xs7+KyMM87ZAYxncKFBvzEt2rpK/BJCH2ps=
github.com/aws/aws-sdk-go-v2/service/iam v1.36.2 h1:2/kSYD8hfRU/q1HbgSzZ4PGiDmzDwtPSYgJq4yxF6bs=
github.com/aws/aws-sdk-go-v2/service/iam v1.36.2/go.mod h1:HSvujsK8xeEHMIB18oMXjSfqaN9cVqpo/MtHJIksQRk=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.4 h1:KypMCbLPPHEmf9DgMGw51jMj77VfGPAN2Kv4cfhlfgI=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.4/go.mod h1:Vz1JQXliGcQktFTN/LN6uGppAIRoLBR2bMvIMP0gOjc=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.19 h1:rfprUlsdzgl7ZL2KlXiUAoJnI/VxfHCvDFr2QDFj6u4=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.19/go.mod h1:SCWkEdRq8/7EK60NcvvQ6NXKuTcchAD4ROAsC37VEZE=
github.com/aws/aws-sdk-go-v2/service/sso v1.18.7 h1:eajuO3nykDPdYicLlP3AGgOyVN3MOlFmZv7WGTuJPow=
github.com/aws/aws-sdk-go-v2/service/sso v1.18.7/go.mod h1:+mJNDdF+qiUlNKNC3fxn74WWNN+sOiGOEImje+3ScPM=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.21.7 h1:QPMJf+Jw8E1l7zqhZmMlFw6w1NmfkfiSK8mS4zOx3BA=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.21.7/go.mod h1:ykf3COxYI0UJmxcfcxcVuz7b6uADi1FkiUz6Eb7AgM8=
github.com/aws/aws-sdk-go-v2/service/sts v1.26.7 h1:NzO4Vrau795RkUdSHKEwiR01FaGzGOH1EETJ+5QHnm0=
github.com/aws/aws-sdk-go-v2/service/sts v1.26.7/go.mod h1:6h2YuIoxaMSCFf5fi1EgZAwdfkGMgDY+DVfa61uLe4U=
github.com/aws/karpenter-provider-aws/tools/kompat v0.0.0-20240410220356-6b868db24881 h1:m9rhsGhdepdQV96tZgfy68oU75AWAjOH8u65OefTjwA=
github.com/aws/karpenter-provider-aws/tools/kompat v0.0.0-20240410220356-6b868db24881/go.mod h1:+Mk5k0b6HpKobxNq+B56DOhZ+I/NiPhd5MIBhQMSTSs=
github.com/aws/smithy-go v1.21.0 h1:H7L8dtDRk0P1Qm6y0ji7MCYMQObJ5R9CRpyPhRUkLYA=
github.com/aws/smithy-go v1.21.0/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg=
github.com/awslabs/amazon-eks-ami/nodeadm v0.0.0-20240229193347-cfab22a10647 h1:8yRBVsjGmI7qQsPWtIrbWP+XfwHO9Wq7gdLVzjqiZFs=
github.com/awslabs/amazon-eks-ami/nodeadm v0.0.0-20240229193347-cfab22a10647/go.mod h1:9NafTAUHL0FlMeL6Cu5PXnMZ1q/LnC9X2emLXHsVbM8=
github.com/awslabs/operatorpkg v0.0.0-20240920182301-771460b3160b h1:aG1+YRmKIf5nLTZJNhw1NmuxvjUprWYyluqJ2jmVqiU=
Expand Down
32 changes: 32 additions & 0 deletions pkg/aws/sdk.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package sdk

import (
"context"

"github.com/aws/aws-sdk-go-v2/service/iam"
)

type IAMAPI interface {
// IAM Methods
GetInstanceProfile(context.Context, *iam.GetInstanceProfileInput, ...func(*iam.Options)) (*iam.GetInstanceProfileOutput, error)
CreateInstanceProfile(context.Context, *iam.CreateInstanceProfileInput, ...func(*iam.Options)) (*iam.CreateInstanceProfileOutput, error)
DeleteInstanceProfile(context.Context, *iam.DeleteInstanceProfileInput, ...func(*iam.Options)) (*iam.DeleteInstanceProfileOutput, error)
AddRoleToInstanceProfile(context.Context, *iam.AddRoleToInstanceProfileInput, ...func(*iam.Options)) (*iam.AddRoleToInstanceProfileOutput, error)
TagInstanceProfile(context.Context, *iam.TagInstanceProfileInput, ...func(*iam.Options)) (*iam.TagInstanceProfileOutput, error)
RemoveRoleFromInstanceProfile(context.Context, *iam.RemoveRoleFromInstanceProfileInput, ...func(*iam.Options)) (*iam.RemoveRoleFromInstanceProfileOutput, error)
UntagInstanceProfile(context.Context, *iam.UntagInstanceProfileInput, ...func(*iam.Options)) (*iam.UntagInstanceProfileOutput, error)
}
32 changes: 16 additions & 16 deletions pkg/controllers/nodeclass/status/instanceprofile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ package status_test
import (
"fmt"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/iam"
"github.com/aws/aws-sdk-go-v2/aws"
iamtypes "github.com/aws/aws-sdk-go-v2/service/iam/types"
"github.com/samber/lo"

v1 "github.com/aws/karpenter-provider-aws/pkg/apis/v1"
Expand All @@ -45,17 +45,17 @@ var _ = Describe("NodeClass InstanceProfile Status Controller", func() {
Expect(awsEnv.IAMAPI.InstanceProfiles[profileName].Roles).To(HaveLen(1))
Expect(*awsEnv.IAMAPI.InstanceProfiles[profileName].Roles[0].RoleName).To(Equal("test-role"))
Expect(awsEnv.IAMAPI.InstanceProfiles[profileName].Tags).To(ContainElements(
&iam.Tag{Key: lo.ToPtr(fmt.Sprintf("kubernetes.io/cluster/%s", options.FromContext(ctx).ClusterName)), Value: lo.ToPtr("owned")},
&iam.Tag{Key: lo.ToPtr(v1.LabelNodeClass), Value: lo.ToPtr(nodeClass.Name)},
&iam.Tag{Key: lo.ToPtr(v1.EKSClusterNameTagKey), Value: lo.ToPtr(options.FromContext(ctx).ClusterName)},
iamtypes.Tag{Key: lo.ToPtr(fmt.Sprintf("kubernetes.io/cluster/%s", options.FromContext(ctx).ClusterName)), Value: lo.ToPtr("owned")},
iamtypes.Tag{Key: lo.ToPtr(v1.LabelNodeClass), Value: lo.ToPtr(nodeClass.Name)},
iamtypes.Tag{Key: lo.ToPtr(v1.EKSClusterNameTagKey), Value: lo.ToPtr(options.FromContext(ctx).ClusterName)},
))

nodeClass = ExpectExists(ctx, env.Client, nodeClass)
Expect(nodeClass.Status.InstanceProfile).To(Equal(profileName))
Expect(nodeClass.StatusConditions().IsTrue(v1.ConditionTypeInstanceProfileReady)).To(BeTrue())
})
It("should add the role to the instance profile when it exists without a role", func() {
awsEnv.IAMAPI.InstanceProfiles = map[string]*iam.InstanceProfile{
awsEnv.IAMAPI.InstanceProfiles = map[string]*iamtypes.InstanceProfile{
profileName: {
InstanceProfileId: aws.String(fake.InstanceProfileID()),
InstanceProfileName: aws.String(profileName),
Expand All @@ -75,11 +75,11 @@ var _ = Describe("NodeClass InstanceProfile Status Controller", func() {
Expect(nodeClass.StatusConditions().IsTrue(v1.ConditionTypeInstanceProfileReady)).To(BeTrue())
})
It("should update the role for the instance profile when the wrong role exists", func() {
awsEnv.IAMAPI.InstanceProfiles = map[string]*iam.InstanceProfile{
awsEnv.IAMAPI.InstanceProfiles = map[string]*iamtypes.InstanceProfile{
profileName: {
InstanceProfileId: aws.String(fake.InstanceProfileID()),
InstanceProfileName: aws.String(profileName),
Roles: []*iam.Role{
Roles: []iamtypes.Role{
{
RoleName: aws.String("other-role"),
},
Expand All @@ -100,16 +100,16 @@ var _ = Describe("NodeClass InstanceProfile Status Controller", func() {
Expect(nodeClass.StatusConditions().IsTrue(v1.ConditionTypeInstanceProfileReady)).To(BeTrue())
})
It("should add the eks:eks-cluster-name tag when the tag doesn't exist", func() {
awsEnv.IAMAPI.InstanceProfiles = map[string]*iam.InstanceProfile{
awsEnv.IAMAPI.InstanceProfiles = map[string]*iamtypes.InstanceProfile{
profileName: {
InstanceProfileId: aws.String(fake.InstanceProfileID()),
InstanceProfileName: aws.String(profileName),
Roles: []*iam.Role{
Roles: []iamtypes.Role{
{
RoleName: aws.String("other-role"),
},
},
Tags: []*iam.Tag{
Tags: []iamtypes.Tag{
{
Key: lo.ToPtr(fmt.Sprintf("kubernetes.io/cluster/%s", options.FromContext(ctx).ClusterName)),
Value: lo.ToPtr("owned"),
Expand All @@ -127,17 +127,17 @@ var _ = Describe("NodeClass InstanceProfile Status Controller", func() {

Expect(awsEnv.IAMAPI.InstanceProfiles).To(HaveLen(1))
Expect(awsEnv.IAMAPI.InstanceProfiles[profileName].Tags).To(ContainElements(
&iam.Tag{Key: lo.ToPtr(fmt.Sprintf("kubernetes.io/cluster/%s", options.FromContext(ctx).ClusterName)), Value: lo.ToPtr("owned")},
&iam.Tag{Key: lo.ToPtr(v1.LabelNodeClass), Value: lo.ToPtr(nodeClass.Name)},
&iam.Tag{Key: lo.ToPtr(v1.EKSClusterNameTagKey), Value: lo.ToPtr(options.FromContext(ctx).ClusterName)},
iamtypes.Tag{Key: lo.ToPtr(fmt.Sprintf("kubernetes.io/cluster/%s", options.FromContext(ctx).ClusterName)), Value: lo.ToPtr("owned")},
iamtypes.Tag{Key: lo.ToPtr(v1.LabelNodeClass), Value: lo.ToPtr(nodeClass.Name)},
iamtypes.Tag{Key: lo.ToPtr(v1.EKSClusterNameTagKey), Value: lo.ToPtr(options.FromContext(ctx).ClusterName)},
))
})
It("should not call CreateInstanceProfile or AddRoleToInstanceProfile when instance profile exists with correct role", func() {
awsEnv.IAMAPI.InstanceProfiles = map[string]*iam.InstanceProfile{
awsEnv.IAMAPI.InstanceProfiles = map[string]*iamtypes.InstanceProfile{
profileName: {
InstanceProfileId: aws.String(fake.InstanceProfileID()),
InstanceProfileName: aws.String(profileName),
Roles: []*iam.Role{
Roles: []iamtypes.Role{
{
RoleName: aws.String("test-role"),
},
Expand Down
32 changes: 17 additions & 15 deletions pkg/controllers/nodeclass/termination/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ import (

"sigs.k8s.io/karpenter/pkg/test/v1alpha1"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go-v2/aws"
ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types"
iamtypes "github.com/aws/aws-sdk-go-v2/service/iam/types"

//used for launch template tests until they are migrated
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/iam"

"github.com/awslabs/operatorpkg/object"
"github.com/samber/lo"
"k8s.io/client-go/tools/record"
Expand Down Expand Up @@ -109,7 +113,7 @@ var _ = Describe("NodeClass Termination", func() {
})
It("should not delete the NodeClass if launch template deletion fails", func() {
launchTemplateName := aws.String(fake.LaunchTemplateName())
awsEnv.EC2API.LaunchTemplates.Store(launchTemplateName, &ec2.LaunchTemplate{LaunchTemplateName: launchTemplateName, LaunchTemplateId: aws.String(fake.LaunchTemplateID()), Tags: []*ec2.Tag{&ec2.Tag{Key: aws.String("karpenter.k8s.aws/cluster"), Value: aws.String("test-cluster")}}})
awsEnv.EC2API.LaunchTemplates.Store(launchTemplateName, &ec2types.LaunchTemplate{LaunchTemplateName: launchTemplateName, LaunchTemplateId: aws.String(fake.LaunchTemplateID()), Tags: []ec2types.Tag{{Key: aws.String("karpenter.k8s.aws/cluster"), Value: aws.String("test-cluster")}}})
_, ok := awsEnv.EC2API.LaunchTemplates.Load(launchTemplateName)
Expect(ok).To(BeTrue())
controllerutil.AddFinalizer(nodeClass, v1.TerminationFinalizer)
Expand All @@ -123,7 +127,7 @@ var _ = Describe("NodeClass Termination", func() {
})
It("should not delete the launch template not associated with the nodeClass", func() {
launchTemplateName := aws.String(fake.LaunchTemplateName())
awsEnv.EC2API.LaunchTemplates.Store(launchTemplateName, &ec2.LaunchTemplate{LaunchTemplateName: launchTemplateName, LaunchTemplateId: aws.String(fake.LaunchTemplateID()), Tags: []*ec2.Tag{&ec2.Tag{Key: aws.String("karpenter.k8s.aws/cluster"), Value: aws.String("test-cluster")}}})
awsEnv.EC2API.LaunchTemplates.Store(launchTemplateName, &ec2.LaunchTemplate{LaunchTemplateName: launchTemplateName, LaunchTemplateId: aws.String(fake.LaunchTemplateID()), Tags: []*ec2.Tag{{Key: aws.String("karpenter.k8s.aws/cluster"), Value: aws.String("test-cluster")}}})
_, ok := awsEnv.EC2API.LaunchTemplates.Load(launchTemplateName)
Expect(ok).To(BeTrue())
controllerutil.AddFinalizer(nodeClass, v1.TerminationFinalizer)
Expand All @@ -138,17 +142,16 @@ var _ = Describe("NodeClass Termination", func() {
})
It("should succeed to delete the launch template", func() {
ltName1 := aws.String(fake.LaunchTemplateName())
awsEnv.EC2API.LaunchTemplates.Store(ltName1, &ec2.LaunchTemplate{LaunchTemplateName: ltName1, LaunchTemplateId: aws.String(fake.LaunchTemplateID()), Tags: []*ec2.Tag{&ec2.Tag{Key: aws.String("karpenter.k8s.aws/cluster"), Value: aws.String("test-cluster")}, {Key: aws.String("karpenter.k8s.aws/ec2nodeclass"), Value: aws.String(nodeClass.Name)}}})
awsEnv.EC2API.LaunchTemplates.Store(ltName1, &ec2.LaunchTemplate{LaunchTemplateName: ltName1, LaunchTemplateId: aws.String(fake.LaunchTemplateID()), Tags: []*ec2.Tag{{Key: aws.String("karpenter.k8s.aws/cluster"), Value: aws.String("test-cluster")}, {Key: aws.String("karpenter.k8s.aws/ec2nodeclass"), Value: aws.String(nodeClass.Name)}}})
ltName2 := aws.String(fake.LaunchTemplateName())
awsEnv.EC2API.LaunchTemplates.Store(ltName2, &ec2.LaunchTemplate{LaunchTemplateName: ltName2, LaunchTemplateId: aws.String(fake.LaunchTemplateID()), Tags: []*ec2.Tag{&ec2.Tag{Key: aws.String("karpenter.k8s.aws/cluster"), Value: aws.String("test-cluster")}, {Key: aws.String("karpenter.k8s.aws/ec2nodeclass"), Value: aws.String(nodeClass.Name)}}})
awsEnv.EC2API.LaunchTemplates.Store(ltName2, &ec2.LaunchTemplate{LaunchTemplateName: ltName2, LaunchTemplateId: aws.String(fake.LaunchTemplateID()), Tags: []*ec2.Tag{{Key: aws.String("karpenter.k8s.aws/cluster"), Value: aws.String("test-cluster")}, {Key: aws.String("karpenter.k8s.aws/ec2nodeclass"), Value: aws.String(nodeClass.Name)}}})
_, ok := awsEnv.EC2API.LaunchTemplates.Load(ltName1)
Expect(ok).To(BeTrue())
_, ok = awsEnv.EC2API.LaunchTemplates.Load(ltName2)
Expect(ok).To(BeTrue())
controllerutil.AddFinalizer(nodeClass, v1.TerminationFinalizer)
ExpectApplied(ctx, env.Client, nodeClass)
ExpectObjectReconciled(ctx, env.Client, terminationController, nodeClass)

Expect(env.Client.Delete(ctx, nodeClass)).To(Succeed())
ExpectObjectReconciled(ctx, env.Client, terminationController, nodeClass)
_, ok = awsEnv.EC2API.LaunchTemplates.Load(ltName1)
Expand All @@ -158,10 +161,10 @@ var _ = Describe("NodeClass Termination", func() {
ExpectNotFound(ctx, env.Client, nodeClass)
})
It("should succeed to delete the instance profile with no NodeClaims", func() {
awsEnv.IAMAPI.InstanceProfiles = map[string]*iam.InstanceProfile{
awsEnv.IAMAPI.InstanceProfiles = map[string]*iamtypes.InstanceProfile{
profileName: {
InstanceProfileName: aws.String(profileName),
Roles: []*iam.Role{
Roles: []iamtypes.Role{
{
RoleId: aws.String(fake.RoleID()),
RoleName: aws.String(nodeClass.Spec.Role),
Expand All @@ -180,7 +183,7 @@ var _ = Describe("NodeClass Termination", func() {
ExpectNotFound(ctx, env.Client, nodeClass)
})
It("should succeed to delete the instance profile when no roles exist with no NodeClaims", func() {
awsEnv.IAMAPI.InstanceProfiles = map[string]*iam.InstanceProfile{
awsEnv.IAMAPI.InstanceProfiles = map[string]*iamtypes.InstanceProfile{
profileName: {
InstanceProfileName: aws.String(profileName),
},
Expand All @@ -189,7 +192,6 @@ var _ = Describe("NodeClass Termination", func() {
ExpectApplied(ctx, env.Client, nodeClass)
ExpectObjectReconciled(ctx, env.Client, terminationController, nodeClass)
Expect(awsEnv.IAMAPI.InstanceProfiles).To(HaveLen(1))

Expect(env.Client.Delete(ctx, nodeClass)).To(Succeed())
ExpectObjectReconciled(ctx, env.Client, terminationController, nodeClass)
Expect(awsEnv.IAMAPI.InstanceProfiles).To(HaveLen(0))
Expand Down Expand Up @@ -220,10 +222,10 @@ var _ = Describe("NodeClass Termination", func() {
ExpectApplied(ctx, env.Client, nc)
nodeClaims = append(nodeClaims, nc)
}
awsEnv.IAMAPI.InstanceProfiles = map[string]*iam.InstanceProfile{
awsEnv.IAMAPI.InstanceProfiles = map[string]*iamtypes.InstanceProfile{
profileName: {
InstanceProfileName: aws.String(profileName),
Roles: []*iam.Role{
Roles: []iamtypes.Role{
{
RoleId: aws.String(fake.RoleID()),
RoleName: aws.String(nodeClass.Spec.Role),
Expand Down Expand Up @@ -258,10 +260,10 @@ var _ = Describe("NodeClass Termination", func() {
ExpectNotFound(ctx, env.Client, nodeClass)
})
It("should not call the IAM API when deleting a NodeClass with an instanceProfile specified", func() {
awsEnv.IAMAPI.InstanceProfiles = map[string]*iam.InstanceProfile{
awsEnv.IAMAPI.InstanceProfiles = map[string]*iamtypes.InstanceProfile{
profileName: {
InstanceProfileName: aws.String("test-instance-profile"),
Roles: []*iam.Role{
Roles: []iamtypes.Role{
{
RoleId: aws.String(fake.RoleID()),
RoleName: aws.String("fake-role"),
Expand Down
Loading

0 comments on commit c2be457

Please sign in to comment.