Skip to content
Merged
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
k8s.io/client-go v0.32.2
k8s.io/code-generator v0.32.2
k8s.io/kube-openapi v0.0.0-20241212222426-2c72e554b1e7
knative.dev/hack v0.0.0-20250314171439-742e1e50da78
knative.dev/hack v0.0.0-20250318155814-8f599b7a828c
knative.dev/pkg v0.0.0-20250312035536-b7bbf4be5dbd
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -685,8 +685,8 @@ k8s.io/kube-openapi v0.0.0-20241212222426-2c72e554b1e7 h1:hcha5B1kVACrLujCKLbr8X
k8s.io/kube-openapi v0.0.0-20241212222426-2c72e554b1e7/go.mod h1:GewRfANuJ70iYzvn+i4lezLDAFzvjxZYK1gn1lWcfas=
k8s.io/utils v0.0.0-20241210054802-24370beab758 h1:sdbE21q2nlQtFh65saZY+rRM6x6aJJI8IUa1AmH/qa0=
k8s.io/utils v0.0.0-20241210054802-24370beab758/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
knative.dev/hack v0.0.0-20250314171439-742e1e50da78 h1:K3cI9khmEm63uwnm2S6ZFq1r/nsJFDXtUHqPnyKdnCM=
knative.dev/hack v0.0.0-20250314171439-742e1e50da78/go.mod h1:R0ritgYtjLDO9527h5vb5X6gfvt5LCrJ55BNbVDsWiY=
knative.dev/hack v0.0.0-20250318155814-8f599b7a828c h1:WbSdxtzL02rpfF6KNbAFnWLMCE9TFfrfD39VqgsCuOA=
knative.dev/hack v0.0.0-20250318155814-8f599b7a828c/go.mod h1:R0ritgYtjLDO9527h5vb5X6gfvt5LCrJ55BNbVDsWiY=
knative.dev/pkg v0.0.0-20250312035536-b7bbf4be5dbd h1:KXG6bACwjKSZcT0JxyQDVYLcDPSip+7l6sVULeITi7k=
knative.dev/pkg v0.0.0-20250312035536-b7bbf4be5dbd/go.mod h1:OuszA8pcsXmO+Pp4QCtD10ph6tjRPFN+LrF/XgAMDb8=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
Expand Down
40 changes: 32 additions & 8 deletions hack/boilerplate/add-boilerplate.sh → hack/add-boilerplate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

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

# shellcheck disable=SC1090
source "$(GOFLAGS='-mod=mod' go run knative.dev/hack/cmd/script codegen-library.sh)"

USAGE=$(cat <<EOF
Add boilerplate.<ext>.txt to all .<ext> files missing it in a directory.

Expand All @@ -22,17 +29,34 @@ Usage: (from repository root)

Example: (from repository root)
./hack/boilerplate/add-boilerplate.sh go cmd

As of now, only .go files are supported.
EOF
)

set -e

if [[ -z $1 || -z $2 ]]; then
echo "${USAGE}"
if [ -z "${1:-}" ] || [ -z "${2:-}" ]; then
error Invalid arguments
echo "${USAGE}" 1>&2
exit 1
fi

grep -r -L -P "Copyright \d+ The Knative Authors" $2 \
| grep -P "\.$1\$" \
| xargs -I {} sh -c \
"cat hack/boilerplate/boilerplate.$1.txt {} > /tmp/boilerplate && mv /tmp/boilerplate {}"
if ! [[ "$1" = "go" ]]; then
error Unsupported file extension
echo "${USAGE}" 1>&2
exit 2
fi

cnt=0
while read -r file; do
if grep -q -E "^Copyright [[:digit:]]+ The Knative Authors$" "$file"; then
continue
fi
cat "$(boilerplate)" > "$file".bck
echo '' >> "$file".bck
cat "$file" >> "$file".bck
mv "$file".bck "$file"
log License added to "$file"
cnt=$(( cnt + 1))
done < <(find "$2" -type f -name "*.$1")

log License added to $cnt files
15 changes: 0 additions & 15 deletions hack/boilerplate/boilerplate.go.txt

This file was deleted.

15 changes: 0 additions & 15 deletions hack/boilerplate/boilerplate.sh.txt

This file was deleted.

5 changes: 3 additions & 2 deletions hack/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
# limitations under the License.


source $(dirname $0)/../vendor/knative.dev/hack/release.sh
# shellcheck disable=SC1090
source "$(GOFLAGS='-mod=mod' go run knative.dev/hack/cmd/script release.sh)"

declare -A COMPONENTS
COMPONENTS=(
Expand Down Expand Up @@ -43,4 +44,4 @@ function build_release() {
ARTIFACTS_TO_PUBLISH="${all_yamls[@]}"
}

main $@
main "$@"
14 changes: 7 additions & 7 deletions hack/update-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ set -o errexit
set -o nounset
set -o pipefail

source $(dirname $0)/../vendor/knative.dev/hack/codegen-library.sh
export PATH="$GOBIN:$PATH"
# shellcheck disable=SC1090
source "$(GOFLAGS='-mod=mod' go run knative.dev/hack/cmd/script codegen-library.sh)"

echo "=== Update Codegen for ${MODULE_NAME}"

Expand All @@ -28,23 +28,23 @@ group "Kubernetes Codegen"
source "${CODEGEN_PKG}/kube_codegen.sh"

kube::codegen::gen_client \
--boilerplate "${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt" \
--boilerplate "$(boilerplate)" \
--output-dir "${REPO_ROOT_DIR}/pkg/client" \
--output-pkg "knative.dev/sample-controller/pkg/client" \
--with-watch \
"${REPO_ROOT_DIR}/pkg/apis"

kube::codegen::gen_helpers \
--boilerplate "${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt" \
--boilerplate "$(boilerplate)" \
"${REPO_ROOT_DIR}/pkg"

group "Knative Codegen"

# Knative Injection
${KNATIVE_CODEGEN_PKG}/hack/generate-knative.sh "injection" \
"${KNATIVE_CODEGEN_PKG}/hack/generate-knative.sh" "injection" \
knative.dev/sample-controller/pkg/client knative.dev/sample-controller/pkg/apis \
"samples:v1alpha1" \
--go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt
--go-header-file "$(boilerplate)"

group "Update CRD Schema"

Expand All @@ -55,4 +55,4 @@ go run sigs.k8s.io/controller-tools/cmd/[email protected] \

group "Update deps post-codegen"
# Make sure our dependencies are up-to-date
${REPO_ROOT_DIR}/hack/update-deps.sh
"${REPO_ROOT_DIR}/hack/update-deps.sh"
3 changes: 2 additions & 1 deletion hack/update-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ set -o errexit
set -o nounset
set -o pipefail

source $(dirname "$0")/../vendor/knative.dev/hack/library.sh
# shellcheck disable=SC1090
source "$(GOFLAGS='-mod=mod' go run knative.dev/hack/cmd/script library.sh)"

go_update_deps "$@"
48 changes: 14 additions & 34 deletions hack/verify-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,18 @@ set -o errexit
set -o nounset
set -o pipefail

readonly REPO_ROOT_DIR="$(git rev-parse --show-toplevel)"
readonly TMP_DIFFROOT="$(mktemp -d -p ${REPO_ROOT_DIR})"

cleanup() {
rm -rf "${TMP_DIFFROOT}"
}

trap "cleanup" EXIT SIGINT

cleanup

# Save working tree state
mkdir -p "${TMP_DIFFROOT}/pkg"
cp -aR "${REPO_ROOT_DIR}/go.sum" "${REPO_ROOT_DIR}/pkg" "${REPO_ROOT_DIR}/vendor" "${TMP_DIFFROOT}"

# TODO(mattmoor): We should be able to rm -rf pkg/client/ and vendor/

"${REPO_ROOT_DIR}/hack/update-codegen.sh"
echo "Diffing ${REPO_ROOT_DIR} against freshly generated codegen"
ret=0
diff -Naupr "${REPO_ROOT_DIR}/pkg" "${TMP_DIFFROOT}/pkg" || ret=1
diff -Naupr --no-dereference "${REPO_ROOT_DIR}/vendor" "${TMP_DIFFROOT}/vendor" || ret=1

# Restore working tree state
rm -fr "${TMP_DIFFROOT}/config"
rm -fr "${REPO_ROOT_DIR}/go.sum" "${REPO_ROOT_DIR}/pkg" "${REPO_ROOT_DIR}/vendor"
cp -aR "${TMP_DIFFROOT}"/* "${REPO_ROOT_DIR}"

if [[ $ret -eq 0 ]]
then
echo "${REPO_ROOT_DIR} up to date."
else
echo "ERROR: ${REPO_ROOT_DIR} is out of date. Please run ./hack/update-codegen.sh"
exit 1
# shellcheck disable=SC1090
source "$(GOFLAGS='-mod=mod' go run knative.dev/hack/cmd/script library.sh)"

"${REPO_ROOT_DIR}"/hack/update-codegen.sh

if ! git diff --exit-code --name-only > /dev/null; then
error 'Modified files found:'
git diff --name-only
error 'Difference:'
git --no-pager diff
abort "${MODULE_NAME} is out of date!" "" \
"Please, run ./hack/update-codegen.sh and commit."
fi

header "${MODULE_NAME} is up to date."
4 changes: 2 additions & 2 deletions test/presubmit-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
# Markdown linting failures don't show up properly in Gubernator resulting
# in a net-negative contributor experience.
export DISABLE_MD_LINTING=1
export GO111MODULE=on

source $(dirname $0)/../vendor/knative.dev/hack/presubmit-tests.sh
# shellcheck disable=SC1090
source "$(GOFLAGS='-mod=mod' go run knative.dev/hack/cmd/script presubmit-tests.sh)"

# TODO(mattmoor): integration tests

Expand Down
2 changes: 1 addition & 1 deletion vendor/knative.dev/hack/boilerplate.go.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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
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,
Expand Down
4 changes: 2 additions & 2 deletions vendor/knative.dev/hack/codegen-library.sh
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ function restore-changes-if-its-copyright-year-only() {
git diff --name-only > "$difflist"
while read -r file; do
# check if the file contains just the change in the boilerplate year
if [ "$(LANG=C git diff --exit-code --shortstat -- "$file")" = ' 1 file changed, 1 insertion(+), 1 deletion(-)' ] && \
[[ "$(git diff --exit-code -U1 -- "$file" | grep -Ec '^[+-]\s*[*#]?\s*Copyright 2[0-9]{3}')" -eq 2 ]]; then
if [ "$(LANG=C git diff --ignore-space-change --exit-code --shortstat -- "$file")" = ' 1 file changed, 1 insertion(+), 1 deletion(-)' ] && \
[[ "$(git diff --ignore-space-change --exit-code -U1 -- "$file" | grep -Ec '^[+-]\s*[*#]?\s*Copyright 2[0-9]{3}')" -eq 2 ]]; then
# restore changes to that file
git checkout -- "$file"
fi
Expand Down
2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ k8s.io/utils/net
k8s.io/utils/pointer
k8s.io/utils/ptr
k8s.io/utils/trace
# knative.dev/hack v0.0.0-20250314171439-742e1e50da78
# knative.dev/hack v0.0.0-20250318155814-8f599b7a828c
## explicit; go 1.21
knative.dev/hack
# knative.dev/pkg v0.0.0-20250312035536-b7bbf4be5dbd
Expand Down
Loading