copy shell script changes from PR #1040 to release-0.12

This commit is contained in:
Ryan Richard 2022-03-01 13:30:47 -08:00
parent 4d6a2af894
commit fa89150c95
2 changed files with 40 additions and 18 deletions

View File

@ -1,6 +1,6 @@
#!/usr/bin/env bash
# Copyright 2020-2021 the Pinniped contributors. All Rights Reserved.
# Copyright 2020-2022 the Pinniped contributors. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
@ -8,16 +8,20 @@ KUBE_VERSIONS=("$@")
BASE_PKG="go.pinniped.dev"
export GO111MODULE="on"
# Note that you can change this value to 10 to debug the Kubernetes code generator shell scripts used below.
debug_level="${CODEGEN_LOG_LEVEL:-1}"
# If we're not running in a container, assume that we want to loop over and run each build
# in a container.
if [[ -z "${CONTAINED:-}" ]]; then
for kubeVersion in "${KUBE_VERSIONS[@]}"; do
# CODEGEN_IMAGE is the container image to use when running
CODEGEN_IMAGE="projects.registry.vmware.com/pinniped/k8s-code-generator-$(echo "$kubeVersion" | cut -d"." -f1-2):latest"
CODEGEN_IMAGE="ghcr.io/pinniped-ci-bot/k8s-code-generator-$(echo "$kubeVersion" | cut -d"." -f1-2):latest"
echo "generating code for ${kubeVersion} using ${CODEGEN_IMAGE}..."
docker run --rm \
--env CONTAINED=1 \
--env CODEGEN_LOG_LEVEL="$debug_level" \
--volume "${ROOT}:/work" \
--workdir "/work" \
"${CODEGEN_IMAGE}" \
@ -83,6 +87,10 @@ require (
)
EOF
# Generate a go.sum without changing the go.mod by running go mod download.
echo "running go mod download in ${OUTPUT_DIR}/apis/go.mod to generate a go.sum file..."
(cd "${OUTPUT_DIR}/apis" && go mod download all 2>&1 | sed "s|^|go-mod-download > |")
# Make the generated client code its own Go module.
echo "generating ${OUTPUT_DIR}/client/go.mod..."
mkdir client
@ -98,33 +106,37 @@ require (
k8s.io/api ${KUBE_MODULE_VERSION}
k8s.io/apimachinery ${KUBE_MODULE_VERSION}
k8s.io/client-go ${KUBE_MODULE_VERSION}
k8s.io/apimachinery ${KUBE_MODULE_VERSION}
${BASE_PKG}/generated/${KUBE_MINOR_VERSION}/apis v0.0.0
)
replace ${BASE_PKG}/generated/${KUBE_MINOR_VERSION}/apis => ../apis
EOF
# Generate a go.sum without changing the go.mod by running go mod download.
echo "running go mod download in ${OUTPUT_DIR}/client/go.mod to generate a go.sum file..."
(cd "${OUTPUT_DIR}/client" && go mod download all 2>&1 | sed "s|^|go-mod-download > |")
# Generate API-related code for our public API groups
echo "generating API-related code for our public API groups..."
(cd apis &&
bash "${GOPATH}/src/k8s.io/code-generator/generate-groups.sh" \
deepcopy \
"deepcopy" \
"${BASE_PKG}/generated/${KUBE_MINOR_VERSION}/apis" \
"${BASE_PKG}/generated/${KUBE_MINOR_VERSION}/apis" \
"supervisor/config:v1alpha1 supervisor/idp:v1alpha1 concierge/config:v1alpha1 concierge/authentication:v1alpha1 concierge/login:v1alpha1 concierge/identity:v1alpha1" \
--go-header-file "${ROOT}/hack/boilerplate.go.txt" 2>&1 | sed "s|^|gen-api > |"
--go-header-file "${ROOT}/hack/boilerplate.go.txt" -v "$debug_level" 2>&1 | sed "s|^|gen-api > |"
)
# Generate API-related code for our internal API groups
echo "generating API-related code for our internal API groups..."
(cd apis &&
bash "${GOPATH}/src/k8s.io/code-generator/generate-internal-groups.sh" \
deepcopy,defaulter,conversion \
"deepcopy,defaulter,conversion" \
"${BASE_PKG}/generated/${KUBE_MINOR_VERSION}/client/concierge" \
"${BASE_PKG}/generated/${KUBE_MINOR_VERSION}/apis" \
"${BASE_PKG}/generated/${KUBE_MINOR_VERSION}/apis" \
"concierge/login:v1alpha1 concierge/identity:v1alpha1" \
--go-header-file "${ROOT}/hack/boilerplate.go.txt" 2>&1 | sed "s|^|gen-int-api > |"
--go-header-file "${ROOT}/hack/boilerplate.go.txt" -v "$debug_level" 2>&1 | sed "s|^|gen-int-api > |"
)
@ -136,19 +148,19 @@ echo "tidying ${OUTPUT_DIR}/apis/go.mod..."
echo "generating client code for our public API groups..."
(cd client &&
bash "${GOPATH}/src/k8s.io/code-generator/generate-groups.sh" \
client,lister,informer \
"client,lister,informer" \
"${BASE_PKG}/generated/${KUBE_MINOR_VERSION}/client/concierge" \
"${BASE_PKG}/generated/${KUBE_MINOR_VERSION}/apis" \
"concierge/config:v1alpha1 concierge/authentication:v1alpha1 concierge/login:v1alpha1 concierge/identity:v1alpha1" \
--go-header-file "${ROOT}/hack/boilerplate.go.txt" 2>&1 | sed "s|^|gen-client > |"
--go-header-file "${ROOT}/hack/boilerplate.go.txt" -v "$debug_level" 2>&1 | sed "s|^|gen-client > |"
)
(cd client &&
(cd client &&
bash "${GOPATH}/src/k8s.io/code-generator/generate-groups.sh" \
client,lister,informer \
"client,lister,informer" \
"${BASE_PKG}/generated/${KUBE_MINOR_VERSION}/client/supervisor" \
"${BASE_PKG}/generated/${KUBE_MINOR_VERSION}/apis" \
"supervisor/config:v1alpha1 supervisor/idp:v1alpha1" \
--go-header-file "${ROOT}/hack/boilerplate.go.txt" 2>&1 | sed "s|^|gen-client > |"
--go-header-file "${ROOT}/hack/boilerplate.go.txt" -v "$debug_level" 2>&1 | sed "s|^|gen-client > |"
)
# Tidy up the .../client module

View File

@ -1,6 +1,6 @@
#!/usr/bin/env bash
# Copyright 2020-2021 the Pinniped contributors. All Rights Reserved.
# Copyright 2020-2022 the Pinniped contributors. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
set -euo pipefail
@ -11,17 +11,27 @@ ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"
xargs -n 1 -P 8 "$ROOT/hack/lib/update-codegen.sh" < "${ROOT}/hack/lib/kube-versions.txt"
# Copy the latest version into a ./generated/latest directory so we can depend on it without nested modules.
LATEST_VERSION="$(head -1 < "${ROOT}/hack/lib/kube-versions.txt" | cut -d"." -f1-2)"
LATEST_MINOR_VERSION="$(head -1 < "${ROOT}/hack/lib/kube-versions.txt" | cut -d"." -f1-2)"
LATEST_ROOT="$ROOT/generated/latest"
rm -rf "$LATEST_ROOT"
cp -r "$ROOT/generated/$LATEST_VERSION/" "$LATEST_ROOT"
cp -r "$ROOT/generated/$LATEST_MINOR_VERSION/" "$LATEST_ROOT"
find "$LATEST_ROOT" \( -name "go.mod" -or -name "go.sum" -or -name "README.adoc" \) -delete
rm -r "$LATEST_ROOT/crds"
find "$LATEST_ROOT" -type f -print0 | xargs -0 sed -i '' -e "s|go.pinniped.dev/generated/$LATEST_VERSION|go.pinniped.dev/generated/latest|g"
if [[ "$(uname -s)" == "Linux" ]]; then
# docker on linux preserves the root ownership of the output files of update-codegen.sh,
# so chown the files before editing them.
sudo chown -R "$(id --user)" generated
sudo chgrp -R "$(id --group)" generated
# sed on Linux uses -i'' (no space in between).
find "$LATEST_ROOT" -type f -print0 | xargs -0 sed -i'' -e "s|go.pinniped.dev/generated/$LATEST_MINOR_VERSION|go.pinniped.dev/generated/latest|g"
else
# sed on MacOS uses -i '' (with space in between).
find "$LATEST_ROOT" -type f -print0 | xargs -0 sed -i '' -e "s|go.pinniped.dev/generated/$LATEST_MINOR_VERSION|go.pinniped.dev/generated/latest|g"
fi
# Copy each CRD yaml to the app which should cause it to be installed.
cp "$ROOT"/generated/1.20/crds/*.supervisor.*.yaml "$ROOT/deploy/supervisor"
cp "$ROOT"/generated/1.20/crds/*.concierge.*.yaml "$ROOT/deploy/concierge"
cp "$ROOT"/generated/"$LATEST_MINOR_VERSION"/crds/*.supervisor.*.yaml "$ROOT/deploy/supervisor"
cp "$ROOT"/generated/"$LATEST_MINOR_VERSION"/crds/*.concierge.*.yaml "$ROOT/deploy/concierge"
# Tidy.
"$ROOT/hack/module.sh" tidy