Skip to content

Commit 3931892

Browse files
author
Arjun Naik
committed
Boilerplate: Update to 946651c6eb6934f25ff1c80d8f99dc07eea3ff85
Conventions: - openshift/golang-osd-operator: Update --- openshift/boilerplate@f435f4a...946651c commit: 7e944022e0b144fed844626bd2ef163b50e8f268 author: Eric Fried Minor fixups A grab-bag of small nonfunctional changes. - Add some more formatting to the output of openshift/golang-osd-operator's `update` script. - Consistent error formatting in prow-config (fup from openshift/boilerplate#75 (comment)) - Rename a handful of test case files from snake_case to kebab-case for consistency. - Get rid of trailing whitespace, which shows up in annoying ugly red in diffs when consumers onboard. commit: f5b3cf91cd8c7637136d8cad0b5932788a2dc0d5 author: Eric Fried README: Add a "Quick Start" section commit: b5b9ec147f85ab6f3003864714066465b090bcea author: Eric Fried Run image build in a temp directory The build script was valiantly trying to clean up after itself, but was leaving a few things behind: ``` sh-4.2$ git status On branch master Untracked files: (use "git add <file>..." to include in what will be committed) config.log config.mak.autogen config.status git.tar.gz ``` ...which were causing CI failures when they ended up in the image used for pr-check. This refactor moves all the processing to a temp directory which it blows away when done. commit: d82ff2ab073455b0c2a81a82fc2ac4ba6828ee57 author: Eric Fried Set up in-repo prow build root commit: 263bf0b41ad795368c087e8b8fec2db9f5c60e07 author: Eric Fried openshift/golang-osd-operator: prow config script Add a script to generate standard prow configuration for openshift/golang-osd-operator subscribers in an openshift/release clone. Invoke as `make prow-config` or `make RELEASE_CLONE=/path/to/existing/clone/of/openshift/release prow-config` Jira: [OSD-5421](https://issues.redhat.com/browse/OSD-5421) commit: 14b7dc1dfa8b4ce3078f1c4551c53b78b5bbae9c author: Eric Fried Fix bracing in push.sh D'oh. I copied the skopeo commands from [the `make` target](https://github.com/openshift/boilerplate/pull/72/files#diff-76ed074a9305c04054cdebb9e9aad2d818052b07091de1f20cad0bbac34ffb52L30-L35) and I didn't notice that the variable interpolation was using parentheses rather than curly braces. Fixed. And since this messes with the build config, I need to publish a new image tag. (We'll never use `image-v0.1.0`.) commit: 6dddc7040d9299961a6c538c9cb6b7a05577cdb4 author: Eric Fried Consumers build/test with tagged images The openshift/golang-osd-operator convention now syncs the image used by prow and appsre by editing build/Dockerfile and .ci-operator.yaml. The image tag used in both is the latest `image-v*` tag from the boilerplate repository. commit: 3fbe8859e36c7c377b8d9407886176bfb61d9331 author: Arjun Naik Added variable for git hash Signed-off-by: Arjun Naik <anaik@redhat.com> commit: 6be78b08d4db67808b28b7435e0057c5a9dc97e1 author: Arjun Naik Added a missing double quotes Signed-off-by: Arjun Naik <anaik@redhat.com> commit: cd79e932726e39ee96d03be44be9fe74e3d777a7 author: Arjun Naik Fixed the build and push with skopeo Signed-off-by: Arjun Naik <anaik@redhat.com>
1 parent d88c563 commit 3931892

File tree

11 files changed

+244
-27
lines changed

11 files changed

+244
-27
lines changed

.ci-operator.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
build_root_image:
22
namespace: openshift
3-
name: release
4-
tag: golang-1.13
3+
name: boilerplate
4+
tag: image-v0.1.2
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
f435f4ab6213d69d6ffbe493435e8b062cf54684
1+
946651c6eb6934f25ff1c80d8f99dc07eea3ff85

boilerplate/_lib/common.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
err() {
2-
echo "$@" >&2
2+
echo "==ERROR== $@" >&2
33
exit 1
44
}
55

@@ -52,3 +52,9 @@ fi
5252
if [ -z "$BOILERPLATE_GIT_CLONE" ]; then
5353
export BOILERPLATE_GIT_CLONE="git clone $BOILERPLATE_GIT_REPO"
5454
fi
55+
56+
# The namespace of the ImageStream by which prow will import the image.
57+
IMAGE_NAMESPACE=openshift
58+
IMAGE_NAME=boilerplate
59+
# The public image location
60+
IMAGE_PULL_PATH=quay.io/app-sre/$IMAGE_NAME:$LATEST_IMAGE_TAG

boilerplate/_lib/freeze-check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ cd $TMPD
4949
git init
5050
# TODO(efried): DRY this remote. Make it configurable?
5151
git remote add origin $BOILERPLATE_GIT_REPO
52-
git fetch origin $(cat $LBCF)
52+
git fetch origin $(cat $LBCF) --tags
5353
git reset --hard FETCH_HEAD
5454

5555
# Now invoke the update script, bypassing the exec step because we
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
build_root_image:
2-
namespace: openshift
3-
name: release
4-
tag: golang-1.13
2+
namespace: __NAMESPACE__
3+
name: __NAME__
4+
tag: __TAG__

boilerplate/openshift/golang-osd-operator/README.md

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ include boilerplate/generated-includes.mk
1313
```
1414

1515
One of the primary purposes of these `make` targets is to allow you to
16-
standardize your prow and app-sre pipeline configurations. They should be as
17-
follows:
16+
standardize your prow and app-sre pipeline configurations using the
17+
following:
1818

1919
### Prow
2020

@@ -23,16 +23,19 @@ follows:
2323
| `validate` | Ensure code generation has not been forgotten; and ensure generated and boilerplate code has not been modified. |
2424
| `lint` | Perform static analysis. |
2525
| `test` | "Local" unit and functional testing. |
26-
| `coverage` | (Code coverage)[#code-coverage] analysis and reporting. |
27-
| `build` | Code compilation and bundle generation. |
26+
| `coverage` | [Code coverage](#code-coverage) analysis and reporting. |
2827

29-
In addition to configuring these test targets, make sure your
30-
`build_root` stanza is configured to use the configuration from your
31-
repository, which is provided by this convention:
28+
To standardize your prow configuration, you may run:
3229

33-
```yaml
34-
build_root:
35-
from_repository: true
30+
```shell
31+
$ make prow-config
32+
```
33+
34+
If you already have the openshift/release repository cloned locally, you
35+
may specify its path via `$RELEASE_CLONE`:
36+
37+
```shell
38+
$ make RELEASE_CLONE=/home/me/github/openshift/release prow-config
3639
```
3740

3841
### app-sre
@@ -61,7 +64,7 @@ run code coverage analysis per [this SOP](https://github.com/openshift/ops-sop/b
6164
The convention embeds default checks to ensure generated code generation is current, committed, and unaltered.
6265
To trigger the check, you can use `make generate-check` provided your Makefile properly includes the boilerplate-generated include `boilerplate/generated-includes.mk`.
6366

64-
Checks consist of :
67+
Checks consist of:
6568
* Checking all files are committed to ensure a safe point to revert to in case of error
6669
* Running the `make generate` command to regenerate the needed code
6770
* Checking if this results in any new uncommitted files in the git project or if all is clean.
Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
#!/bin/bash -e
2+
3+
REPO_ROOT=$(git rev-parse --show-toplevel)
4+
source $REPO_ROOT/boilerplate/_lib/common.sh
5+
6+
cmd=${0##*/}
7+
8+
release_repo=openshift/release
9+
10+
usage() {
11+
cat <<EOF
12+
Usage: $cmd [PATH_TO_RELEASE_CLONE]
13+
14+
Creates a delta in $release_repo standardizing prow configuration for a
15+
boilerplate consumer. Must be invoked from within a local clone of a repository
16+
already subscribed to the $CONVENTION_NAME convention.
17+
18+
Parameters:
19+
PATH_TO_RELEASE_CLONE File system path to a local clone of
20+
https://github.com/$release_repo. If not
21+
specified, the repository will be cloned in a
22+
temporary directory.
23+
EOF
24+
exit -1
25+
}
26+
27+
repo_name() {
28+
(git -C $1 config --get remote.upstream.url || git -C $1 config --get remote.origin.url) | sed 's,.*:,,; s/\.git$//'
29+
}
30+
31+
# Was a release repo clone specified?
32+
release_clone=
33+
if [[ $# -eq 1 ]]; then
34+
# Special cases for usage queries
35+
if [[ "$1" == '-'* ]] || [[ "$1" == help ]]; then
36+
usage
37+
fi
38+
39+
[[ -d $1 ]] || err "
40+
$1: Not a directory."
41+
42+
[[ $(repo_name $1) == "$release_repo" ]] || err "
43+
$1 is not a clone of $release_repo; or its 'origin' remote is not set properly."
44+
45+
# Got a usable clone of openshift/release
46+
release_clone=$1
47+
48+
elif [[ $# -ne 0 ]]; then
49+
usage
50+
fi
51+
52+
consumer=$(repo_name .)
53+
[[ -z "$consumer" ]] && err "
54+
Failed to determine current repository name"
55+
56+
consumer_org=${consumer%/*}
57+
[[ -z "$consumer_org" ]] && err "
58+
Failed to determine consumer org"
59+
60+
consumer_name=${consumer#*/}
61+
[[ -z "$consumer_name" ]] && err "
62+
Failed to determine consumer name"
63+
64+
# This will be something like refs/remotes/origin/master
65+
default_branch=$(git symbolic-ref refs/remotes/origin/HEAD)
66+
[[ -z "$default_branch" ]] && err "
67+
Failed to determine default branch name"
68+
# Strip off refs/remotes/origin/
69+
default_branch=${default_branch##*/}
70+
[[ -z "$default_branch" ]] && err "
71+
Failed to determine default branch name"
72+
73+
# Make sure we were invoked from a boilerplate consumer.
74+
[[ -z "$CONVENTION_NAME" ]] && err "
75+
$cmd must be invoked from a consumer of an appropriate convention. Where did you get this script from?"
76+
# Or at least not from boilerplate itself
77+
[[ "$consumer" == "openshift/boilerplate" ]] && err "
78+
$cmd must be invoked from a boilerplate consumer, not from boilerplate itself."
79+
80+
[[ -s $CONVENTION_ROOT/_data/last-boilerplate-commit ]] || err "
81+
$cmd must be invoked from a boilerplate consumer!"
82+
83+
grep -E -q "^$CONVENTION_NAME(\s.*)?$" $CONVENTION_ROOT/update.cfg || err "
84+
$consumer is not subscribed to $CONVENTION_NAME!"
85+
86+
# Due to the DPTP-1640 workaround, we need to be even stricter, since we have
87+
# to copy in the ImageStreamTag config.
88+
# TODO: Get rid of this check, and $ci_config, and its usage in the config
89+
# dump, once DPTP-1640 is resolved.
90+
ci_config=$REPO_ROOT/.ci-operator.yaml
91+
[[ -s $ci_config ]] || err "
92+
.ci-operator.yaml not found! Do you need to 'make boilerplate-update'?"
93+
94+
# If a release repo clone wasn't specified, create one
95+
if [[ -z "$release_clone" ]]; then
96+
release_clone=$(mktemp -dt openshift_release_XXXXXXX)
97+
git clone git@github.com:${release_repo}.git $release_clone
98+
else
99+
[[ -z "$(git -C $release_clone status --porcelain)" ]] || err "
100+
Your release clone must start clean."
101+
# These will blow up if it's misconfigured
102+
git -C $release_clone checkout master
103+
git -C $release_clone pull
104+
fi
105+
106+
cd $release_clone
107+
release_branch=$consumer_org-$consumer_name-$default_branch-boilerplate-prow-config
108+
config_dir=ci-operator/config/${consumer_org}/${consumer_name}
109+
config=${consumer_org}-${consumer_name}-${default_branch}.yaml
110+
[[ -f $config_dir/$config ]] || err "
111+
$release_repo bootstrapping is not fully supported! Recommend running 'make new-repo' first!
112+
To circumvent this warning (not recommended), run:
113+
114+
git -C $release_clone checkout -b $release_branch
115+
mkdir -p $release_clone/$config_dir
116+
touch $release_clone/$config_dir/$config
117+
git -C $release_clone add $config_dir/$config
118+
git -C $release_clone commit
119+
$0 $release_clone"
120+
121+
# If we get here, the config file exists. Replace it.
122+
# TODO: Edit it instead, replacing only the relevant sections. This would allow
123+
# the consumer to preserve any additional checks they want in prow.
124+
cat <<EOF > $config_dir/$config
125+
base_images:
126+
temporarily_needed_to_make_this_image_appear_in_all_build_clusters_see_jira_dptp_1640:
127+
$(sed -n '2,5s/^/ /p' $ci_config)
128+
build_root:
129+
from_repository: true
130+
resources:
131+
'*':
132+
limits:
133+
memory: 4Gi
134+
requests:
135+
cpu: 100m
136+
memory: 200Mi
137+
tests:
138+
- as: coverage
139+
commands: |
140+
export CODECOV_TOKEN=\$(cat /tmp/secret/CODECOV_TOKEN)
141+
make coverage
142+
container:
143+
from: src
144+
secret:
145+
mount_path: /tmp/secret
146+
name: ${consumer_name}-codecov-token
147+
- as: publish-coverage
148+
commands: |
149+
export CODECOV_TOKEN=\$(cat /tmp/secret/CODECOV_TOKEN)
150+
make coverage
151+
container:
152+
from: src
153+
postsubmit: true
154+
secret:
155+
mount_path: /tmp/secret
156+
name: ${consumer_name}-codecov-token
157+
- as: lint
158+
commands: make lint
159+
container:
160+
from: src
161+
- as: test
162+
commands: make test
163+
container:
164+
from: src
165+
- as: validate
166+
commands: make validate
167+
container:
168+
from: src
169+
zz_generated_metadata:
170+
branch: ${default_branch}
171+
org: ${consumer_org}
172+
repo: ${consumer_name}
173+
EOF
174+
175+
make jobs
176+
177+
echo
178+
git status
179+
180+
cat <<EOF
181+
182+
Ready to commit, push, and create a PR in $release_clone
183+
You may wish to:
184+
185+
cd $release_clone
186+
git checkout -b $release_branch
187+
git add -A
188+
git commit
189+
git push origin $release_branch
190+
EOF

boilerplate/openshift/golang-osd-operator/standard.mk

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,11 @@ python-venv:
119119
$(eval PYTHON := .venv/bin/python3)
120120

121121
.PHONY: generate-check
122-
generate-check:
123-
@$(MAKE) -s isclean --no-print-directory
122+
generate-check:
123+
@$(MAKE) -s isclean --no-print-directory
124124
@$(MAKE) -s generate --no-print-directory
125125
@$(MAKE) -s isclean --no-print-directory || (echo 'Files after generation are different than committed ones. Please commit updated and unaltered generated files' >&2 && exit 1)
126-
@echo "All generated files are up-to-date and unaltered"
126+
@echo "All generated files are up-to-date and unaltered"
127127

128128
.PHONY: yaml-validate
129129
yaml-validate: python-venv
@@ -133,6 +133,10 @@ yaml-validate: python-venv
133133
olm-deploy-yaml-validate: python-venv
134134
${PYTHON} ${CONVENTION_DIR}/validate-yaml.py $(shell git ls-files 'deploy/*.yaml' 'deploy/*.yml')
135135

136+
.PHONY: prow-config
137+
prow-config:
138+
${CONVENTION_DIR}/prow-config ${RELEASE_CLONE}
139+
136140
######################
137141
# Targets used by prow
138142
######################

boilerplate/openshift/golang-osd-operator/update

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,21 @@ source $CONVENTION_ROOT/_lib/common.sh
88
# Expect POST
99
[[ "$1" == "POST" ]] || err "Got a parameter I don't understand: '$1'. Did the infrastructure change?"
1010

11-
for f in .codecov.yml .ci-operator.yaml; do
12-
echo "Copying $f to your repository root."
13-
cp ${HERE}/$f $REPO_ROOT
14-
done
11+
echo "Copying .codecov.yml to your repository root."
12+
cp ${HERE}/.codecov.yml $REPO_ROOT
13+
14+
# TODO: boilerplate more of Dockerfile
15+
echo "Overwriting build/Dockerfile's initial FROM with $IMAGE_PULL_PATH"
16+
sed -i "1s,.*,FROM $IMAGE_PULL_PATH AS builder," build/Dockerfile
17+
18+
echo "Writing .ci-operator.yaml in your repository root with:"
19+
echo " namespace: $IMAGE_NAMESPACE"
20+
echo " name: $IMAGE_NAME"
21+
echo " tag: $LATEST_IMAGE_TAG"
22+
sed "s/__NAMESPACE__/$IMAGE_NAMESPACE/; s/__NAME__/$IMAGE_NAME/; s/__TAG__/$LATEST_IMAGE_TAG/" ${HERE}/.ci-operator.yaml > $REPO_ROOT/.ci-operator.yaml
1523

1624
cat <<EOF
25+
1726
=====================
1827
THINGS YOU NEED TO DO
1928
=====================
@@ -32,4 +41,6 @@ include boilerplate/generated-includes.mk
3241
3342
- Make sure your prow and app-sre pipeline configurations use the
3443
build_root configuration and standard targets described in the README.
44+
=====================
45+
3546
EOF

boilerplate/update

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ if [ ! -f "$CONFIG_FILE" ]; then
140140
exit 1
141141
fi
142142

143+
# The most recent build image tag. Export this for individual `update` scripts.
144+
export LATEST_IMAGE_TAG=$(cd $BP_CLONE; git describe --tags --abbrev=0 --match image-v*)
145+
143146
# Prepare the "nexus makefile include".
144147
NEXUS_MK="${CONVENTION_ROOT}/generated-includes.mk"
145148
cat <<EOF>"${NEXUS_MK}"

0 commit comments

Comments
 (0)