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

Add ability to override Organization ID for image lookups #723

Merged
merged 3 commits into from
Apr 17, 2019
Merged
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
4 changes: 4 additions & 0 deletions config/crds/awsprovider_v1alpha1_awsmachineproviderspec.yaml
Original file line number Diff line number Diff line change
@@ -95,6 +95,10 @@ spec:
description: IAMInstanceProfile is a name of an IAM instance profile to
assign to the instance
type: string
imageLookupOrg:
description: ImageLookupOrg is the AWS Organization ID to use for image
lookup if AMI is not set.
type: string
instanceType:
description: 'InstanceType is the type of instance to create. Example: m4.xlarge'
type: string
Original file line number Diff line number Diff line change
@@ -37,6 +37,9 @@ type AWSMachineProviderSpec struct {
// AMI is the reference to the AMI from which to create the machine instance.
AMI AWSResourceReference `json:"ami,omitempty"`

// ImageLookupOrg is the AWS Organization ID to use for image lookup if AMI is not set.
ImageLookupOrg string `json:"imageLookupOrg,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

Nit, ImageLookupOrg could be ImageLookupOrgID

Copy link
Member Author

Choose a reason for hiding this comment

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

I had thought about that, but I also felt it was already a bit long.


// InstanceType is the type of instance to create. Example: m4.xlarge
InstanceType string `json:"instanceType,omitempty"`

11 changes: 7 additions & 4 deletions pkg/cloud/aws/services/ec2/ami.go
Original file line number Diff line number Diff line change
@@ -28,9 +28,9 @@ import (
)

const (
// machineAMIOwnerID is a heptio/VMware owned account. Please see:
// defaultMachineAMIOwnerID is a heptio/VMware owned account. Please see:
// https://github.com/kubernetes-sigs/cluster-api-provider-aws/issues/487
machineAMIOwnerID = "258751437250"
defaultMachineAMIOwnerID = "258751437250"

// amiNameFormat is defined in the build/ directory of this project.
// The pattern is:
@@ -50,12 +50,15 @@ func amiName(baseOS, baseOSVersion, kubernetesVersion string) string {
}

// defaultAMILookup returns the default AMI based on region
func (s *Service) defaultAMILookup(baseOS, baseOSVersion, kubernetesVersion string) (string, error) {
func (s *Service) defaultAMILookup(ownerID, baseOS, baseOSVersion, kubernetesVersion string) (string, error) {
if ownerID == "" {
ownerID = defaultMachineAMIOwnerID
}
describeImageInput := &ec2.DescribeImagesInput{
Filters: []*ec2.Filter{
{
Name: aws.String("owner-id"),
Values: []*string{aws.String(machineAMIOwnerID)},
Values: []*string{aws.String(ownerID)},
},
{
Name: aws.String("name"),
2 changes: 1 addition & 1 deletion pkg/cloud/aws/services/ec2/ami_test.go
Original file line number Diff line number Diff line change
@@ -76,7 +76,7 @@ func TestAMIs(t *testing.T) {
tc.expect(ec2Mock.EXPECT())

s := NewService(scope)
id, err := s.defaultAMILookup("base os", "baseos version", "1.11.1")
id, err := s.defaultAMILookup("", "base os", "baseos version", "1.11.1")
if err != nil {
t.Fatalf("did not expect error calling a mock: %v", err)
}
2 changes: 1 addition & 1 deletion pkg/cloud/aws/services/ec2/instances.go
Original file line number Diff line number Diff line change
@@ -122,7 +122,7 @@ func (s *Service) createInstance(machine *actuators.MachineScope, bootstrapToken
if machine.MachineConfig.AMI.ID != nil {
input.ImageID = *machine.MachineConfig.AMI.ID
} else {
input.ImageID, err = s.defaultAMILookup("ubuntu", "18.04", machine.Machine.Spec.Versions.Kubelet)
input.ImageID, err = s.defaultAMILookup(machine.MachineConfig.ImageLookupOrg, "ubuntu", "18.04", machine.Machine.Spec.Versions.Kubelet)
if err != nil {
return nil, err
}