-
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.
Rewrite AMI generator using jennifer
- Loading branch information
1 parent
6972196
commit e9b7bc1
Showing
6 changed files
with
95 additions
and
136 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 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
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,80 @@ | ||
// +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") | ||
|
||
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, it is generated by static_resolver_ami_generate.go") | ||
|
||
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