From cded574524a0ee2c03a79b0bf96dbc92d05d9118 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Wed, 7 Nov 2018 09:36:19 -0800 Subject: [PATCH] pkg/asset/installconfig/platform: Remove libvirt image prompt 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 it's default to track the RHCOS folks (e.g. like 11178211, rhcos: implement image discovery for new pipeline, 2018-10-26, #554). --- docs/user/environment-variables.md | 6 +++-- pkg/asset/installconfig/platform.go | 42 +++++++++++------------------ 2 files changed, 20 insertions(+), 28 deletions(-) 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 }