Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}