diff --git a/pkg/asset/installconfig/platform.go b/pkg/asset/installconfig/platform.go index 7abeca3cdd4..a1b1ad99171 100644 --- a/pkg/asset/installconfig/platform.go +++ b/pkg/asset/installconfig/platform.go @@ -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{ + 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 } diff --git a/pkg/asset/installconfig/ssh.go b/pkg/asset/installconfig/ssh.go index 6f88ec30a3e..0dece7fc378 100644 --- a/pkg/asset/installconfig/ssh.go +++ b/pkg/asset/installconfig/ssh.go @@ -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 { + return &asset.State{ + Contents: []asset.Content{{ + Data: []byte(value), + }}, + }, nil + } + pubKeys := map[string][]byte{ none: {}, } diff --git a/pkg/asset/installconfig/stock.go b/pkg/asset/installconfig/stock.go index 8cf61554683..e75aa35b862 100644 --- a/pkg/asset/installconfig/stock.go +++ b/pkg/asset/installconfig/stock.go @@ -55,6 +55,7 @@ func (s *StockImpl) EstablishStock() { Message: "Email Address", Help: "The email address of the cluster administrator. This will be used to log in to the console.", }, + EnvVarName: "OPENSHIFT_INSTALL_EMAIL_ADDRESS", } s.password = &asset.UserProvided{ AssetName: "Password", @@ -62,6 +63,7 @@ func (s *StockImpl) EstablishStock() { Message: "Password", Help: "The password of the cluster administrator. This will be used to log in to the console.", }, + EnvVarName: "OPENSHIFT_INSTALL_PASSWORD", } s.baseDomain = &asset.UserProvided{ AssetName: "Base Domain", @@ -69,6 +71,7 @@ func (s *StockImpl) EstablishStock() { Message: "Base Domain", Help: "The base domain of the cluster. All DNS records will be sub-domains of this base.", }, + EnvVarName: "OPENSHIFT_INSTALL_BASE_DOMAIN", } s.clusterName = &asset.UserProvided{ AssetName: "Cluster Name", @@ -76,6 +79,7 @@ func (s *StockImpl) EstablishStock() { Message: "Cluster Name", Help: "The name of the cluster. This will be used when generating sub-domains.", }, + EnvVarName: "OPENSHIFT_INSTALL_CLUSTER_NAME", } s.pullSecret = &asset.UserProvided{ AssetName: "Pull Secret", @@ -83,6 +87,7 @@ func (s *StockImpl) EstablishStock() { Message: "Pull Secret", Help: "The container registry pull secret for this cluster.", }, + EnvVarName: "OPENSHIFT_INSTALL_PULL_SECRET", } s.platform = &Platform{} s.sshKey = &sshPublicKey{} diff --git a/pkg/asset/userprovided.go b/pkg/asset/userprovided.go index ef59528a845..add4abd6768 100644 --- a/pkg/asset/userprovided.go +++ b/pkg/asset/userprovided.go @@ -1,13 +1,16 @@ package asset import ( + "os" + "github.com/AlecAivazis/survey" ) // UserProvided generates an asset that is supplied by a user. type UserProvided struct { - AssetName string - Prompt survey.Prompt + AssetName string + Prompt survey.Prompt + EnvVarName string } var _ Asset = (*UserProvided)(nil) @@ -20,7 +23,11 @@ func (a *UserProvided) Dependencies() []Asset { // Generate queries for input from the user. func (a *UserProvided) Generate(map[Asset]*State) (*State, error) { var response string - survey.AskOne(a.Prompt, &response, survey.Required) + if value, ok := os.LookupEnv(a.EnvVarName); ok { + response = value + } else { + survey.AskOne(a.Prompt, &response, survey.Required) + } return &State{ Contents: []Content{{