Skip to content
Merged
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
4 changes: 4 additions & 0 deletions config/crds/awsprovider_v1alpha1_awsmachineproviderspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy Markdown
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
Copy Markdown
Contributor 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"`

Expand Down
11 changes: 7 additions & 4 deletions pkg/cloud/aws/services/ec2/ami.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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"),
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloud/aws/services/ec2/ami_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloud/aws/services/ec2/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down