mirror of
https://github.com/vmware-tanzu/pinniped.git
synced 2026-01-05 21:15:26 +00:00
Merge branch 'main' into jtc/merge-main-at-d7849c79-to-github
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Copyright 2022-2023 the Pinniped contributors. All Rights Reserved.
|
||||
# Copyright 2022-2024 the Pinniped contributors. All Rights Reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
set -euo pipefail
|
||||
@@ -11,11 +11,13 @@ cd "${ROOT}"
|
||||
# Print the Go version.
|
||||
go version
|
||||
|
||||
# Install the same version of the linter that is used in the CI pipelines
|
||||
lint_version="v$(cat hack/lib/lint-version.txt)"
|
||||
|
||||
echo "Installing golangci-lint@${lint_version}"
|
||||
|
||||
# Install the same version of the linter that the pipelines will use
|
||||
# so you can get the same results when running the linter locally.
|
||||
# Whenever the linter is updated in the CI pipelines, it should also be
|
||||
# updated here to make local development more convenient.
|
||||
go install -v github.com/golangci/golangci-lint/cmd/golangci-lint@v1.55.1
|
||||
go install -v "github.com/golangci/golangci-lint/cmd/golangci-lint@${lint_version}"
|
||||
golangci-lint --version
|
||||
|
||||
echo "Finished. You may need to run 'rehash' in your current shell before using the new version (e.g. if you are using gvm)."
|
||||
|
||||
1
hack/lib/lint-version.txt
Normal file
1
hack/lib/lint-version.txt
Normal file
@@ -0,0 +1 @@
|
||||
1.58.1
|
||||
@@ -7,47 +7,6 @@ set -euo pipefail
|
||||
|
||||
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
|
||||
function tidy_cmd() {
|
||||
local version="$(cat "${ROOT}/go.mod" | grep '^go ' | cut -f 2 -d ' ')"
|
||||
echo "go mod tidy -v -go=${version} -compat=${version}"
|
||||
}
|
||||
|
||||
function lint_cmd() {
|
||||
echo "golangci-lint run --modules-download-mode=readonly --timeout=30m"
|
||||
}
|
||||
|
||||
function test_cmd() {
|
||||
echo "go test -count 1 -race ./..."
|
||||
}
|
||||
|
||||
function unittest_cmd() {
|
||||
echo "go test -short -race ./..."
|
||||
}
|
||||
|
||||
function with_modules() {
|
||||
local cmd_function="${1}"
|
||||
cmd="$(${cmd_function})"
|
||||
|
||||
# start the cache mutation detector by default so that cache mutators will be found
|
||||
local kube_cache_mutation_detector="${KUBE_CACHE_MUTATION_DETECTOR:-true}"
|
||||
|
||||
# panic the server on watch decode errors since they are considered coder mistakes
|
||||
local kube_panic_watch_decode_error="${KUBE_PANIC_WATCH_DECODE_ERROR:-true}"
|
||||
|
||||
env_vars="KUBE_CACHE_MUTATION_DETECTOR=${kube_cache_mutation_detector} KUBE_PANIC_WATCH_DECODE_ERROR=${kube_panic_watch_decode_error}"
|
||||
|
||||
pushd "${ROOT}" >/dev/null
|
||||
for mod_file in $(find . -maxdepth 4 -not -path "./generated/*" -name go.mod | sort); do
|
||||
mod_dir="$(dirname "${mod_file}")"
|
||||
(
|
||||
echo "=> "
|
||||
echo " cd ${mod_dir} && ${env_vars} ${cmd}"
|
||||
cd "${mod_dir}" && env ${env_vars} ${cmd}
|
||||
)
|
||||
done
|
||||
popd >/dev/null
|
||||
}
|
||||
|
||||
function usage() {
|
||||
echo "Error: <task> must be specified"
|
||||
echo " module.sh <task> [tidy, lint, test, unittest]"
|
||||
@@ -55,20 +14,41 @@ function usage() {
|
||||
}
|
||||
|
||||
function main() {
|
||||
pushd "${ROOT}" > /dev/null
|
||||
|
||||
# start the cache mutation detector by default so that cache mutators will be found
|
||||
local kube_cache_mutation_detector="${KUBE_CACHE_MUTATION_DETECTOR:-true}"
|
||||
|
||||
# panic the server on watch decode errors since they are considered coder mistakes
|
||||
local kube_panic_watch_decode_error="${KUBE_PANIC_WATCH_DECODE_ERROR:-true}"
|
||||
|
||||
case "${1:-invalid}" in
|
||||
'tidy')
|
||||
with_modules 'tidy_cmd'
|
||||
local version="$(cat "${ROOT}/go.mod" | grep '^go ' | cut -f 2 -d ' ')"
|
||||
go mod tidy -v -go=${version} -compat=${version}
|
||||
;;
|
||||
'lint' | 'linter' | 'linters')
|
||||
golangci-lint --version
|
||||
echo
|
||||
with_modules 'lint_cmd'
|
||||
go version
|
||||
golangci-lint run --modules-download-mode=readonly --timeout=30m
|
||||
;;
|
||||
'test' | 'tests')
|
||||
with_modules 'test_cmd'
|
||||
'lint_in_docker')
|
||||
local lint_version
|
||||
lint_version="${2:-latest}"
|
||||
docker run --rm \
|
||||
--volume "${ROOT/..}":/pinniped \
|
||||
--volume "$(go env GOCACHE):/gocache" \
|
||||
--volume "$(go env GOMODCACHE):/gomodcache" \
|
||||
--env GOCACHE=/gocache \
|
||||
--env GOMODCACHE=/gomodcache \
|
||||
--workdir /pinniped \
|
||||
golangci/golangci-lint:$lint_version \
|
||||
./hack/module.sh lint
|
||||
;;
|
||||
'unittest' | 'unittests' | 'units' | 'unit')
|
||||
with_modules 'unittest_cmd'
|
||||
KUBE_CACHE_MUTATION_DETECTOR=${kube_cache_mutation_detector} \
|
||||
KUBE_PANIC_WATCH_DECODE_ERROR=${kube_panic_watch_decode_error} \
|
||||
go test -short -race ./...
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
@@ -77,6 +57,8 @@ function main() {
|
||||
|
||||
echo "=> "
|
||||
echo " \"module.sh $1\" Finished successfully."
|
||||
|
||||
popd > /dev/null
|
||||
}
|
||||
|
||||
main "$@"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Copyright 2021 the Pinniped contributors. All Rights Reserved.
|
||||
# Copyright 2021-2024 the Pinniped contributors. All Rights Reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
#
|
||||
@@ -32,6 +32,9 @@ EOF
|
||||
|
||||
# Use the CLI to get a kubeconfig that will use this WebhookAuthenticator.
|
||||
go build -o /tmp/pinniped ./cmd/pinniped
|
||||
/tmp/pinniped get kubeconfig --static-token "$PINNIPED_TEST_USER_TOKEN" >/tmp/kubeconfig-with-webhook-auth.yaml
|
||||
/tmp/pinniped get kubeconfig \
|
||||
--concierge-authenticator-type webhook \
|
||||
--concierge-authenticator-name my-webhook \
|
||||
--static-token "$PINNIPED_TEST_USER_TOKEN" >/tmp/kubeconfig-with-webhook-auth.yaml
|
||||
|
||||
echo "export KUBECONFIG=/tmp/kubeconfig-with-webhook-auth.yaml"
|
||||
|
||||
Reference in New Issue
Block a user