From 3ef7dbfdbb4a938774f889d3e1069ef47944082a Mon Sep 17 00:00:00 2001 From: Rajat Chopra Date: Mon, 26 Nov 2018 19:12:57 -0500 Subject: [PATCH 1/2] hack: pin the release image in build flags But still leave an override env var so that it can be overridden. Use the following env var to pin the image while building the binary: ``` $ # export the release-image variable $ export RELEASE_IMAGE=registry.redhat.io/openshift/origin-release:v4.0" $ # build the openshift-install binary $ ./hack/build.sh $ # distribute the binary to customers and run with pinned image being picked up $ ./bin/openshift-install create cluster... ``` The only way to override it would be to use an env var OPENSHIFT_INSTALL_RELEASE_IMAGE_OVERRIDE while running the openshift-install binary. --- hack/build.sh | 4 ++++ pkg/asset/ignition/bootstrap/bootstrap.go | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/hack/build.sh b/hack/build.sh index 587932971e2..17f35dda20f 100755 --- a/hack/build.sh +++ b/hack/build.sh @@ -39,6 +39,10 @@ export CGO_ENABLED=0 case "${MODE}" in release) TAGS="${TAGS} release" + if test -n "${RELEASE_IMAGE}" + then + LDFLAGS="${LDFLAGS} -X github.com/openshift/installer/pkg/asset/ignition/bootstrap.defaultReleaseImage=${RELEASE_IMAGE}" + 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 977eff061af..8cfd7e6349e 100644 --- a/pkg/asset/ignition/bootstrap/bootstrap.go +++ b/pkg/asset/ignition/bootstrap/bootstrap.go @@ -29,13 +29,16 @@ import ( const ( rootDir = "/opt/openshift" - defaultReleaseImage = "registry.svc.ci.openshift.org/openshift/origin-release:v4.0" bootstrapIgnFilename = "bootstrap.ign" etcdCertSignerImage = "quay.io/coreos/kube-etcd-signer-server:678cc8e6841e2121ebfdb6e2db568fce290b67d6" etcdctlImage = "quay.io/coreos/etcd:v3.2.14" ignitionUser = "core" ) +var t( + defaultReleaseImage = "registry.svc.ci.openshift.org/openshift/origin-release:v4.0" +) + // bootstrapTemplateData is the data to use to replace values in bootstrap // template files. type bootstrapTemplateData struct { From 07f17f4163693a926487e4e46f46b1b9c0d0d9ff Mon Sep 17 00:00:00 2001 From: Rajat Chopra Date: Wed, 28 Nov 2018 16:48:09 -0500 Subject: [PATCH 2/2] hack: pin the os release build name One environment variable to be used when building the pinned release binary: RHCOS_BUILD_NAME: a string representing the build name(or rather number e.g. 47.48). If empty, then the latest one will be picked up. This could just be hardcoded in the hack/build.sh script before making the release branch so that it stays baked in. --- hack/build.sh | 4 ++++ pkg/asset/ignition/bootstrap/bootstrap.go | 2 +- pkg/rhcos/builds.go | 18 +++++++++++++----- 3 files changed, 18 insertions(+), 6 deletions(-) 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()