Skip to content

Commit

Permalink
version: Output RHEL CoreOS bootimage version
Browse files Browse the repository at this point in the history
There are a lot of reasons to want to know the RHCOS bootimage version
associated with an installer - the installer pins it today, but doesn't
make the information easy to find particularly in a CI/development
environment.

This is a very small step towards something like:
openshift#1399
  • Loading branch information
cgwalters committed Jun 4, 2019
1 parent 98e9958 commit 982210e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
5 changes: 5 additions & 0 deletions cmd/openshift-install/version.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package main

import (
"context"
"fmt"
"os"

"github.com/spf13/cobra"

"github.com/openshift/installer/pkg/asset/ignition/bootstrap"
"github.com/openshift/installer/pkg/rhcos"
"github.com/openshift/installer/pkg/version"
)

Expand All @@ -28,5 +30,8 @@ func runVersionCmd(cmd *cobra.Command, args []string) error {
if image, err := bootstrap.DefaultReleaseImage(); err == nil {
fmt.Printf("release image %s\n", image)
}
if rhcosmeta, err := rhcos.FetchRHCOSBuild(context.TODO()); err == nil {
fmt.Printf("RHEL CoreOS bootimage %s\n", rhcosmeta.OSTreeVersion)
}
return nil
}
2 changes: 1 addition & 1 deletion pkg/rhcos/ami.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

// AMI fetches the HVM AMI ID of the Red Hat Enterprise Linux CoreOS release.
func AMI(ctx context.Context, region string) (string, error) {
meta, err := fetchRHCOSBuild(ctx)
meta, err := FetchRHCOSBuild(ctx)
if err != nil {
return "", errors.Wrap(err, "failed to fetch RHCOS metadata")
}
Expand Down
9 changes: 6 additions & 3 deletions pkg/rhcos/builds.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import (
"github.com/pkg/errors"
)

type metadata struct {
// Metadata is a subset of the `meta.json` generated
// by https://github.com/coreos/coreos-assembler
type Metadata struct {
AMIs map[string]struct {
HVM string `json:"hvm"`
} `json:"amis"`
Expand All @@ -23,7 +25,8 @@ type metadata struct {
OSTreeVersion string `json:"ostree-version"`
}

func fetchRHCOSBuild(ctx context.Context) (*metadata, error) {
// FetchRHCOSBuild retrieves the pinned RHEL CoreOS version.
func FetchRHCOSBuild(ctx context.Context) (*Metadata, error) {
file, err := data.Assets.Open("rhcos.json")
if err != nil {
return nil, err
Expand All @@ -35,7 +38,7 @@ func fetchRHCOSBuild(ctx context.Context) (*metadata, error) {
return nil, err
}

var meta *metadata
var meta *Metadata
if err := json.Unmarshal(body, &meta); err != nil {
return meta, errors.Wrap(err, "failed to parse RHCOS build metadata")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/rhcos/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

// QEMU fetches the URL of the Red Hat Enterprise Linux CoreOS release.
func QEMU(ctx context.Context) (string, error) {
meta, err := fetchRHCOSBuild(ctx)
meta, err := FetchRHCOSBuild(ctx)
if err != nil {
return "", errors.Wrap(err, "failed to fetch RHCOS metadata")
}
Expand Down

0 comments on commit 982210e

Please sign in to comment.