Skip to content

Commit

Permalink
*: remove support for environment variables
Browse files Browse the repository at this point in the history
The environment variables were originally added to make CI testing a
little easier, since the installer didn't support consumption of
provided assets (e.g. the install config). Now that the installer
supports consumption, there is no need for most of the environment
variables anymore. The variables have actually been confusing to users,
so their removal should simplify the mental model.
  • Loading branch information
crawford committed Dec 11, 2018
1 parent 717e2a0 commit 6be4c25
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 164 deletions.
9 changes: 0 additions & 9 deletions docs/dev/libvirt-howto.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,6 @@ Set `TAGS` when building if you need `destroy cluster` support for libvirt; this
TAGS=libvirt_destroy hack/build.sh
```

To avoid being prompted repeatedly, you can set [environment variables](../user/environment-variables.md) to reflect your libvirt choices. For example, selecting libvirt, setting [our earlier name choices](#pick-names), and telling both the installer and the machine-API operator to contact `libvirtd` at [the usual libvirt IP](#firewall), you can use:

```sh
export OPENSHIFT_INSTALL_PLATFORM=libvirt
export OPENSHIFT_INSTALL_BASE_DOMAIN=tt.testing
export OPENSHIFT_INSTALL_CLUSTER_NAME=test1
export OPENSHIFT_INSTALL_LIBVIRT_URI=qemu+tcp://192.168.122.1/system
```

## Cleanup

If you compiled with `libvirt_destroy`, you can use:
Expand Down
51 changes: 0 additions & 51 deletions docs/user/environment-variables.md

This file was deleted.

12 changes: 0 additions & 12 deletions pkg/asset/installconfig/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
package aws

import (
"encoding/json"
"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -112,23 +111,14 @@ func Platform() (*aws.Platform, error) {
}),
Transform: regionTransform,
},
"OPENSHIFT_INSTALL_AWS_REGION",
)
if err != nil {
return nil, err
}

userTags := map[string]string{}
if value, ok := os.LookupEnv("_CI_ONLY_STAY_AWAY_OPENSHIFT_INSTALL_AWS_USER_TAGS"); ok {
if err := json.Unmarshal([]byte(value), &userTags); err != nil {
return nil, errors.Wrapf(err, "_CI_ONLY_STAY_AWAY_OPENSHIFT_INSTALL_AWS_USER_TAGS contains invalid JSON: %s", value)
}
}

return &aws.Platform{
VPCCIDRBlock: defaultVPCCIDR,
Region: region,
UserTags: userTags,
}, nil
}

Expand All @@ -141,7 +131,6 @@ func getCredentials() error {
Help: "The AWS access key ID to use for installation (this is not your username).\nhttps://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html",
},
},
"",
)
if err != nil {
return err
Expand All @@ -155,7 +144,6 @@ func getCredentials() error {
Help: "The AWS secret access key corresponding to your access key ID (this is not your password).",
},
},
"",
)
if err != nil {
return err
Expand Down
1 change: 0 additions & 1 deletion pkg/asset/installconfig/basedomain.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ func (a *baseDomain) Generate(asset.Parents) error {
return validate.DomainName(ans.(string))
}),
},
"OPENSHIFT_INSTALL_BASE_DOMAIN",
)
a.BaseDomain = bd
return err
Expand Down
1 change: 0 additions & 1 deletion pkg/asset/installconfig/clustername.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ func (a *clusterName) Generate(asset.Parents) error {
return validate.DomainName(ans.(string))
}),
},
"OPENSHIFT_INSTALL_CLUSTER_NAME",
)
a.ClusterName = n
return err
Expand Down
1 change: 0 additions & 1 deletion pkg/asset/installconfig/emailaddress.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ func (a *emailAddress) Generate(asset.Parents) error {
return validate.Email(ans.(string))
}),
},
"OPENSHIFT_INSTALL_EMAIL_ADDRESS",
)
a.EmailAddress = email
return err
Expand Down
16 changes: 3 additions & 13 deletions pkg/asset/installconfig/libvirt/libvirt.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"fmt"
"net/url"
"os"

"github.com/pkg/errors"
survey "gopkg.in/AlecAivazis/survey.v1"
Expand All @@ -32,23 +31,14 @@ func Platform() (*libvirt.Platform, error) {
},
Validate: survey.ComposeValidators(survey.Required, uriValidator),
},
"OPENSHIFT_INSTALL_LIBVIRT_URI",
)
if err != nil {
return nil, err
}

qcowImage, ok := os.LookupEnv("OPENSHIFT_INSTALL_LIBVIRT_IMAGE")
if ok {
err = validURI(qcowImage)
if err != nil {
return nil, errors.Wrap(err, "resolve OPENSHIFT_INSTALL_LIBVIRT_IMAGE")
}
} else {
qcowImage, err = rhcos.QEMU(context.TODO(), rhcos.DefaultChannel)
if err != nil {
return nil, errors.Wrap(err, "failed to fetch QEMU image URL")
}
qcowImage, err := rhcos.QEMU(context.TODO(), rhcos.DefaultChannel)
if err != nil {
return nil, errors.Wrap(err, "failed to fetch QEMU image URL")
}

return &libvirt.Platform{
Expand Down
4 changes: 0 additions & 4 deletions pkg/asset/installconfig/openstack/openstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ func Platform() (*openstack.Platform, error) {
return nil
}),
},
"OPENSHIFT_INSTALL_OPENSTACK_CLOUD",
)
if err != nil {
return nil, err
Expand Down Expand Up @@ -178,7 +177,6 @@ func Platform() (*openstack.Platform, error) {
return nil
}),
},
"OPENSHIFT_INSTALL_OPENSTACK_REGION",
)
if err != nil {
return nil, err
Expand Down Expand Up @@ -206,7 +204,6 @@ func Platform() (*openstack.Platform, error) {
return nil
}),
},
"OPENSHIFT_INSTALL_OPENSTACK_IMAGE",
)
if err != nil {
return nil, err
Expand All @@ -233,7 +230,6 @@ func Platform() (*openstack.Platform, error) {
return nil
}),
},
"OPENSHIFT_INSTALL_OPENSTACK_EXTERNAL_NETWORK",
)
if err != nil {
return nil, errors.Wrapf(err, "failed to Marshal %s platform", openstack.Name)
Expand Down
1 change: 0 additions & 1 deletion pkg/asset/installconfig/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,5 @@ func (a *platform) queryUserForPlatform() (string, error) {
return nil
}),
},
"OPENSHIFT_INSTALL_PLATFORM",
)
}
4 changes: 1 addition & 3 deletions pkg/asset/installconfig/pullsecret.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func (a *pullSecret) Dependencies() []asset.Asset {

// Generate queries for the pull secret from the user.
func (a *pullSecret) Generate(asset.Parents) error {
s, err := asset.GenerateUserProvidedAssetForPath(
s, err := asset.GenerateUserProvidedAsset(
a.Name(),
&survey.Question{
Prompt: &survey.Input{
Expand All @@ -31,8 +31,6 @@ func (a *pullSecret) Generate(asset.Parents) error {
return validate.JSON([]byte(ans.(string)))
}),
},
"OPENSHIFT_INSTALL_PULL_SECRET",
"OPENSHIFT_INSTALL_PULL_SECRET_PATH",
)
a.PullSecret = s
return err
Expand Down
37 changes: 10 additions & 27 deletions pkg/asset/installconfig/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,38 +47,21 @@ func readSSHKey(path string) (string, error) {

// Generate generates the SSH public key asset.
func (a *sshPublicKey) Generate(asset.Parents) error {
if value, ok := os.LookupEnv("OPENSHIFT_INSTALL_SSH_PUB_KEY"); ok {
if value != "" {
if err := validate.SSHPublicKey(value); err != nil {
return errors.Wrap(err, "failed to validate public key")
}
}
a.Key = value
return nil
pubKeys := map[string]string{
none: "",
}

pubKeys := map[string]string{}
if path, ok := os.LookupEnv("OPENSHIFT_INSTALL_SSH_PUB_KEY_PATH"); ok {
key, err := readSSHKey(path)
home := os.Getenv("HOME")
if home != "" {
paths, err := filepath.Glob(filepath.Join(home, ".ssh", "*.pub"))
if err != nil {
return errors.Wrap(err, "failed to read public key file")
return errors.Wrap(err, "failed to glob for public key files")
}
pubKeys[path] = key
} else {
pubKeys[none] = ""
home := os.Getenv("HOME")
if home != "" {
paths, err := filepath.Glob(filepath.Join(home, ".ssh", "*.pub"))
for _, path := range paths {
key, err := readSSHKey(path)
if err != nil {
return errors.Wrap(err, "failed to glob for public key files")
}
for _, path := range paths {
key, err := readSSHKey(path)
if err != nil {
continue
}
pubKeys[path] = key
continue
}
pubKeys[path] = key
}
}

Expand Down
45 changes: 4 additions & 41 deletions pkg/asset/userprovided.go
Original file line number Diff line number Diff line change
@@ -1,50 +1,13 @@
package asset

import (
"io/ioutil"
"os"

"github.com/pkg/errors"
survey "gopkg.in/AlecAivazis/survey.v1"
)

// GenerateUserProvidedAsset queries for input from the user.
func GenerateUserProvidedAsset(inputName string, question *survey.Question, envVarName string) (string, error) {
return generateUserProvidedAsset(inputName, question, envVarName, "")
}

// GenerateUserProvidedAssetForPath queries for input from the user. The input can
// be read from a file specified in an environment variable.
func GenerateUserProvidedAssetForPath(inputName string, question *survey.Question, envVarName, pathEnvVarName string) (string, error) {
return generateUserProvidedAsset(inputName, question, envVarName, pathEnvVarName)
}

func generateUserProvidedAsset(inputName string, question *survey.Question, envVarName, pathEnvVarName string) (response string, err error) {
defer func() {
if err != nil {
err = errors.Wrapf(err, "failed to acquire user-provided input %s", inputName)
}
}()

if value, ok := os.LookupEnv(envVarName); ok {
response = value
} else if path, ok := os.LookupEnv(pathEnvVarName); ok {
value, err := ioutil.ReadFile(path)
if err != nil {
return "", errors.Wrapf(err, "failed to read file from %s", pathEnvVarName)
}
response = string(value)
}

if response == "" {
if err := survey.Ask([]*survey.Question{question}, &response); err != nil {
return "", errors.Wrap(err, "failed to Ask")
}
} else if question.Validate != nil {
if err := question.Validate(response); err != nil {
return "", errors.Wrap(err, "validation failed")
}
}

return response, nil
func GenerateUserProvidedAsset(inputName string, question *survey.Question) (string, error) {
var response string
err := survey.Ask([]*survey.Question{question}, &response)
return response, errors.Wrapf(err, "failed to acquire user-provided input %s", inputName)
}

0 comments on commit 6be4c25

Please sign in to comment.