Skip to content

Commit edd89ad

Browse files
authored
Merge pull request kubernetes-csi#251 from jsafrane/add-logcheck
Add test-logcheck target
2 parents d7535ae + 043fd09 commit edd89ad

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

build.make

+7
Original file line numberDiff line numberDiff line change
@@ -322,3 +322,10 @@ test-spelling:
322322
test-boilerplate:
323323
@ echo; echo "### $@:"
324324
@ ./release-tools/verify-boilerplate.sh "$(pwd)"
325+
326+
# Test klog usage. This test is optional and must be explicitly added to `test` target in the main Makefile:
327+
# test: test-logcheck
328+
.PHONY: test-logcheck
329+
test-logcheck:
330+
@ echo; echo "### $@:"
331+
@ ./release-tools/verify-logcheck.sh

verify-logcheck.sh

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2024 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# This script uses the logcheck tool to analyze the source code
18+
# for proper usage of klog contextual logging.
19+
20+
set -o errexit
21+
set -o nounset
22+
set -o pipefail
23+
24+
LOGCHECK_VERSION=${1:-0.8.2}
25+
26+
# This will canonicalize the path
27+
CSI_LIB_UTIL_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. && pwd -P)
28+
29+
# Create a temporary directory for installing logcheck and
30+
# set up a trap command to remove it when the script exits.
31+
CSI_LIB_UTIL_TEMP=$(mktemp -d 2>/dev/null || mktemp -d -t csi-lib-utils.XXXXXX)
32+
trap 'rm -rf "${CSI_LIB_UTIL_TEMP}"' EXIT
33+
34+
echo "Installing logcheck to temp dir: sigs.k8s.io/logtools/logcheck@v${LOGCHECK_VERSION}"
35+
GOBIN="${CSI_LIB_UTIL_TEMP}" go install "sigs.k8s.io/logtools/logcheck@v${LOGCHECK_VERSION}"
36+
echo "Verifing logcheck: ${CSI_LIB_UTIL_TEMP}/logcheck -check-contextual ${CSI_LIB_UTIL_ROOT}/..."
37+
"${CSI_LIB_UTIL_TEMP}/logcheck" -check-contextual -check-with-helpers "${CSI_LIB_UTIL_ROOT}/..."

0 commit comments

Comments
 (0)