From 037d4662c8e42cc5deadfec24dfe0e20ecc7b349 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Mon, 11 Mar 2019 19:19:11 +0000 Subject: [PATCH] rhcos: Support channels The code was hardcoded to `DefaultChannel`; add an environment variable so people (and CI) can use the other channels. --- pkg/asset/rhcos/image.go | 4 ++-- pkg/rhcos/ami.go | 4 ++-- pkg/rhcos/builds.go | 13 ++++++++++++- pkg/rhcos/qemu.go | 6 +++--- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/pkg/asset/rhcos/image.go b/pkg/asset/rhcos/image.go index 956b85bc320..ab082524e77 100644 --- a/pkg/asset/rhcos/image.go +++ b/pkg/asset/rhcos/image.go @@ -55,9 +55,9 @@ func (i *Image) Generate(p asset.Parents) error { defer cancel() switch config.Platform.Name() { case aws.Name: - osimage, err = rhcos.AMI(ctx, rhcos.DefaultChannel, config.Platform.AWS.Region) + osimage, err = rhcos.AMI(ctx, config.Platform.AWS.Region) case libvirt.Name: - osimage, err = rhcos.QEMU(ctx, rhcos.DefaultChannel) + osimage, err = rhcos.QEMU(ctx) case openstack.Name: osimage = "rhcos" case none.Name: diff --git a/pkg/rhcos/ami.go b/pkg/rhcos/ami.go index ee43dba5f89..335b78af87b 100644 --- a/pkg/rhcos/ami.go +++ b/pkg/rhcos/ami.go @@ -7,8 +7,8 @@ import ( ) // AMI fetches the HVM AMI ID of the latest Red Hat Enterprise Linux CoreOS release. -func AMI(ctx context.Context, channel, region string) (string, error) { - meta, err := fetchLatestMetadata(ctx, channel) +func AMI(ctx context.Context, region string) (string, error) { + meta, err := fetchLatestMetadata(ctx) if err != nil { return "", errors.Wrap(err, "failed to fetch RHCOS metadata") } diff --git a/pkg/rhcos/builds.go b/pkg/rhcos/builds.go index 015b50ef615..5d4fd60b9a8 100644 --- a/pkg/rhcos/builds.go +++ b/pkg/rhcos/builds.go @@ -6,6 +6,7 @@ import ( "fmt" "io/ioutil" "net/http" + "os" "github.com/pkg/errors" "github.com/sirupsen/logrus" @@ -22,6 +23,15 @@ var ( baseURL = "https://releases-rhcos.svc.ci.openshift.org/storage/releases" ) +// getChannel returns a named "channel" which is just a subdirectory with +// builds.json as defined by coreos-assembler +func getChannel() string { + if channel, ok := os.LookupEnv("OPENSHIFT_INSTALL_OS_CHANNEL"); ok && channel != "" { + return channel + } + return DefaultChannel +} + type metadata struct { AMIs []struct { HVM string `json:"hvm"` @@ -36,9 +46,10 @@ type metadata struct { OSTreeVersion string `json:"ostree-version"` } -func fetchLatestMetadata(ctx context.Context, channel string) (metadata, error) { +func fetchLatestMetadata(ctx context.Context) (metadata, error) { build := buildName var err error + channel := getChannel() if build == "" { build, err = fetchLatestBuild(ctx, channel) if err != nil { diff --git a/pkg/rhcos/qemu.go b/pkg/rhcos/qemu.go index 98b0d33e88b..3c97fc38457 100644 --- a/pkg/rhcos/qemu.go +++ b/pkg/rhcos/qemu.go @@ -8,11 +8,11 @@ import ( ) // QEMU fetches the URL of the latest Red Hat Enterprise Linux CoreOS release. -func QEMU(ctx context.Context, channel string) (string, error) { - meta, err := fetchLatestMetadata(ctx, channel) +func QEMU(ctx context.Context) (string, error) { + meta, err := fetchLatestMetadata(ctx) if err != nil { return "", errors.Wrap(err, "failed to fetch RHCOS metadata") } - return fmt.Sprintf("%s/%s/%s/%s", baseURL, channel, meta.OSTreeVersion, meta.Images.QEMU.Path), nil + return fmt.Sprintf("%s/%s/%s/%s", baseURL, getChannel(), meta.OSTreeVersion, meta.Images.QEMU.Path), nil }