Skip to content

Commit

Permalink
rhcos: Support channels
Browse files Browse the repository at this point in the history
The code was hardcoded to `DefaultChannel`; add an environment variable
so people (and CI) can use the other channels.
  • Loading branch information
cgwalters committed Mar 11, 2019
1 parent 0e12f45 commit 48a3dda
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
4 changes: 2 additions & 2 deletions pkg/asset/rhcos/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions pkg/rhcos/ami.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
13 changes: 12 additions & 1 deletion pkg/rhcos/builds.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"net/http"

"github.com/pkg/errors"
Expand All @@ -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"`
Expand All @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions pkg/rhcos/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 48a3dda

Please sign in to comment.