diff --git a/docs/user/environment-variables.md b/docs/user/environment-variables.md index bedd18a0e28..f9e27fedfab 100644 --- a/docs/user/environment-variables.md +++ b/docs/user/environment-variables.md @@ -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. diff --git a/pkg/asset/installconfig/platform.go b/pkg/asset/installconfig/platform.go index 00f3daec937..6decf9b1736 100644 --- a/pkg/asset/installconfig/platform.go +++ b/pkg/asset/installconfig/platform.go @@ -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 @@ -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 }