diff --git a/hack/build.sh b/hack/build.sh index 17f35dda20f..7cfa7b46806 100755 --- a/hack/build.sh +++ b/hack/build.sh @@ -43,6 +43,10 @@ release) then LDFLAGS="${LDFLAGS} -X github.com/openshift/installer/pkg/asset/ignition/bootstrap.defaultReleaseImage=${RELEASE_IMAGE}" fi + if test -n "${RHCOS_BUILD_NAME}" + then + LDFLAGS="${LDFLAGS} -X github.com/openshift/installer/pkg/rhcos.buildName=${RHCOS_BUILD_NAME}" + fi if test "${SKIP_GENERATION}" != y then go generate ./data diff --git a/pkg/asset/ignition/bootstrap/bootstrap.go b/pkg/asset/ignition/bootstrap/bootstrap.go index 8cfd7e6349e..36312862ac1 100644 --- a/pkg/asset/ignition/bootstrap/bootstrap.go +++ b/pkg/asset/ignition/bootstrap/bootstrap.go @@ -35,7 +35,7 @@ const ( ignitionUser = "core" ) -var t( +var ( defaultReleaseImage = "registry.svc.ci.openshift.org/openshift/origin-release:v4.0" ) diff --git a/pkg/rhcos/builds.go b/pkg/rhcos/builds.go index a1a76158d9c..015b50ef615 100644 --- a/pkg/rhcos/builds.go +++ b/pkg/rhcos/builds.go @@ -11,10 +11,14 @@ import ( "github.com/sirupsen/logrus" ) -const ( +var ( // DefaultChannel is the default RHCOS channel for the cluster. DefaultChannel = "maipo" + // buildName is the name of the build in the channel that will be picked up + // empty string means the first one in the build list (latest) will be used + buildName = "" + baseURL = "https://releases-rhcos.svc.ci.openshift.org/storage/releases" ) @@ -33,9 +37,13 @@ type metadata struct { } func fetchLatestMetadata(ctx context.Context, channel string) (metadata, error) { - build, err := fetchLatestBuild(ctx, channel) - if err != nil { - return metadata{}, errors.Wrap(err, "failed to fetch latest build") + build := buildName + var err error + if build == "" { + build, err = fetchLatestBuild(ctx, channel) + if err != nil { + return metadata{}, errors.Wrap(err, "failed to fetch latest build") + } } url := fmt.Sprintf("%s/%s/%s/meta.json", baseURL, channel, build) @@ -48,7 +56,7 @@ func fetchLatestMetadata(ctx context.Context, channel string) (metadata, error) client := &http.Client{} resp, err := client.Do(req.WithContext(ctx)) if err != nil { - return metadata{}, errors.Wrap(err, "failed to fetch metadata") + return metadata{}, errors.Wrapf(err, "failed to fetch metadata for build %s", build) } defer resp.Body.Close()