-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #273 from weaveworks/improve-ami-generator
Improve AMI generator
- Loading branch information
Showing
9 changed files
with
120 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,20 @@ | ||
package ami | ||
|
||
// Code generated by go generate; DO NOT EDIT. | ||
// This file was generated by static_resolver_ami_generate.go; DO NOT EDIT. | ||
|
||
package ami | ||
// StaticImages is a map that holds the list of AMIs to be used by for static resolution | ||
var StaticImages = map[string]map[int]map[string]string{"AmazonLinux2": { | ||
|
||
ImageClassGPU: { | ||
|
||
"eu-west-1": "ami-0706dc8a5eed2eed9", | ||
"us-east-1": "ami-058bfb8c236caae89", | ||
"us-west-2": "ami-0731694d53ef9604b", | ||
}, | ||
ImageClassGeneral: { | ||
|
||
// StaticImages is a map that holds the list of amis to be used by | ||
// for static ami resolution | ||
var StaticImages = map[string]map[int]map[string]string{ | ||
ImageFamilyAmazonLinux2: { | ||
ImageClassGeneral: { | ||
"eu-west-1": "ami-0c7a4976cb6fafd3a", | ||
"us-east-1": "ami-0440e4f6b9713faf6", | ||
"us-west-2": "ami-0a54c984b9f908c81", | ||
}, | ||
ImageClassGPU: { | ||
"eu-west-1": "ami-0706dc8a5eed2eed9", | ||
"us-east-1": "ami-058bfb8c236caae89", | ||
"us-west-2": "ami-0731694d53ef9604b", | ||
}, | ||
"eu-west-1": "ami-0c7a4976cb6fafd3a", | ||
"us-east-1": "ami-0440e4f6b9713faf6", | ||
"us-west-2": "ami-0a54c984b9f908c81", | ||
}, | ||
} | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// +build ignore | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/credentials/stscreds" | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-sdk-go/service/ec2" | ||
|
||
"github.com/weaveworks/eksctl/pkg/ami" | ||
"github.com/weaveworks/eksctl/pkg/eks/api" | ||
|
||
. "github.com/dave/jennifer/jen" | ||
) | ||
|
||
func main() { | ||
fmt.Println("generating list of AMIs for the static resolvers") | ||
|
||
f := NewFile("ami") | ||
|
||
f.Comment("This file was generated by static_resolver_ami_generate.go; DO NOT EDIT.") | ||
f.Line() | ||
|
||
d := Dict{} | ||
|
||
client := newMultiRegionClient() | ||
|
||
for family := range ami.ImageSearchPatterns { | ||
familyImages := Dict{} | ||
log.Printf("looking up %s images", family) | ||
for class := range ami.ImageSearchPatterns[family] { | ||
classImages := Dict{} | ||
for _, region := range api.SupportedRegions { | ||
p := ami.ImageSearchPatterns[family][class] | ||
log.Printf("looking up images matching %q in %q", p, region) | ||
image, err := ami.FindImage(client[region], p) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
classImages[Lit(region)] = Lit(image) | ||
} | ||
familyImages[Id(ami.ImageClasses[class])] = Block(classImages) | ||
} | ||
d[Lit(family)] = Block(familyImages) | ||
} | ||
|
||
f.Comment("StaticImages is a map that holds the list of AMIs to be used by for static resolution") | ||
|
||
f.Var().Id("StaticImages").Op("="). | ||
Map(String()).Map(Int()).Map(String()).String().Values(d) | ||
|
||
if err := f.Save("static_resolver_ami.go"); err != nil { | ||
log.Fatal(err.Error()) | ||
} | ||
|
||
} | ||
|
||
func newSession(region string) *session.Session { | ||
config := aws.NewConfig() | ||
config = config.WithRegion(region) | ||
config = config.WithCredentialsChainVerboseErrors(true) | ||
|
||
// Create the options for the session | ||
opts := session.Options{ | ||
Config: *config, | ||
SharedConfigState: session.SharedConfigEnable, | ||
AssumeRoleTokenProvider: stscreds.StdinTokenProvider, | ||
} | ||
|
||
return session.Must(session.NewSessionWithOptions(opts)) | ||
} | ||
|
||
func newMultiRegionClient() map[string]*ec2.EC2 { | ||
clients := make(map[string]*ec2.EC2) | ||
for _, region := range api.SupportedRegions { | ||
clients[region] = ec2.New(newSession(region)) | ||
} | ||
return clients | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters