Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] 🧹 Using scripts without relying on vendor dir #8056

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions .github/workflows/kind-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
uses: ko-build/[email protected]

- name: Check out code onto GOPATH
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Install KinD
run: |
Expand Down Expand Up @@ -110,7 +110,7 @@ jobs:
- name: Wait for things to be up
run: |
set -e
source ./vendor/knative.dev/hack/infra-library.sh
source "$(go run knative.dev/hack/cmd/script infra-library.sh)"
wait_until_pods_running ${SYSTEM_NAMESPACE}
- name: Run e2e Tests
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ require (
sigs.k8s.io/yaml v1.4.0
)

replace knative.dev/hack => github.com/cardil/knative-hack v0.0.0-20240718135939-e922902857fa

require (
contrib.go.opencensus.io/exporter/ocagent v0.7.1-0.20200907061046-05415f1de66d // indirect
contrib.go.opencensus.io/exporter/prometheus v0.4.2 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM
github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=
github.com/blendle/zapdriver v1.3.1 h1:C3dydBOWYRiOk+B8X9IVZ5IOe+7cl+tGOexN4QqHfpE=
github.com/blendle/zapdriver v1.3.1/go.mod h1:mdXfREi6u5MArG4j9fewC+FGnXaBR+T4Ox4J2u4eHCc=
github.com/cardil/knative-hack v0.0.0-20240718135939-e922902857fa h1:MNJ+q3m8/Gnw5j0Xk5/Sn6AnfrVVhXH8f2cR01cAz1U=
github.com/cardil/knative-hack v0.0.0-20240718135939-e922902857fa/go.mod h1:R0ritgYtjLDO9527h5vb5X6gfvt5LCrJ55BNbVDsWiY=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/census-instrumentation/opencensus-proto v0.4.1 h1:iKLQ0xPNFxR/2hzXZMrBo8f1j86j5WHzznCCQxV/b8g=
github.com/census-instrumentation/opencensus-proto v0.4.1/go.mod h1:4T9NM4+4Vw91VeyqjLS6ao50K5bOcLKN6Q42XnYaRYw=
Expand Down Expand Up @@ -838,8 +840,6 @@ k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 h1:aVUu9fTY98ivBPKR9Y5w/A
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00/go.mod h1:AsvuZPBlUDVuCdzJ87iajxtXuR9oktsTctW/R9wwouA=
k8s.io/utils v0.0.0-20240102154912-e7106e64919e h1:eQ/4ljkx21sObifjzXwlPKpdGLrCfRziVtos3ofG/sQ=
k8s.io/utils v0.0.0-20240102154912-e7106e64919e/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
knative.dev/hack v0.0.0-20240704013904-b9799599afcf h1:n92FmZRywgtHso7pFAku7CW0qvRAs1hXtMQqO0R6eiE=
knative.dev/hack v0.0.0-20240704013904-b9799599afcf/go.mod h1:yk2OjGDsbEnQjfxdm0/HJKS2WqTLEFg/N6nUs6Rqx3Q=
knative.dev/hack/schema v0.0.0-20240704013904-b9799599afcf h1:AUfdS2IxgjNLc7jplP7Xk/SPnk0c/40G1TvrkZ07UKU=
knative.dev/hack/schema v0.0.0-20240704013904-b9799599afcf/go.mod h1:3pWwBLnTZSM9psSgCAvhKOHIPTzqfEMlWRpDu6IYhK0=
knative.dev/pkg v0.0.0-20240708181110-b4e5f07a2c37 h1:YJopww8+M2C6vdiKzHAP98917VxEZhkBJ66P3ilhU/4=
Expand Down
5 changes: 3 additions & 2 deletions hack/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
# Documentation about this script and how to use it can be found
# at https://github.com/knative/test-infra/tree/main/ci

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

function build_release() {
# Run `generate-yamls.sh`, which should be versioned with the
Expand All @@ -32,4 +33,4 @@ function build_release() {
fi
}

main $@
main "$@"
2 changes: 1 addition & 1 deletion hack/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ limitations under the License.
package tools

import (
_ "knative.dev/hack"
_ "knative.dev/hack/cmd/script"
_ "knative.dev/pkg/configmap/hash-gen"
_ "knative.dev/pkg/hack"

Expand Down
7 changes: 4 additions & 3 deletions hack/update-checksums.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ if [ -z "${GOPATH:-}" ]; then
export GOPATH=$(go env GOPATH)
fi

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

go run "${REPO_ROOT_DIR}/vendor/knative.dev/pkg/configmap/hash-gen" "${REPO_ROOT_DIR}"/config/core/configmaps/*.yaml
go run "${REPO_ROOT_DIR}/vendor/knative.dev/pkg/configmap/hash-gen" "${REPO_ROOT_DIR}"/config/channels/in-memory-channel/configmaps/*.yaml
go run knative.dev/pkg/configmap/hash-gen "${REPO_ROOT_DIR}"/config/core/configmaps/*.yaml
go run knative.dev/pkg/configmap/hash-gen "${REPO_ROOT_DIR}"/config/channels/in-memory-channel/configmaps/*.yaml
30 changes: 14 additions & 16 deletions hack/update-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,55 +18,53 @@ set -o errexit
set -o nounset
set -o pipefail

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

# If we run with -mod=vendor here, then generate-groups.sh looks for vendor files in the wrong place.
export GOFLAGS=-mod=

echo "=== Update Codegen for $MODULE_NAME"
log.step "Update Codegen for $MODULE_NAME"

# Compute _example hash for all configmaps.
group "Generating checksums for configmap _example keys"

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

group "Kubernetes Codegen"

# generate the code with:
# --output-base because this script should also be able to run inside the vendor dir of
# k8s.io/kubernetes. The output-base is needed for the generators to output into the vendor dir
# instead of the $GOPATH directly. For normal projects this can be dropped.
${CODEGEN_PKG}/generate-groups.sh "deepcopy,client,informer,lister" \
generate-groups "deepcopy,client,informer,lister" \
knative.dev/eventing/pkg/client knative.dev/eventing/pkg/apis \
"sinks:v1alpha1 eventing:v1alpha1 eventing:v1beta1 eventing:v1beta2 eventing:v1beta3 eventing:v1 messaging:v1 flows:v1 sources:v1beta2 sources:v1" \
--go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt
"sinks:v1alpha1 eventing:v1alpha1 eventing:v1beta1 eventing:v1beta2 eventing:v1beta3 eventing:v1 messaging:v1 flows:v1 sources:v1beta2 sources:v1"

# Deep copy config
${GOPATH}/bin/deepcopy-gen \
"${GOBIN}/deepcopy-gen" \
-O zz_generated.deepcopy \
--go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt \
--go-header-file "$(boilerplate)" \
-i knative.dev/eventing/pkg/apis/config \
-i knative.dev/eventing/pkg/apis/messaging/config \

# Only deepcopy the Duck types, as they are not real resources.
${CODEGEN_PKG}/generate-groups.sh "deepcopy" \
generate-groups "deepcopy" \
knative.dev/eventing/pkg/client knative.dev/eventing/pkg/apis \
"duck:v1beta1 duck:v1alpha1 duck:v1" \
--go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt
"duck:v1beta1 duck:v1alpha1 duck:v1"

group "Knative Codegen"

# Knative Injection
${KNATIVE_CODEGEN_PKG}/hack/generate-knative.sh "injection" \
generate-knative "injection" \
knative.dev/eventing/pkg/client knative.dev/eventing/pkg/apis \
"sinks:v1alpha1 eventing:v1alpha1 eventing:v1beta1 eventing:v1beta2 eventing:v1beta3 eventing:v1 messaging:v1 flows:v1 sources:v1beta2 sources:v1 duck:v1beta1 duck:v1" \
--go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt
"sinks:v1alpha1 eventing:v1alpha1 eventing:v1beta1 eventing:v1beta2 eventing:v1beta3 eventing:v1 messaging:v1 flows:v1 sources:v1beta2 sources:v1 duck:v1beta1 duck:v1"

group "Generating API reference docs"

${REPO_ROOT_DIR}/hack/update-reference-docs.sh
"${REPO_ROOT_DIR}/hack/update-reference-docs.sh"

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"
5 changes: 3 additions & 2 deletions hack/update-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ set -o errexit
set -o nounset
set -o pipefail

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

$(dirname $0)/update-cert-manager.sh
"$(dirname "$0")/update-cert-manager.sh"

go_update_deps "$@"
7 changes: 4 additions & 3 deletions hack/update-reference-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ if [ -z "${GOPATH:-}" ]; then
export GOPATH=$(go env GOPATH)
fi

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

(
cd ${REPO_ROOT_DIR}
go run "${REPO_ROOT_DIR}/vendor/github.com/ahmetb/gen-crd-api-reference-docs" \
cd "${REPO_ROOT_DIR}"
go run github.com/ahmetb/gen-crd-api-reference-docs \
-out-file "docs/eventing-api.md" \
-api-dir "knative.dev/eventing/pkg/apis" \
-template-dir "${REPO_ROOT_DIR}/vendor/github.com/ahmetb/gen-crd-api-reference-docs/template" \
Expand Down
5 changes: 3 additions & 2 deletions hack/verify-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ set -o pipefail

export GO111MODULE=on

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

readonly TMP_DIFFROOT="$(mktemp -d ${REPO_ROOT_DIR}/tmpdiffroot.XXXXXX)"
readonly TMP_DIFFROOT="$(mktemp -d "${REPO_ROOT_DIR}/tmpdiffroot.XXXXXX")"

cleanup() {
rm -rf "${TMP_DIFFROOT}"
Expand Down
3 changes: 2 additions & 1 deletion test/e2e-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@

export GO111MODULE=on

source "$(dirname "${BASH_SOURCE[0]}")/../vendor/knative.dev/hack/e2e-tests.sh"
# shellcheck disable=SC1090
source "$(go run knative.dev/hack/cmd/script e2e-tests.sh)"

# If gcloud is not available make it a no-op, not an error.
which gcloud &>/dev/null || gcloud() { echo "[ignore-gcloud $*]" 1>&2; }
Expand Down
4 changes: 3 additions & 1 deletion test/presubmit-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
export GO111MODULE=on

export KO_FLAGS="--platform=linux/amd64"
source "$(dirname "${BASH_SOURCE[0]}")/../vendor/knative.dev/hack/presubmit-tests.sh"

# shellcheck disable=SC1090
source "$(go run knative.dev/hack/cmd/script presubmit-tests.sh)"

# We use the default build, unit and integration test runners.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2021 The Knative Authors
Copyright #{YEAR} The Knative Authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
49 changes: 49 additions & 0 deletions vendor/knative.dev/hack/cmd/script/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Vendorless Knative

The Knative projects can be built without a vendor directory. This is a
convenience for developers, and brings a number of benefits:

* It is easier to see the changes to the code and review them.
* It is easier to maintain the build and CI scripts, as they don't need to
filter out the vendor directory.
* The project doesn't look dated (the proper dependency management tools
are available for Go since 1.13+).
* No vendor directory means less possibility of accidentally traversing
into it by symlinks or scripts.

For more details and reasons for avoiding the vendor directory, see
[knative/infra#134](https://github.com/knative/infra/issues/134).

## Status

The [knative/infra#134](https://github.com/knative/infra/issues/134) is
ongoing effort. Currently, it is possible to use make projects vendorless,
only if they don't use Knative nor Kubernetes code-generation tools. See the
epic issue for current status.

## Migration to a vendorless project

The following steps are required to migrate a project to be vendorless:

1. Update the `knative.dev/hack` dependency to the latest version.
1. Update the project scripts to use the scripts inflation:
```patch
-source $(dirname $0)/../vendor/knative.dev/hack/release.sh
+source "$(go run knative.dev/hack/cmd/script release.sh)"
```
1. Update the `hack/tools.go` file to refer to the `knative.dev/hack/cmd/script`
tool:
```go
package hack

import (
_ "knative.dev/hack/cmd/script"
)
```
1. Remove the `vendor` directory.
1. Run `hack/update-deps.sh` to update the `go.mod` file(s).

### Examples of migrated projects

* [knative/func#1966](https://github.com/knative/func/pull/1966)
* [knative-extensions/kn-plugin-event#307](https://github.com/knative-extensions/kn-plugin-event/pull/307)
28 changes: 28 additions & 0 deletions vendor/knative.dev/hack/cmd/script/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
Copyright 2022 The Knative 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
https://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 main

import "knative.dev/hack/pkg/inflator/cli"

func main() {
cli.ExecuteOrDie(cli.Options...)
}

// RunMain is used by tests to run the main function.
func RunMain() { // nolint:deadcode
main()
}
Loading
Loading