Skip to content

Commit 232269a

Browse files
committed
Use Go modules when generating code
We used to use `dep` to download "k8s.io/code-generator" and call it within the vendor directory. Go does not provide a way to do that with a single module, so follow the lead of "sigs.k8s.io/kubebuilder" and install the binary using another, temporary module when it's not already on the PATH. Issue: [ch9453] See: c8f13d3
1 parent ca9815c commit 232269a

File tree

5 files changed

+48
-83
lines changed

5 files changed

+48
-83
lines changed

Makefile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,7 @@ release: linuxpgo macpgo winpgo
245245
cp $(PGOROOT)/examples/pgo-bash-completion $(RELTMPDIR)
246246
tar czvf $(RELFILE) -C $(RELTMPDIR) .
247247

248-
update-codegen:
249-
$(PGOROOT)/hack/update-codegen.sh
248+
generate: generate-client
250249

251-
verify-codegen:
252-
$(PGOROOT)/hack/verify-codegen.sh
250+
generate-client:
251+
./hack/generate-clientset.sh

docs/content/contributing/developer-setup.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,12 @@ Code generation is leveraged to generate the clients and informers utilized to i
6262
various [Custom Resources](https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/)
6363
(e.g. `pgclusters`) comprising the PostgreSQL Operator declarative API. Code generation is provided
6464
by the [Kubernetes code-generator project](https://github.com/kubernetes/code-generator),
65-
and the following two `Make` targets are included within the PostgreSQL Operator project to both
66-
determine if any generated code within the project requires an update, and then update that code
65+
and the following Make target is included within the PostgreSQL Operator project to update that code
6766
as needed:
6867

6968
```bash
70-
# Check to see if an update to generated code is needed:
71-
make verify-codegen
72-
7369
# Update any generated code:
74-
make update-codegen
70+
make generate
7571
```
7672

7773
Therefore, in the event that a Custom Resource defined within the PostgreSQL Operator API

hack/generate-clientset.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2020 Crunchy Data Solutions, Inc.
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
set -eu
17+
18+
# Find the Go install path.
19+
[ "${GOBIN:-}" ] || GOBIN="$(go env GOBIN)"
20+
[ "${GOBIN:-}" ] || GOBIN="$(go env GOPATH)/bin"
21+
22+
# Create and cleanup a temporary directory.
23+
DIR="$(mktemp -d)"
24+
trap "rm -rf '$DIR'" EXIT
25+
26+
# Find `client-gen` on the current PATH or install it to the Go install path.
27+
tool="$(command -v client-gen || true)"
28+
[ -n "$tool" ] || tool="$GOBIN/client-gen"
29+
[ -x "$tool" ] || ( cd "$DIR" && go mod init tmp && go get 'k8s.io/code-generator/cmd/client-gen@v0.17.9' )
30+
31+
# Generate ./pkg/generated/clientset/versioned from objects defined in ./pkg/apis/crunchydata.com/...
32+
33+
target_directory='pkg/generated/clientset'
34+
target_package="$(go list -m)/${target_directory}"
35+
36+
"$tool" \
37+
--clientset-name='versioned' \
38+
--go-header-file='hack/boilerplate.go.txt' \
39+
--input-base='' --input="$(go list ./pkg/apis/crunchydata.com/... | paste -sd, -)" \
40+
--output-base="$DIR" --output-package="$target_package" \
41+
42+
[ ! -d "$target_directory" ] || rm -r "$target_directory"
43+
mv "${DIR}/${target_package}" "${target_directory}"

hack/update-codegen.sh

Lines changed: 0 additions & 26 deletions
This file was deleted.

hack/verify-codegen.sh

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)