Skip to content

Commit

Permalink
Merge pull request kubernetes-sigs#77 from amy/verify
Browse files Browse the repository at this point in the history
Verify manifests script
  • Loading branch information
k8s-ci-robot authored Aug 6, 2019
2 parents 4693461 + 7245971 commit 0c38ba3
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ TOOLS_DIR := hack/tools
CONTROLLER_GEN_BIN := bin/controller-gen
CONTROLLER_GEN := $(TOOLS_DIR)/$(CONTROLLER_GEN_BIN)

# Allow overriding manifest generation destination directory
MANIFEST_ROOT ?= "config"
CRD_ROOT ?= "$(MANIFEST_ROOT)/crd/bases"
WEBHOOK_ROOT ?= "$(MANIFEST_ROOT)/webhook"
RBAC_ROOT ?= "$(MANIFEST_ROOT)/rbac"

# Active module mode, as we use go modules to manage dependencies
export GO111MODULE=on

Expand Down Expand Up @@ -54,7 +60,7 @@ deploy: manifests
# Generate manifests e.g. CRD, RBAC etc.
.PHONY: manifests
manifests: $(CONTROLLER_GEN)
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
$(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)

# Run go fmt against code
.PHONY: fmt
Expand Down
7 changes: 7 additions & 0 deletions hack/verify-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ outputs=()

# run all verify scripts, optionally skipping any of them

if [[ "${VERIFY_MANIFESTS:-true}" == "true" ]]; then
echo "[*] Verifying manifests..."
out=$(hack/verify-manifests.sh 2>&1)
failure $? "verify-manifests.sh" "${out}"
cd "${REPO_PATH}"
fi

if [[ "${VERIFY_WHITESPACE:-true}" == "true" ]]; then
echo "[*] Verifying whitespace..."
out=$(hack/verify-whitespace.sh 2>&1)
Expand Down
42 changes: 42 additions & 0 deletions hack/verify-manifests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env bash
# Copyright 2019 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit
set -o nounset
set -o pipefail

REPO_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
DIFFROOT="${REPO_ROOT}/config"
TMP_ROOT="${REPO_ROOT}/_tmp"


cleanup() {
rm -rf "${TMP_ROOT}"
}
trap "cleanup" EXIT SIGINT
cleanup

MANIFEST_ROOT=$TMP_ROOT make manifests

echo "diffing ${DIFFROOT} against freshly generated manifests"
ret=0
git diff --no-index --diff-filter=MD --stat ${TMP_ROOT} ${DIFFROOT} || ret=$?
if [[ $ret -eq 0 ]]
then
echo "Manifests in ${DIFFROOT} are up to date."
else
echo "Manifests in ${DIFFROOT} are out of date. Please run \`make manifests\`"
exit 1
fi

0 comments on commit 0c38ba3

Please sign in to comment.