Skip to content

Commit

Permalink
Add ability to override Organization ID for image lookups
Browse files Browse the repository at this point in the history
  • Loading branch information
detiber committed Apr 17, 2019
1 parent 1ba422e commit 068905e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
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"`

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

Expand Down
9 changes: 6 additions & 3 deletions pkg/cloud/aws/services/ec2/ami.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
const (
// machineAMIOwnerID 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

0 comments on commit 068905e

Please sign in to comment.