From 7245971ce50b3053df4fb098c4693a0f75a12b57 Mon Sep 17 00:00:00 2001 From: Amy Chen Date: Mon, 5 Aug 2019 14:03:38 -0700 Subject: [PATCH] verify manifests script --- Makefile | 8 +++++++- hack/verify-all.sh | 7 +++++++ hack/verify-manifests.sh | 42 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100755 hack/verify-manifests.sh diff --git a/Makefile b/Makefile index b347fcc14735..2d805660bb89 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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 diff --git a/hack/verify-all.sh b/hack/verify-all.sh index 402a46f78208..abfc5e28db31 100755 --- a/hack/verify-all.sh +++ b/hack/verify-all.sh @@ -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) diff --git a/hack/verify-manifests.sh b/hack/verify-manifests.sh new file mode 100755 index 000000000000..a69e074b9b58 --- /dev/null +++ b/hack/verify-manifests.sh @@ -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