Skip to content

Commit 5ae01fc

Browse files
Merge pull request #5268 from cheesesashimi/zzlotnik/fix-image-registry-error-handling
OCPBUGS-60157: ensure that images are rebuilt if they do not exist
2 parents 9db4a37 + 859a273 commit 5ae01fc

File tree

14 files changed

+1371
-446
lines changed

14 files changed

+1371
-446
lines changed

Makefile

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,18 @@ else
116116
GO111MODULE=on go build -o $(GOPATH)/bin/golangci-lint ./vendor/github.com/golangci/golangci-lint/cmd/golangci-lint
117117
endif
118118

119+
SKOPEO := $(shell command -v skopeo 2> /dev/null)
120+
install-skopeo:
121+
ifdef SKOPEO
122+
@echo "Found skopeo"
123+
skopeo --version
124+
else
125+
@echo "Installing skopeo"
126+
./hack/install-skopeo.sh
127+
endif
128+
129+
# install-skopeo is purposely omitted from this target because it is only
130+
# needed for a single test target (test-e2e-ocl).
119131
install-tools: install-golangci-lint install-go-junit-report install-setup-envtest
120132

121133
# Runs golangci-lint
@@ -210,8 +222,9 @@ test-e2e-techpreview: install-go-junit-report
210222
test-e2e-single-node: install-go-junit-report
211223
set -o pipefail; go test -tags=$(GOTAGS) -failfast -timeout 120m -v$${WHAT:+ -run="$$WHAT"} ./test/e2e-single-node/ | ./hack/test-with-junit.sh $(@)
212224

213-
test-e2e-ocl: install-go-junit-report
214-
set -o pipefail; go test -tags=$(GOTAGS) -failfast -timeout 120m -v$${WHAT:+ -run="$$WHAT"} ./test/e2e-ocl/ | ./hack/test-with-junit.sh $(@)
225+
test-e2e-ocl: install-go-junit-report install-skopeo
226+
# Temporarily include /tmp/skopeo/bin in our PATH variable so that the test suite can find skopeo.
227+
set -o pipefail; PATH="$(PATH):/tmp/skopeo/bin" go test -tags=$(GOTAGS) -failfast -timeout 190m -v$${WHAT:+ -run="$$WHAT"} ./test/e2e-ocl/ | ./hack/test-with-junit.sh $(@)
215228

216229
bootstrap-e2e: install-go-junit-report install-setup-envtest
217230
@echo "Setting up KUBEBUILDER_ASSETS"

devex/cmd/mco-builder/local.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/openshift/machine-config-operator/devex/internal/pkg/utils"
1616
ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common"
1717
"github.com/openshift/machine-config-operator/test/framework"
18+
"github.com/openshift/machine-config-operator/test/helpers"
1819
"github.com/spf13/cobra"
1920
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2021
aggerrs "k8s.io/apimachinery/pkg/util/errors"
@@ -192,7 +193,7 @@ func buildLocallyAndPushIntoCluster(cs *framework.ClientSet, buildOpts localBuil
192193
}
193194
}()
194195

195-
extHostname, err := rollout.ExposeClusterImageRegistry(cs)
196+
extHostname, err := helpers.ExposeClusterImageRegistry(context.TODO(), cs)
196197
if err != nil {
197198
return err
198199
}

devex/cmd/mco-builder/revert.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/openshift/machine-config-operator/devex/internal/pkg/rollout"
88
ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common"
99
"github.com/openshift/machine-config-operator/test/framework"
10+
"github.com/openshift/machine-config-operator/test/helpers"
1011
"github.com/spf13/cobra"
1112
apierrs "k8s.io/apimachinery/pkg/api/errors"
1213
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -34,7 +35,7 @@ func doRevert(_ *cobra.Command, _ []string) error {
3435
return fmt.Errorf("could not revert to original MCO image: %w", err)
3536
}
3637

37-
if err := rollout.UnexposeClusterImageRegistry(cs); err != nil {
38+
if err := helpers.UnexposeClusterImageRegistry(context.TODO(), cs); err != nil {
3839
return fmt.Errorf("could not unexpose cluster image registry: %w", err)
3940
}
4041

devex/internal/pkg/rollout/external.go

Lines changed: 0 additions & 125 deletions
This file was deleted.

hack/install-skopeo.sh

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env bash
2+
3+
set -xeuo
4+
5+
# This is an installation script for skopeo. skopeo is needed by the
6+
# e2e-gcp-op-ocl test suite since it pushes and pulls images around.
7+
#
8+
# Using a build-root image for this is the preferred approach (see:
9+
# https://docs.ci.openshift.org/docs/architecture/ci-operator/#build-root-image)
10+
# since skopeo can be installed via dnf at build-time. However, that process is
11+
# a bit more involved. While it would ultimately pay off, it is not in-scope
12+
# with the bug that is being resolved.
13+
#
14+
# Because of limitations within the builder container image and the context it
15+
# runs in, certain adaptations must be made:
16+
# - The builder image does not run as a privileged user and is denied privilege
17+
# escalation. This means that running dnf install -y skopeo cannot be done.
18+
# - The builder image does not have jq installed. This means we need to use
19+
# Python for any JSON parsing we need to perform instead.
20+
# - Because this runs as a non-privileged user, we cannot run the make install
21+
# step for skopeo. Instead, we need to append /tmp/skopeo/bin to the PATH. This
22+
# is done in the Makefile and only for the go test invocation.
23+
24+
OPENSHIFT_CI="${OPENSHIFT_CI:-""}"
25+
26+
install_skopeo() {
27+
# If we've already built skopeo once, check if it works and then return.
28+
if [ -f /tmp/skopeo/bin/skopeo ]; then
29+
echo "Prebuilt skopeo found at /tmp/skopeo/bin/skopeo, skipping installation"
30+
/tmp/skopeo/bin/skopeo --version
31+
return 0
32+
fi
33+
34+
# Get the most recent tagged version of skopeo.
35+
skopeo_version="$(curl -s https://api.github.com/repos/containers/skopeo/releases/latest | python3 -c 'import sys, json; print(json.load(sys.stdin)["tag_name"])')"
36+
37+
echo "Installing skopeo $skopeo_version from source"
38+
39+
skopeo_clone_dir="/tmp/skopeo"
40+
41+
mkdir -p "$skopeo_clone_dir"
42+
43+
# Shallow-clone the skopeo repo to the local repo dir.
44+
git clone --branch "$skopeo_version" --depth 1 https://github.com/containers/skopeo.git "$skopeo_clone_dir"
45+
46+
cd "$skopeo_clone_dir"
47+
48+
# Build skopeo
49+
make bin/skopeo
50+
}
51+
52+
# Check if we have skopeo installed first.
53+
if command -v skopeo >/dev/null 2>&1 ; then
54+
# If we do, just output its version.
55+
skopeo --version
56+
else
57+
# Check if we're running in CI.
58+
if [ "$OPENSHIFT_CI" == "true" ]; then
59+
# Only when we're in CI should we install skopeo.
60+
install_skopeo
61+
else
62+
# Otherwise, we should exit with a clear error.
63+
echo "Missing required binary 'skopeo'"
64+
exit 1
65+
fi
66+
fi

0 commit comments

Comments
 (0)