Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion hack/boilerplate/boilerplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@

verbose_out = sys.stderr if args.verbose else open("/dev/null", "w")

default_skipped_dirs = ['Godeps', '.git', 'vendor', 'third_party', '_gopath', '_output']
default_skipped_dirs = ['Godeps', '.git', 'vendor', 'third_party', '_gopath', '_output', '.cache']

# list all the files that contain 'DO NOT EDIT', but are not generated
default_skipped_not_generated = []
Expand Down Expand Up @@ -127,6 +127,10 @@ def file_content_passes(data, filename, ref, extension, generated, regexs):

data, _ = replace_specials(data, extension, regexs)

if len(regexs["copyright"].findall(data)) > 1:
print('File %s has the boilerplate header more than once' % filename, file=verbose_out)
return False

data = data.splitlines()

# if our test file is smaller than the reference it surely fails!
Expand Down Expand Up @@ -294,6 +298,7 @@ def get_regexs():
regexs["shebang"] = re.compile(r"^(#!.*\n)\n*", re.MULTILINE)
# Search for generated files
regexs["generated"] = re.compile('DO NOT EDIT')
regexs["copyright"] = re.compile(r'Copyright.*The Kubernetes Authors\.')
return regexs


Expand Down
11 changes: 11 additions & 0 deletions hack/boilerplate/boilerplate_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,17 @@ def test_replace_specials(self):
self.assertEqual(actual_content, expected_content)
self.assertEqual(actual_match, expected_match)

def test_duplicate_boilerplate_header_fails(self):
refs = boilerplate.get_refs()
regexs = boilerplate.get_regexs()
data = "\n".join(refs["go"] + refs["go"] + ["package main"])

passes = boilerplate.file_content_passes(
data, "duplicate.go", refs["go"], "go", False, regexs
)

self.assertFalse(passes)

def test_ensure_command_line_flag(self):
os.chdir("./testdata/default/")
boilerplate.args.ensure = True
Expand Down
6 changes: 3 additions & 3 deletions hack/boilerplate/testdata/default/fail.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

# Copyright 2022 The Kubernetes Authors.
# Copyright 2022 Invalid Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

## invalid header
## invalid header on purpose

exit_code=42
exit $exit_code
exit $exit_code
14 changes: 0 additions & 14 deletions hack/check-capi-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# Copyright 2025 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.
#
# Bash Strict Mode: https://github.com/guettli/bash-strict-mode
trap 'echo -e "\n🤷 🚨 🔥 Warning: A command has failed. Exiting the script. Line was ($0:$LINENO): $(sed -n "${LINENO}p" "$0" 2>/dev/null || true) 🔥 🚨 🤷 "; exit 3' ERR
set -Eeuo pipefail
Expand Down
2 changes: 1 addition & 1 deletion hack/lint-links.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ if [[ -z ${GITHUB_TOKEN:-} ]]; then
exit 1
fi
lychee --verbose --config .lychee.toml --root-dir . --cache \
./*.md ./docs/**/*.md 2>&1 | sed -nE '/\[(200|EXCLUDED)\]/!p'
./*.md ./docs/**/*.md 2>&1 | sed -nE '/\[(200|EXCLUDED)\]/!p'
16 changes: 8 additions & 8 deletions hack/test-unit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ if [[ -n ${KUBEBUILDER_ASSETS:-} ]]; then
echo "This env var gets set automatically"
exit 1
fi
if ! ./hack/tools/bin/setup-envtest list | grep -q "$KUBEBUILDER_ENVTEST_KUBERNETES_VERSION"; then
echo "./hack/tools/bin/setup-envtest is outdated. It does not support $KUBEBUILDER_ENVTEST_KUBERNETES_VERSION."
echo "Remove ./hack/tools/bin/setup-envtest and call make again."
exit 1
fi

unset KUBEBUILDER_ASSETS

KUBEBUILDER_ASSETS=$(./hack/tools/bin/setup-envtest use \
if ! KUBEBUILDER_ASSETS=$(./hack/tools/bin/setup-envtest use \
--bin-dir "$PWD/hack/tools/bin" -p path \
"$KUBEBUILDER_ENVTEST_KUBERNETES_VERSION")
"$KUBEBUILDER_ENVTEST_KUBERNETES_VERSION"); then
echo "Unable to resolve envtest assets for Kubernetes $KUBEBUILDER_ENVTEST_KUBERNETES_VERSION."
echo "Maybe this helps:"
echo " rm -rf hack/tools/bin/setup-envtest"
echo " make setup-envtest"
exit 1
fi

if [[ ! -e $KUBEBUILDER_ASSETS ]]; then
echo "$KUBEBUILDER_ASSETS does not exist. Check our setup."
Expand Down
13 changes: 0 additions & 13 deletions test/helpers/mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

/*
Copyright 2022 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.
*/

package helpers

import (
Expand Down
Loading