-
Notifications
You must be signed in to change notification settings - Fork 1.5k
asset/*: allow prompts to be read from environment #320
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,7 +41,11 @@ func (a *Platform) Dependencies() []asset.Asset { | |
|
|
||
| // Generate queries for input from the user. | ||
| func (a *Platform) Generate(map[asset.Asset]*asset.State) (*asset.State, error) { | ||
| platform := a.queryUserForPlatform() | ||
| platform, err := a.queryUserForPlatform() | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| switch platform { | ||
| case AWSPlatformType: | ||
| return a.awsPlatform() | ||
|
|
@@ -57,61 +61,80 @@ func (a *Platform) Name() string { | |
| return "Platform" | ||
| } | ||
|
|
||
| func (a *Platform) queryUserForPlatform() string { | ||
| var platform string | ||
| survey.AskOne(&survey.Select{ | ||
| Message: "Platform", | ||
| Options: validPlatforms, | ||
| }, &platform, nil) | ||
| func (a *Platform) queryUserForPlatform() (string, error) { | ||
| prompt := asset.UserProvided{ | ||
| Prompt: &survey.Select{ | ||
| Message: "Platform", | ||
| Options: validPlatforms, | ||
| }, | ||
| EnvVarName: "OPENSHIFT_INSTALL_PLATFORM", | ||
| } | ||
|
|
||
| platform, err := prompt.Generate(nil) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
|
|
||
| return platform | ||
| return string(platform.Contents[0].Data), nil | ||
| } | ||
|
|
||
| func (a *Platform) awsPlatform() (*asset.State, error) { | ||
| var region string | ||
| survey.AskOne(&survey.Select{ | ||
| Message: "Region", | ||
| Help: "The AWS region to be used for installation.", | ||
| Default: "us-east-1 (N. Virginia)", | ||
| Options: []string{ | ||
| "us-east-2 (Ohio)", | ||
| "us-east-1 (N. Virginia)", | ||
| "us-west-1 (N. California)", | ||
| "us-west-2 (Oregon)", | ||
| "ap-south-1 (Mumbai)", | ||
| "ap-northeast-2 (Seoul)", | ||
| "ap-northeast-3 (Osaka-Local)", | ||
| "ap-southeast-1 (Singapore)", | ||
| "ap-southeast-2 (Sydney)", | ||
| "ap-northeast-1 (Tokyo)", | ||
| "ca-central-1 (Central)", | ||
| "cn-north-1 (Beijing)", | ||
| "cn-northwest-1 (Ningxia)", | ||
| "eu-central-1 (Frankfurt)", | ||
| "eu-west-1 (Ireland)", | ||
| "eu-west-2 (London)", | ||
| "eu-west-3 (Paris)", | ||
| "sa-east-1 (São Paulo)", | ||
| prompt := asset.UserProvided{ | ||
| Prompt: &survey.Select{ | ||
| Message: "Region", | ||
| Help: "The AWS region to be used for installation.", | ||
| Default: "us-east-1 (N. Virginia)", | ||
| Options: []string{ | ||
| "us-east-2 (Ohio)", | ||
| "us-east-1 (N. Virginia)", | ||
| "us-west-1 (N. California)", | ||
| "us-west-2 (Oregon)", | ||
| "ap-south-1 (Mumbai)", | ||
| "ap-northeast-2 (Seoul)", | ||
| "ap-northeast-3 (Osaka-Local)", | ||
| "ap-southeast-1 (Singapore)", | ||
| "ap-southeast-2 (Sydney)", | ||
| "ap-northeast-1 (Tokyo)", | ||
| "ca-central-1 (Central)", | ||
| "cn-north-1 (Beijing)", | ||
| "cn-northwest-1 (Ningxia)", | ||
| "eu-central-1 (Frankfurt)", | ||
| "eu-west-1 (Ireland)", | ||
| "eu-west-2 (London)", | ||
| "eu-west-3 (Paris)", | ||
| "sa-east-1 (São Paulo)", | ||
| }, | ||
| }, | ||
| }, ®ion, nil) | ||
| EnvVarName: "OPENSHIFT_INSTALL_AWS_REGION", | ||
| } | ||
| region, err := prompt.Generate(nil) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return assetStateForStringContents( | ||
| AWSPlatformType, | ||
| strings.Split(region, " ")[0], | ||
| strings.Split(string(region.Contents[0].Data), " ")[0], | ||
| ), nil | ||
| } | ||
|
|
||
| func (a *Platform) libvirtPlatform() (*asset.State, error) { | ||
| var uri string | ||
| survey.AskOne(&survey.Input{ | ||
| Message: "URI", | ||
| Help: "The libvirt connection URI to be used. This must be accessible from the running cluster.", | ||
| Default: "qemu+tcp://192.168.122.1/system", | ||
| }, &uri, nil) | ||
| prompt := asset.UserProvided{ | ||
| Prompt: &survey.Input{ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you forget to use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. This is a free-form field.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do I understand correctly that due to https://github.com/openshift/installer/pull/320/files#diff-042a71691f31141034ea54bae5b36b06R26 this is settable via environment variable and will only ask interactively if it's not present?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. |
||
| Message: "URI", | ||
| Help: "The libvirt connection URI to be used. This must be accessible from the running cluster.", | ||
| Default: "qemu+tcp://192.168.122.1/system", | ||
| }, | ||
| EnvVarName: "OPENSHIFT_INSTALL_LIBVIRT_URI", | ||
| } | ||
| uri, err := prompt.Generate(nil) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return assetStateForStringContents( | ||
| LibvirtPlatformType, | ||
| uri, | ||
| string(uri.Contents[0].Data), | ||
| ), nil | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,14 @@ func (a *sshPublicKey) Dependencies() []asset.Asset { | |
|
|
||
| // Generate generates the SSH public key asset. | ||
| func (a *sshPublicKey) Generate(map[asset.Asset]*asset.State) (state *asset.State, err error) { | ||
| if value, ok := os.LookupEnv("OPENSHIFT_INSTALL_SSH_PUB_KEY"); ok { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd consider to also ask for the SSH key if not provided, or are there use-cases where one wouldn't want one set?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I'm fine allowing folks to not set one (e.g. if they trust us to set up a working cluster for them so they won't have to poke around ;). So I think we want to allow empty
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Setting
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That sounds useful. If someone goes through it the first time interactively they might forget or not be aware of this setting and later have to restart when they find themselves unable to login.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The long-term plan is to have one of the operators (the machine-config operator?) managing authorized SSH keys over the life of the cluster. So you should (eventually) be able to recover even if you launch a cluster without this. |
||
| return &asset.State{ | ||
| Contents: []asset.Content{{ | ||
| Data: []byte(value), | ||
| }}, | ||
| }, nil | ||
| } | ||
|
|
||
| pubKeys := map[string][]byte{ | ||
| none: {}, | ||
| } | ||
|
|
||
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.
maybe rename this to
queryUserOrGetEnvForPlatformThere 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.
I'm fine with the old name. Environment variables are just another channel for the user to answer these queries.
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.
So you'd rather double-check each function where it gets the input from instead of having the information readily available in the name?
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.
Yeah. The caller just needs to care that the input is gotten. The source location is an implementation detail.