Skip to content

Commit

Permalink
pkg/asset/installconfig/platform: Remove libvirt image prompt
Browse files Browse the repository at this point in the history
Keep the environment variable (with a warning about using it), but
drop the interactive prompt.  The default is solid, and users
manipulating it are more likely to break something (e.g. by continuing
to use the old v1 pipeline), while the installer can update its
default to track the RHCOS folks (e.g. like 1117821, rhcos: implement
image discovery for new pipeline, 2018-10-26, #554).
  • Loading branch information
wking committed Nov 7, 2018
1 parent 56c360c commit a03ee03
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 28 deletions.
6 changes: 4 additions & 2 deletions docs/user/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,7 @@ The installer accepts a number of environment variable that allow the interactiv
This must be accessible from the running cluster.
* `OPENSHIFT_INSTALL_LIBVIRT_IMAGE`:
The URI for the OS image.
For example it might be url like `http://aos-ostree.rhev-ci-vms.eng.rdu2.redhat.com/rhcos/images/cloud/latest/rhcos-qemu.qcow2.gz` or
a local file like `file:///tmp/openshift-install-853528428`.
For example it might be a URI like `https://example.com/rhcos-qemu.qcow2` or a local file like `file:///tmp/redhat-coreos-maipo-47.78-qemu.qcow2`.

**Warning**: you should only set this if you're testing RHCOS releases.
Most users should allow the installer to choose the OS image.
42 changes: 16 additions & 26 deletions pkg/asset/installconfig/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,40 +289,26 @@ func (a *platform) libvirtPlatform() (*types.LibvirtPlatform, error) {
return nil, err
}

// TODO: Ideally, this would live inside of a closure which is passed to
// asset.GenerateUserProvidedAsset and only called if the environment
// variable isn't present. As this exists, it ruins the abstraction.
var qcowImage string
if _, ok := os.LookupEnv("OPENSHIFT_INSTALL_LIBVIRT_IMAGE"); !ok {
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")
}
}

image, err := asset.GenerateUserProvidedAsset(
"Libvirt Image",
&survey.Question{
Prompt: &survey.Input{
Message: "Image",
Help: "URI of the OS image.",
Default: qcowImage,
},
Validate: survey.ComposeValidators(survey.Required, uriValidator),
},
"OPENSHIFT_INSTALL_LIBVIRT_IMAGE",
)
if err != nil {
return nil, errors.Wrapf(err, "failed to Marshal %s platform", LibvirtPlatformType)
}

return &types.LibvirtPlatform{
Network: types.LibvirtNetwork{
IfName: defaultLibvirtNetworkIfName,
IPRange: defaultLibvirtNetworkIPRange,
},
DefaultMachinePlatform: &types.LibvirtMachinePoolPlatform{
Image: image,
Image: qcowImage,
},
URI: uri,
}, nil
Expand All @@ -331,13 +317,17 @@ func (a *platform) libvirtPlatform() (*types.LibvirtPlatform, error) {
// uriValidator validates if the answer provided in prompt is a valid
// url and has non-empty scheme.
func uriValidator(ans interface{}) error {
value := ans.(string)
uri, err := url.Parse(value)
return validURI(ans.(string))
}

// validURI validates if the URI is a valid URI with a non-empty scheme.
func validURI(uri string) error {
parsed, err := url.Parse(uri)
if err != nil {
return err
}
if uri.Scheme == "" {
return fmt.Errorf("invalid URI %q (no scheme)", value)
if parsed.Scheme == "" {
return fmt.Errorf("invalid URI %q (no scheme)", uri)
}
return nil
}

0 comments on commit a03ee03

Please sign in to comment.