Add scripts for generating CRDs using controller-tools
Signed-off-by: James Munnelly <james@munnelly.eu>
This commit is contained in:
parent
a3f02cbdfa
commit
77869cf936
@ -309,6 +309,13 @@ npm_install(
|
||||
package_lock_json = "//docs/generated/reference/generate/bin:package-lock.json",
|
||||
)
|
||||
|
||||
# Load the controller-tools repository in order to build the crd generator tool
|
||||
go_repository(
|
||||
name = "io_kubernetes_sigs_controller-tools",
|
||||
commit = "94656be085bdbd48c49be0a41c91e4fc5ea5b1ee",
|
||||
importpath = "sigs.k8s.io/controller-tools",
|
||||
)
|
||||
|
||||
# Load kubernetes-incubator/reference-docs, to be used as part of the docs
|
||||
# generation pipeline.
|
||||
# This involves quite a few dependencies, hence the long list of go_repository
|
||||
|
||||
@ -150,6 +150,30 @@ sh_test(
|
||||
],
|
||||
)
|
||||
|
||||
sh_binary(
|
||||
name = "update-crds",
|
||||
srcs = ["update-crds.sh"],
|
||||
data = [
|
||||
":update-deploy-gen",
|
||||
"//hack/bin:gencrd",
|
||||
"//pkg/apis:all-srcs",
|
||||
"//vendor/k8s.io/api/core/v1:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:all-srcs",
|
||||
"//vendor/k8s.io/apimachinery/pkg/runtime:all-srcs",
|
||||
],
|
||||
)
|
||||
|
||||
sh_test(
|
||||
name = "verify-crds",
|
||||
srcs = ["verify-crds.sh"],
|
||||
data = [
|
||||
":update-crds",
|
||||
"//deploy:all-srcs",
|
||||
"//hack/bin:gencrd",
|
||||
"//pkg/apis:all-srcs",
|
||||
],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
|
||||
@ -63,6 +63,14 @@ genrule(
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
genrule(
|
||||
name = "fetch_gencrd",
|
||||
srcs = ["@io_kubernetes_sigs_controller-tools//cmd/crd"],
|
||||
outs = ["gencrd"],
|
||||
cmd = "cp $(SRCS) $@",
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "k8",
|
||||
values = {"host_cpu": "k8"},
|
||||
|
||||
42
hack/update-crds.sh
Executable file
42
hack/update-crds.sh
Executable file
@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Copyright 2019 The Jetstack cert-manager contributors.
|
||||
#
|
||||
# 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.
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
# This script should be run via `bazel run //hack:update-crds`
|
||||
REPO_ROOT=${BUILD_WORKSPACE_DIRECTORY:-"$(cd "$(dirname "$0")" && pwd -P)"/..}
|
||||
runfiles="$(pwd)"
|
||||
export PATH="${runfiles}/hack/bin:${PATH}"
|
||||
cd "${REPO_ROOT}"
|
||||
|
||||
output="$(mktemp -d)"
|
||||
gencrd generate \
|
||||
--domain "k8s.io" \
|
||||
--output-dir "${output}"
|
||||
|
||||
echo "Copying files to output file"
|
||||
out="deploy/manifests/00-crds.yaml"
|
||||
rm "$out" > /dev/null 2>&1 || true
|
||||
mkdir -p "$(dirname $out)"
|
||||
touch "$out"
|
||||
for file in ${output}/*; do
|
||||
cat "$file" >> "$out"
|
||||
echo "---" >> "$out"
|
||||
done
|
||||
|
||||
hack/update-deploy-gen.sh
|
||||
55
hack/verify-crds.sh
Executable file
55
hack/verify-crds.sh
Executable file
@ -0,0 +1,55 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Copyright 2019 The Jetstack cert-manager contributors.
|
||||
#
|
||||
# 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.
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
RULE_NAME="crds"
|
||||
|
||||
SCRIPT_ROOT=$(dirname "${BASH_SOURCE}")/..
|
||||
|
||||
_tmp="$(mktemp -d)"
|
||||
DIFFROOT="${SCRIPT_ROOT}/"
|
||||
|
||||
cleanup() {
|
||||
rm -rf "${_tmp}"
|
||||
}
|
||||
trap "cleanup" EXIT SIGINT
|
||||
|
||||
# Create a fake GOPATH
|
||||
export GOPATH="${_tmp}"
|
||||
TMP_DIFFROOT="${GOPATH}/src/github.com/jetstack/cert-manager"
|
||||
|
||||
mkdir -p "${TMP_DIFFROOT}"
|
||||
rsync -avvL "${DIFFROOT}"/ "${TMP_DIFFROOT}" >/dev/null
|
||||
# remove __main__ directory copied to tmp
|
||||
rm -Rf "${TMP_DIFFROOT}/__main__"
|
||||
|
||||
cd "${TMP_DIFFROOT}"
|
||||
export BUILD_WORKSPACE_DIRECTORY="$(pwd)"
|
||||
"hack/update-${RULE_NAME}.sh"
|
||||
|
||||
echo "diffing ${DIFFROOT} against freshly generated codegen"
|
||||
ret=0
|
||||
diff -Naupr "${DIFFROOT}/deploy/manifests/00-crds.yaml" "${TMP_DIFFROOT}/deploy/manifests/00-crds.yaml" || ret=$?
|
||||
if [[ $ret -eq 0 ]]
|
||||
then
|
||||
echo "${DIFFROOT} up to date."
|
||||
else
|
||||
echo "${DIFFROOT} is out of date. Please run 'bazel run //hack:update-${RULE_NAME}'"
|
||||
exit 1
|
||||
fi
|
||||
Loading…
Reference in New Issue
Block a user