Skip to content
This repository was archived by the owner on Jul 30, 2021. It is now read-only.

Commit 0c38ba3

Browse files
authored
Merge pull request #77 from amy/verify
Verify manifests script
2 parents 4693461 + 7245971 commit 0c38ba3

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ TOOLS_DIR := hack/tools
1919
CONTROLLER_GEN_BIN := bin/controller-gen
2020
CONTROLLER_GEN := $(TOOLS_DIR)/$(CONTROLLER_GEN_BIN)
2121

22+
# Allow overriding manifest generation destination directory
23+
MANIFEST_ROOT ?= "config"
24+
CRD_ROOT ?= "$(MANIFEST_ROOT)/crd/bases"
25+
WEBHOOK_ROOT ?= "$(MANIFEST_ROOT)/webhook"
26+
RBAC_ROOT ?= "$(MANIFEST_ROOT)/rbac"
27+
2228
# Active module mode, as we use go modules to manage dependencies
2329
export GO111MODULE=on
2430

@@ -54,7 +60,7 @@ deploy: manifests
5460
# Generate manifests e.g. CRD, RBAC etc.
5561
.PHONY: manifests
5662
manifests: $(CONTROLLER_GEN)
57-
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
63+
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:dir=$(CRD_ROOT) output:webhook:dir=$(WEBHOOK_ROOT) output:rbac:dir=$(RBAC_ROOT)
5864

5965
# Run go fmt against code
6066
.PHONY: fmt

hack/verify-all.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ outputs=()
3838

3939
# run all verify scripts, optionally skipping any of them
4040

41+
if [[ "${VERIFY_MANIFESTS:-true}" == "true" ]]; then
42+
echo "[*] Verifying manifests..."
43+
out=$(hack/verify-manifests.sh 2>&1)
44+
failure $? "verify-manifests.sh" "${out}"
45+
cd "${REPO_PATH}"
46+
fi
47+
4148
if [[ "${VERIFY_WHITESPACE:-true}" == "true" ]]; then
4249
echo "[*] Verifying whitespace..."
4350
out=$(hack/verify-whitespace.sh 2>&1)

hack/verify-manifests.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2019 The Kubernetes Authors.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
set -o errexit
17+
set -o nounset
18+
set -o pipefail
19+
20+
REPO_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
21+
DIFFROOT="${REPO_ROOT}/config"
22+
TMP_ROOT="${REPO_ROOT}/_tmp"
23+
24+
25+
cleanup() {
26+
rm -rf "${TMP_ROOT}"
27+
}
28+
trap "cleanup" EXIT SIGINT
29+
cleanup
30+
31+
MANIFEST_ROOT=$TMP_ROOT make manifests
32+
33+
echo "diffing ${DIFFROOT} against freshly generated manifests"
34+
ret=0
35+
git diff --no-index --diff-filter=MD --stat ${TMP_ROOT} ${DIFFROOT} || ret=$?
36+
if [[ $ret -eq 0 ]]
37+
then
38+
echo "Manifests in ${DIFFROOT} are up to date."
39+
else
40+
echo "Manifests in ${DIFFROOT} are out of date. Please run \`make manifests\`"
41+
exit 1
42+
fi

0 commit comments

Comments
 (0)