From 47773bca3eda7896c8e46f60db113588933975f7 Mon Sep 17 00:00:00 2001 From: Matt Cui Date: Mon, 1 Mar 2021 16:03:48 +0800 Subject: [PATCH] Add make target for generating crds through controller-gen --- DEVELOPMENT.md | 4 ++++ Makefile | 8 ++++++++ hack/install-controller-gen.sh | 24 ++++++++++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100755 hack/install-controller-gen.sh diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 2286bf4b68..93c9c8f515 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -145,6 +145,10 @@ As you make changes to the code, you can redeploy your controller with: ```sh ko apply -P -R -f deploy/ ``` +You may use the following command to re-generate CRDs of build and buildrun if you change their spec: + ```sh + make generate-crds + ``` ### Tear it down diff --git a/Makefile b/Makefile index 65c9e3e747..67d9d26c8c 100644 --- a/Makefile +++ b/Makefile @@ -71,6 +71,10 @@ IMAGE_HOST ?= quay.io IMAGE ?= shipwright/shipwright-operator TAG ?= latest +# options for generating crds with controller-gen +CONTROLLER_GEN="${GOBIN}/controller-gen" +CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false" + .EXPORT_ALL_VARIABLES: default: build @@ -279,3 +283,7 @@ kind-tekton: kind: ./hack/install-kind.sh ./hack/install-registry.sh + +generate-crds: + ./hack/install-controller-gen.sh + "$(CONTROLLER_GEN)" "$(CRD_OPTIONS)" rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=deploy/crds diff --git a/hack/install-controller-gen.sh b/hack/install-controller-gen.sh new file mode 100755 index 0000000000..e4ae645b93 --- /dev/null +++ b/hack/install-controller-gen.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +# Copyright The Shipwright Contributors +# +# SPDX-License-Identifier: Apache-2.0 + +# +# Installs controller-gen utility via "go get". +# + +set -eu + +# controller-gen version +CONTROLLER_GEN_VERSION="${CONTROLLER_GEN_VERSION:-v0.4.1}" + +if [ ! -f "${GOPATH}/bin/controller-gen" ] ; then + echo "# Installing controller-gen..." + pushd "$(mktemp -d)" >/dev/null 2>&1 + GO111MODULE=on go get sigs.k8s.io/controller-tools/cmd/controller-gen@"${CONTROLLER_GEN_VERSION}" + popd >/dev/null 2>&1 +fi + +# print controller-gen version +controller-gen --version