From 98728bbdb9113fad52ab44486e9f319aafc44a76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Martins?= Date: Mon, 27 Apr 2020 11:42:34 +0200 Subject: [PATCH] add checker for deepcopy generated code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To avoid code from being merged without being regenerated, this commit adds a checker, that will only run in the CI, to verify if there is code ungenerated. Signed-off-by: André Martins --- Makefile | 5 +++++ contrib/scripts/check-k8s-code-gen.sh | 22 ++++++++++++++++++++++ test/provision/compile.sh | 2 +- 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100755 contrib/scripts/check-k8s-code-gen.sh diff --git a/Makefile b/Makefile index 898c3468b977..bbb90272c622 100644 --- a/Makefile +++ b/Makefile @@ -32,6 +32,7 @@ BENCHFLAGS ?= $(BENCHFLAGS_EVAL) LOGLEVEL ?= "error" SKIP_VET ?= "false" SKIP_KVSTORES ?= "false" +SKIP_K8S_CODE_GEN_CHECK ?= "true" JOB_BASE_NAME ?= cilium_test @@ -424,6 +425,10 @@ microk8s: check-microk8s @echo " microk8s.kubectl -n kube-system delete pod -l k8s-app=cilium" precheck: ineffassign logging-subsys-field +ifeq ($(SKIP_K8S_CODE_GEN_CHECK),"false") + @$(ECHO_CHECK) contrib/scripts/check-k8s-code-gen.sh + $(QUIET) contrib/scripts/check-k8s-code-gen.sh +endif @$(ECHO_CHECK) contrib/scripts/check-fmt.sh $(QUIET) contrib/scripts/check-fmt.sh @$(ECHO_CHECK) contrib/scripts/check-log-newlines.sh diff --git a/contrib/scripts/check-k8s-code-gen.sh b/contrib/scripts/check-k8s-code-gen.sh new file mode 100755 index 000000000000..47eab81c02d3 --- /dev/null +++ b/contrib/scripts/check-k8s-code-gen.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +set -e +set -o pipefail + +# Delete all zz_generated.deepcopy.go files +find . -not -path "./vendor/*" -iname "*zz_generated.deepcopy.go" -exec rm {} \; + +# Generate all files +make generate-k8s-api + +# Check for diff +diff="$(git diff)" + +if [ -n "$diff" ]; then + echo "Ungenerated deepcopy source code:" + echo "$diff" + echo "Please run make generate-k8s-api and submit your changes" + exit 1 +fi + +exit 0 diff --git a/test/provision/compile.sh b/test/provision/compile.sh index 0d94e6fbe482..5d4ef28e1b8c 100755 --- a/test/provision/compile.sh +++ b/test/provision/compile.sh @@ -72,7 +72,7 @@ then fi else echo "compiling cilium..." - sudo -u vagrant -H -E make LOCKDEBUG=1 SKIP_DOCS=true + sudo -u vagrant -H -E make LOCKDEBUG=1 SKIP_K8S_CODE_GEN_CHECK=false SKIP_DOCS=true echo "installing cilium..." make install mkdir -p /etc/sysconfig/