Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rhcos: Support channels #1402

Closed
wants to merge 1 commit into from
Closed
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
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 @@ -6,6 +6,7 @@ import (
"fmt"
"io/ioutil"
"net/http"
"os"

"github.com/pkg/errors"
"github.com/sirupsen/logrus"
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
}