Skip to content

Commit

Permalink
Fix mock for IAM Instance Profile
Browse files Browse the repository at this point in the history
  • Loading branch information
h3poteto committed Feb 11, 2021
1 parent f6672b8 commit 1a495b7
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions pkg/testutils/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ go_library(
"//vendor/github.com/aws/aws-sdk-go/aws:go_default_library",
"//vendor/github.com/aws/aws-sdk-go/service/ec2:go_default_library",
"//vendor/github.com/aws/aws-sdk-go/service/elbv2:go_default_library",
"//vendor/github.com/aws/aws-sdk-go/service/iam:go_default_library",
"//vendor/github.com/aws/aws-sdk-go/service/route53:go_default_library",
"//vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/flavors:go_default_library",
"//vendor/github.com/gophercloud/gophercloud/openstack/dns/v2/zones:go_default_library",
Expand Down
12 changes: 12 additions & 0 deletions pkg/testutils/integrationtestharness.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/elbv2"
"github.com/aws/aws-sdk-go/service/iam"
"github.com/aws/aws-sdk-go/service/route53"
"github.com/gophercloud/gophercloud/openstack/compute/v2/flavors"
"github.com/gophercloud/gophercloud/openstack/dns/v2/zones"
Expand Down Expand Up @@ -256,6 +257,17 @@ func (h *IntegrationTestHarness) SetupMockAWS() *awsup.MockAWSCloud {
Name: aws.String("my-external-tg-3"),
})

mockIAM.CreateRole(&iam.CreateRoleInput{
RoleName: aws.String("kops-custom-node-role"),
})
mockIAM.CreateInstanceProfile(&iam.CreateInstanceProfileInput{
InstanceProfileName: aws.String("kops-custom-node-role"),
})
mockIAM.AddRoleToInstanceProfile(&iam.AddRoleToInstanceProfileInput{
InstanceProfileName: aws.String("kops-custom-node-role"),
RoleName: aws.String("kops-custom-node-role"),
})

return cloud
}

Expand Down
2 changes: 1 addition & 1 deletion upup/pkg/fi/cloudup/awsup/aws_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -1752,7 +1752,7 @@ func (c *awsCloudImplementation) AccountInfo() (string, string, error) {
return arn.AccountID, arn.Partition, nil
}

// GetRolesInInstanceProfile return role names whic are associated with the instance profile specified by profileName.
// GetRolesInInstanceProfile return role names which are associated with the instance profile specified by profileName.
func (c *awsCloudImplementation) GetRolesInInstanceProfile(profileName string) ([]string, error) {
return getRolesInInstanceProfile(c, profileName)
}
Expand Down
1 change: 1 addition & 0 deletions upup/pkg/fi/cloudup/bootstrapchannelbuilder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ func runChannelBuilderTest(t *testing.T, key string, addonManifests []string) {

tf := &TemplateFunctions{
KopsModelContext: kopsModel,
cloud: cloud,
}
tf.AddTo(templates.TemplateFunctions, secretStore)

Expand Down
2 changes: 1 addition & 1 deletion upup/pkg/fi/cloudup/template_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ func (tf *TemplateFunctions) KopsControllerConfig() (string, error) {
if ig.Spec.IAM != nil && ig.Spec.IAM.Profile != nil {
roles, err := tf.cloud.GetRolesInInstanceProfile(*profile.Name)
if err != nil {
return "", fmt.Errorf("getting role from profile %s: %v", profile, err)
return "", fmt.Errorf("getting role from profile %s: %v", *profile.Name, err)
}
nodesRoles.Insert(roles...)
} else {
Expand Down

0 comments on commit 1a495b7

Please sign in to comment.