-
Notifications
You must be signed in to change notification settings - Fork 1.5k
pkg/asset/installconfig/aws/metadata: Store AWS metadata #2512
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
openshift-merge-robot
merged 5 commits into
openshift:master
from
wking:aws-metadata-caching
Oct 15, 2019
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
49ff49b
pkg/asset/installconfig/aws/platform: Put Platform in its own file
wking d9b87db
pkg/asset/installconfig/aws/session: Put GetSession in its own file
wking e08f50d
pkg/asset/installconfig/installconfig: Add InstallConfig.finish
wking 68994b7
pkg/asset/installconfig/aws/metadata: Store AWS metadata
wking 1b4c1bf
pkg/asset/installconfig/aws/availabilityzones: Add zones to Metadata
wking File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,2 @@ | ||
| // Package aws collects AWS-specific configuration. | ||
| package aws |
This file contains hidden or 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,78 @@ | ||
| package aws | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "sort" | ||
| "strings" | ||
|
|
||
| "github.com/openshift/installer/pkg/types/aws" | ||
| "github.com/openshift/installer/pkg/types/aws/validation" | ||
| "github.com/pkg/errors" | ||
| "github.com/sirupsen/logrus" | ||
| survey "gopkg.in/AlecAivazis/survey.v1" | ||
| ) | ||
|
|
||
| // Platform collects AWS-specific configuration. | ||
| func Platform() (*aws.Platform, error) { | ||
| longRegions := make([]string, 0, len(validation.Regions)) | ||
| shortRegions := make([]string, 0, len(validation.Regions)) | ||
| for id, location := range validation.Regions { | ||
| longRegions = append(longRegions, fmt.Sprintf("%s (%s)", id, location)) | ||
| shortRegions = append(shortRegions, id) | ||
| } | ||
| regionTransform := survey.TransformString(func(s string) string { | ||
| return strings.SplitN(s, " ", 2)[0] | ||
| }) | ||
|
|
||
| defaultRegion := "us-east-1" | ||
| _, ok := validation.Regions[defaultRegion] | ||
| if !ok { | ||
| panic(fmt.Sprintf("installer bug: invalid default AWS region %q", defaultRegion)) | ||
| } | ||
|
|
||
| ssn, err := GetSession() | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| defaultRegionPointer := ssn.Config.Region | ||
| if defaultRegionPointer != nil && *defaultRegionPointer != "" { | ||
| _, ok := validation.Regions[*defaultRegionPointer] | ||
| if ok { | ||
| defaultRegion = *defaultRegionPointer | ||
| } else { | ||
| logrus.Warnf("Unrecognized AWS region %q, defaulting to %s", *defaultRegionPointer, defaultRegion) | ||
| } | ||
| } | ||
|
|
||
| sort.Strings(longRegions) | ||
| sort.Strings(shortRegions) | ||
|
|
||
| var region string | ||
| err = survey.Ask([]*survey.Question{ | ||
| { | ||
| Prompt: &survey.Select{ | ||
| Message: "Region", | ||
| Help: "The AWS region to be used for installation.", | ||
| Default: fmt.Sprintf("%s (%s)", defaultRegion, validation.Regions[defaultRegion]), | ||
| Options: longRegions, | ||
| }, | ||
| Validate: survey.ComposeValidators(survey.Required, func(ans interface{}) error { | ||
| choice := regionTransform(ans).(string) | ||
| i := sort.SearchStrings(shortRegions, choice) | ||
| if i == len(shortRegions) || shortRegions[i] != choice { | ||
| return errors.Errorf("invalid region %q", choice) | ||
| } | ||
| return nil | ||
| }), | ||
| Transform: regionTransform, | ||
| }, | ||
| }, ®ion) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return &aws.Platform{ | ||
| Region: region, | ||
| }, nil | ||
| } |
71 changes: 0 additions & 71 deletions
71
pkg/asset/installconfig/aws/aws.go → pkg/asset/installconfig/aws/session.go
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would like to keep this part in the asset itself.
and
finishcould take*InstallConfigfor better api.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We currently marshal in
Generateand inLoad(presumably to capture any default injection so it doesn't need to get re-injected next time, it was added here). So I think it makes sense to have it in the sharedfinishhelper, but can push it back up into the doubledGenerate/Loadlogic if you prefer. Thoughts?You want
func finish(a *InstallConfig, filename string) errorinstead offunc (a *InstallConfig) finish(filename string) error? I don't see a benefit to a function over my current method, but I can reroll to use a function if you like. Just let me know that I'm reading your comment correctly.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't care enough. It's fine as is.