Skip to content

Commit 4451823

Browse files
pseudomutoprafull01
authored andcommitted
Add support for make test/preflight-<target>
Adding targets for running preflight tests. These only work on Linux machines since preflight is currently not available on other platforms. The preflight tasks all assume you've got a running OpenShift cluster and that GCP_PROJECT and KUBECONFIG are set accordingly in the env.
1 parent 0e93ede commit 4451823

File tree

8 files changed

+145
-4
lines changed

8 files changed

+145
-4
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,5 @@ bundle/
6363
faq
6464

6565
_artifacts
66-
bundle.Dockerfile
66+
artifacts
6767
tmp

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,12 @@ test/e2e/testrunner-openshift-packaging: test/openshift-package
210210
--action_env=APP_VERSION=$(APP_VERSION) \
211211
--action_env=DOCKER_REGISTRY=$(DOCKER_REGISTRY)
212212

213+
# Run preflight checks for OpenShift. This expects a running OpenShift cluster.
214+
# Eg. make test/preflight-<operator|bundle|marketplace>
215+
test/preflight-%: CONTAINER=$*
216+
test/preflight-%: release/generate-bundle
217+
@bazel run //hack:redhat-preflight -- $(CONTAINER)
218+
213219
#
214220
# Different dev targets
215221
#
@@ -267,6 +273,7 @@ dev/up: dev/down
267273

268274
.PHONY: dev/down
269275
dev/down:
276+
@bazel build //hack/bin:k3d
270277
@hack/dev.sh down
271278
#
272279
# Targets that allow to install the operator on an existing cluster

config/default/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ k8s_deploy(
3434
# when running locally, use the image from the local codebase
3535
"cockroachdb/cockroach-operator:$(APP_VERSION)": "//cmd/cockroach-operator:operator_image",
3636
},
37+
resolver_args = ["--allow_unused_images"],
3738
template = ":manifest",
3839
)
3940

config/manifests/bases/cockroach-operator.clusterserviceversion.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ spec:
178178
179179
name: Cockroach Labs Support
180180
maturity: stable
181+
minKubeVersion: 1.18.0
181182
provider:
182183
name: Cockroach Labs
183184
version: 0.0.0

config/templates/csv.yaml.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ spec:
178178
179179
name: Cockroach Labs Support
180180
maturity: stable
181+
minKubeVersion: 1.18.0
181182
provider:
182183
name: Cockroach Labs
183184
version: 0.0.0

hack/BUILD.bazel

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,17 @@ sh_binary(
129129
],
130130
)
131131

132+
sh_binary(
133+
name = "redhat-preflight",
134+
srcs = ["redhat.sh"],
135+
data = [
136+
JQ,
137+
OPM,
138+
"//hack/bin:preflight",
139+
"@//:all-srcs",
140+
],
141+
)
142+
132143
filegroup(
133144
name = "package-srcs",
134145
srcs = glob(["**"]),

hack/bundle.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,19 @@ generate_bundle() {
8585
mv "${dir}/metadata/annotations.yaml.new" "${dir}/metadata/annotations.yaml"
8686

8787
# add supported openshift versions
88-
echo " com.redhat.openshift.versions: 4.7-4.9" >> "${dir}/metadata/annotations.yaml"
88+
echo " com.redhat.openshift.versions: 4.7-4.10" >> "${dir}/metadata/annotations.yaml"
8989

9090
# Update CSV with correct images, and timestamps
9191
adapt_csv "${dir}" "${img}"
9292

9393
# move the dockerfile into the bundle directory and make it valid
9494
sed \
95-
-e "s+${dir}/++g" bundle.Dockerfile \ # fix up paths
96-
-e "/\s*COPY tests/d" > "${dir}/Dockerfile" # remove scorecard tests
95+
-e "/\s*tests\/scorecard/d" \
96+
-e "s+${dir}/++g" \
97+
bundle.Dockerfile > "${dir}/Dockerfile"
9798

9899
rm bundle.Dockerfile
100+
rm "${dir}/manifests/cockroach-operator-webhook-service_v1_service.yaml"
99101
}
100102

101103
adapt_csv() {

hack/redhat.sh

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2022 The Cockroach Authors
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
set -euo pipefail
17+
18+
# include bazel binaries in the path
19+
PATH="bazel-bin/hack/bin:${PATH}"
20+
21+
# Global preflight settings
22+
export PFLT_DOCKERCONFIG="${HOME}/.docker/config.json"
23+
export PFLT_LOGLEVEL=debug
24+
25+
OPERATOR="cockroachdb/cockroach-operator"
26+
REGISTRY="gcr.io/${GCP_PROJECT}"
27+
VERSION="$(cat version.txt)"
28+
IMAGE="${OPERATOR}:v${VERSION}"
29+
BUNDLE_IMAGE="${OPERATOR}-bundle:v${VERSION}"
30+
BUNDLE_INDEX="${OPERATOR}-index:v${VERSION}"
31+
RHMP_BUNDLE_IMAGE="${OPERATOR}-bundle-rhmp:v${VERSION}"
32+
RHMP_BUNDLE_INDEX="${OPERATOR}-index-rhmp:v${VERSION}"
33+
34+
main() {
35+
# Switch to the build directory. The bundle directory is not part of source
36+
# controller and therefore isn't a bazel target. This means when we run this
37+
# script, there's no way to reference the Dockerfile created by the call to
38+
# make release/generate-bundle (prerequisite of make test/preflight). By cd'ing
39+
# into the build directory, we'll have access to _all_ the files.
40+
if [[ -n "${BUILD_WORKSPACE_DIRECTORY}" ]]; then
41+
cd "${BUILD_WORKSPACE_DIRECTORY}"
42+
fi
43+
44+
case "${1:-}" in
45+
operator)
46+
publish_operator_image
47+
preflight_operator;;
48+
bundle)
49+
publish_bundle_image "${REGISTRY}/${BUNDLE_IMAGE}" "bundle/cockroachdb-certified"
50+
publish_bundle_index "${REGISTRY}/${BUNDLE_IMAGE}" "${REGISTRY}/${BUNDLE_INDEX}"
51+
preflight_bundle "${REGISTRY}/${BUNDLE_IMAGE}" "${REGISTRY}/${BUNDLE_INDEX}"
52+
ensure_success;;
53+
marketplace)
54+
publish_bundle_image "${REGISTRY}/${RHMP_BUNDLE_IMAGE}" "bundle/cockroachdb-certified-rhmp"
55+
publish_bundle_index "${REGISTRY}/${RHMP_BUNDLE_IMAGE}" "${REGISTRY}/${RHMP_BUNDLE_INDEX}"
56+
preflight_bundle "${REGISTRY}/${RHMP_BUNDLE_IMAGE}" "${REGISTRY}/${RHMP_BUNDLE_INDEX}"
57+
ensure_success;;
58+
*)
59+
echo "ERROR: Unknown command: ${1}" 1>&2
60+
echo "Usage bazel run //hack:redhat-preflight -- <operator|bundle|marketplace>." 1>&2
61+
exit 1;;
62+
esac
63+
}
64+
65+
publish_operator_image() {
66+
echo "Publishing operator image to local repo..."
67+
APP_VERSION="v${VERSION}" \
68+
DOCKER_REGISTRY="${REGISTRY}" \
69+
DOCKER_IMAGE_REPOSITORY="${IMAGE%:*}" \
70+
bazel run --stamp --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 //:push_operator_image
71+
}
72+
73+
preflight_operator() {
74+
echo "Running preflight checks on operator image..."
75+
preflight check container "${REGISTRY}/${IMAGE}" \
76+
--docker-config "${HOME}/.docker/config.json"
77+
}
78+
79+
publish_bundle_image() {
80+
local img="${1}"
81+
local dir="${2}"
82+
83+
echo "Publishing ${img}..."
84+
pushd "${dir}"
85+
docker build -t "${img}" .
86+
docker push "${img}"
87+
popd
88+
}
89+
90+
publish_bundle_index() {
91+
local bundle_img="${1}"
92+
local index_img="${2}"
93+
94+
echo "Publishing ${index_img}..."
95+
opm index add \
96+
--container-tool docker \
97+
--bundles "${bundle_img}" \
98+
--tag "${index_img}"
99+
}
100+
101+
preflight_bundle() {
102+
local bundle_img="${1}"
103+
local index_img="${2}"
104+
105+
echo "Running preflight checks on bundle image..."
106+
echo " IMAGE: ${bundle_img}"
107+
108+
PFLT_INDEXIMAGE="${index_img}" preflight check operator "${bundle_img}"
109+
}
110+
111+
ensure_success() {
112+
if [[ $(cat artifacts/results.json | jq -r .passed) == 'false' ]]; then
113+
# error already displayed
114+
exit 1
115+
fi
116+
}
117+
118+
main "$@"

0 commit comments

Comments
 (0)