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
40 changes: 38 additions & 2 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import:
- pkg/client/clientset_generated/clientset
- package: github.com/AlecAivazis/survey
version: 1.6.2
- package: github.com/aws/aws-sdk-go
version: ^1.15.39
testImport:
- package: github.com/stretchr/testify
version: ^1.2.2
Expand Down
1 change: 1 addition & 0 deletions installer/pkg/config-generator/fixtures/test-aws.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ admin:
email: [email protected]
password: asd123
aws:
ec2AMIOverride: ami-0af8953af3ec06b7c
region: us-east-1
sshKey: tectonic
vpcCIDRBlock: 10.0.0.0/16
Expand Down
2 changes: 2 additions & 0 deletions installer/pkg/config-generator/fixtures/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ master:
nodePools:
- name: master
count: 3
aws:
ec2AMIOverride: ami-0af8953af3ec06b7c
3 changes: 2 additions & 1 deletion installer/pkg/config-generator/generator.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package configgenerator

import (
"context"
"crypto/rand"
"encoding/base64"
"encoding/hex"
Expand Down Expand Up @@ -119,7 +120,7 @@ func (c *ConfigGenerator) maoConfig(clusterDir string) (*maoOperatorConfig, erro
if c.AWS.EC2AMIOverride != "" {
ami = c.AWS.EC2AMIOverride
} else {
ami, err = rhcos.AMI(rhcos.DefaultChannel, c.Region)
ami, err = rhcos.AMI(context.TODO(), rhcos.DefaultChannel, c.Region)
if err != nil {
return nil, fmt.Errorf("failed to lookup RHCOS AMI: %v", err)
}
Expand Down
1 change: 1 addition & 0 deletions installer/pkg/workflow/fixtures/aws.basic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ admin:
email: [email protected]
password: fake-password
aws:
ec2AMIOverride: ami-0af8953af3ec06b7c
master:
ec2Type: m4.large
rootVolume:
Expand Down
1 change: 1 addition & 0 deletions pkg/asset/manifests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ go_library(
"//vendor/github.com/coreos/tectonic-config/config/tectonic-network:go_default_library",
"//vendor/github.com/ghodss/yaml:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/rand:go_default_library",
],
)
3 changes: 2 additions & 1 deletion pkg/asset/manifests/machine-api-operator.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package manifests

import (
"context"
"fmt"
"path/filepath"

Expand Down Expand Up @@ -111,7 +112,7 @@ func (mao *machineAPIOperator) maoConfig(dependencies map[asset.Asset]*asset.Sta
if mao.installConfig.Platform.AWS != nil {
var ami string

ami, err := rhcos.AMI(DefaultChannel, mao.installConfig.Platform.AWS.Region)
ami, err := rhcos.AMI(context.TODO(), DefaultChannel, mao.installConfig.Platform.AWS.Region)
if err != nil {
return "", fmt.Errorf("failed to lookup RHCOS AMI: %v", err)
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/rhcos/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@ go_library(
],
importpath = "github.com/openshift/installer/pkg/rhcos",
visibility = ["//visibility:public"],
deps = [
"//vendor/github.com/aws/aws-sdk-go/aws:go_default_library",
"//vendor/github.com/aws/aws-sdk-go/aws/session:go_default_library",
"//vendor/github.com/aws/aws-sdk-go/service/ec2:go_default_library",
],
)
72 changes: 68 additions & 4 deletions pkg/rhcos/ami.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package rhcos

import (
"context"
"fmt"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ec2"
)

const (
Expand All @@ -10,14 +16,72 @@ const (
)

// AMI calculates a Red Hat CoreOS AMI.
func AMI(channel, region string) (ami string, err error) {
func AMI(ctx context.Context, channel, region string) (ami string, err error) {
if channel != DefaultChannel {
return "", fmt.Errorf("channel %q is not yet supported", channel)
}

if region != "us-east-1" {
return "", fmt.Errorf("region %q is not yet supported", region)
ssn := session.Must(session.NewSessionWithOptions(session.Options{
SharedConfigState: session.SharedConfigEnable,
Config: aws.Config{
Region: aws.String(region),
},
}))

svc := ec2.New(ssn)

result, err := svc.DescribeImagesWithContext(ctx, &ec2.DescribeImagesInput{
Filters: []*ec2.Filter{
{
Name: aws.String("name"),
Values: aws.StringSlice([]string{"rhcos*"}),
},
{
Name: aws.String("architecture"),
Values: aws.StringSlice([]string{"x86_64"}),
},
{
Name: aws.String("virtualization-type"),
Values: aws.StringSlice([]string{"hvm"}),
},
{
Name: aws.String("image-type"),
Values: aws.StringSlice([]string{"machine"}),
},
{
Name: aws.String("owner-id"),
Values: aws.StringSlice([]string{"531415883065"}),
},
{
Name: aws.String("state"),
Values: aws.StringSlice([]string{"available"}),
},
},
})
if err != nil {
return "", err
}

var image *ec2.Image
var created time.Time
for _, nextImage := range result.Images {
if nextImage.ImageId == nil || nextImage.CreationDate == nil {
continue
}
nextCreated, err := time.Parse(time.RFC3339, *nextImage.CreationDate)
if err != nil {
return "", err
}

if image == nil || nextCreated.After(created) {
image = nextImage
created = nextCreated
}
}

if image == nil {
return "", fmt.Errorf("no RHCOS AMIs found in %s", region)
}

return "ami-0af8953af3ec06b7c", nil
return *image.ImageId, nil
}
7 changes: 6 additions & 1 deletion pkg/types/config/parser.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package config

import (
"context"
"errors"
"fmt"
"io/ioutil"
"time"

"gopkg.in/yaml.v2"

Expand Down Expand Up @@ -32,7 +34,10 @@ func ParseConfig(data []byte) (*Cluster, error) {
}

if cluster.EC2AMIOverride == "" {
ami, err := rhcos.AMI(rhcos.DefaultChannel, cluster.AWS.Region)
ctx, cancel := context.WithTimeout(context.TODO(), 30*time.Second)
defer cancel()

ami, err := rhcos.AMI(ctx, rhcos.DefaultChannel, cluster.AWS.Region)
if err != nil {
return nil, fmt.Errorf("failed to determine default AMI: %v", err)
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading