Skip to content

Commit d7ffa1a

Browse files
committed
update codegen scripting
On-behalf-of: @SAP [email protected]
1 parent 0bda00b commit d7ffa1a

File tree

4 files changed

+63
-40
lines changed

4 files changed

+63
-40
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
Copyright The KCP Authors.
3+
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+
*/

hack/reconciling.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# https://github.com/kubermatic/reconciler
1717

1818
package: reconciling
19-
boilerplate: hack/boilerplate/boilerplate.go.txt
19+
boilerplate: hack/boilerplate/boilerplate.generatego.txt
2020
resourceTypes:
2121
# kcp-dev/v1alpha1
2222
- { package: github.com/kcp-dev/kcp/sdk/apis/apis/v1alpha1, importAlias: kcpdevv1alpha1, resourceName: APIExport }

hack/update-codegen-crds.sh

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,16 @@ set -euo pipefail
1919
cd $(dirname $0)/..
2020
source hack/lib.sh
2121

22-
sed="sed"
23-
[ "$(command -v gsed)" ] && sed="gsed"
22+
mkdir -p _tools
23+
export GOBIN=$(realpath _tools)
24+
25+
go install k8c.io/reconciler/cmd/reconciler-gen
26+
go install sigs.k8s.io/controller-tools/cmd/controller-gen
2427

2528
echodate "Generating reconciling helpers…"
2629

2730
reconcileHelpers=internal/resources/reconciling/zz_generated_reconcile.go
28-
go run k8c.io/reconciler/cmd/reconciler-gen --config hack/reconciling.yaml > $reconcileHelpers
29-
30-
currentYear=$(date +%Y)
31-
$sed -i "s/Copyright YEAR/Copyright $currentYear/g" $reconcileHelpers
32-
$sed -i "s/Copyright © YEAR/Copyright © $currentYear/g" $reconcileHelpers
31+
$GOBIN/reconciler-gen --config hack/reconciling.yaml > $reconcileHelpers
3332

3433
CRD_DIR=deploy/crd
3534
KCP_CRD_DIR="$CRD_DIR/kcp.io"
@@ -38,17 +37,14 @@ mkdir -p "$KCP_CRD_DIR"
3837

3938
echodate "Generating openAPI v3 CRDs…"
4039

41-
# this also generates the deepcopy funcs
42-
go run sigs.k8s.io/controller-tools/cmd/controller-gen \
40+
$GOBIN/controller-gen \
4341
crd \
44-
object:headerFile=./hack/boilerplate/boilerplate.go.txt \
4542
paths=./sdk/apis/... \
4643
output:crd:dir=./$KCP_CRD_DIR
4744

4845
# these are types only used for testing the syncer
49-
go run sigs.k8s.io/controller-tools/cmd/controller-gen \
46+
$GOBIN/controller-gen \
5047
crd \
51-
object:headerFile=./hack/boilerplate/boilerplate.go.txt \
5248
paths=./internal/sync/apis/... \
5349
output:crd:dir=./internal/sync/crd/
5450

hack/update-codegen-sdk.sh

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,43 +19,55 @@ set -euo pipefail
1919
cd $(dirname $0)/..
2020
source hack/lib.sh
2121

22-
BOILERPLATE_HEADER="$(realpath hack/boilerplate/boilerplate.go.txt)"
22+
BOILERPLATE_HEADER="$(realpath hack/boilerplate/boilerplate.generatego.txt)"
23+
SDK_MODULE="github.com/kcp-dev/api-syncagent/sdk"
24+
APIS_PKG="$SDK_MODULE/apis"
2325

24-
BASE=github.com/kcp-dev/api-syncagent
25-
MODULE="$BASE/sdk"
26-
SDK_DIR=sdk
27-
SDK_PKG="$MODULE"
28-
APIS_PKG="$MODULE/apis"
26+
mkdir -p _tools
27+
export GOBIN=$(realpath _tools)
2928

3029
set -x
31-
rm -rf -- $SDK_DIR/{applyconfiguration,clientset,informers,listers}
3230

33-
go run k8s.io/code-generator/cmd/applyconfiguration-gen \
31+
go install k8s.io/code-generator/cmd/applyconfiguration-gen
32+
go install k8s.io/code-generator/cmd/client-gen
33+
go install github.com/kcp-dev/code-generator/v2
34+
go install github.com/openshift-eng/openshift-goimports
35+
go install sigs.k8s.io/controller-tools/cmd/controller-gen
36+
37+
# these are types only used for testing the syncer
38+
$GOBIN/controller-gen \
39+
"object:headerFile=$BOILERPLATE_HEADER" \
40+
paths=./internal/sync/apis/...
41+
42+
cd sdk
43+
rm -rf -- applyconfiguration clientset informers listers
44+
45+
$GOBIN/controller-gen \
46+
"object:headerFile=$BOILERPLATE_HEADER" \
47+
paths=./apis/...
48+
49+
$GOBIN/applyconfiguration-gen \
3450
--go-header-file "$BOILERPLATE_HEADER" \
35-
--output-dir $SDK_DIR/applyconfiguration \
36-
--output-pkg $SDK_PKG/applyconfiguration \
37-
$APIS_PKG/syncagent/v1alpha1
51+
--output-dir applyconfiguration \
52+
--output-pkg $SDK_MODULE/applyconfiguration \
53+
./apis/...
3854

39-
go run k8s.io/code-generator/cmd/client-gen \
40-
--input-base "" \
41-
--input $APIS_PKG/syncagent/v1alpha1 \
42-
--clientset-name versioned \
55+
$GOBIN/client-gen \
4356
--go-header-file "$BOILERPLATE_HEADER" \
44-
--output-dir $SDK_DIR/clientset \
45-
--output-pkg $SDK_PKG/clientset
57+
--output-dir clientset \
58+
--output-pkg $SDK_MODULE/clientset \
59+
--clientset-name versioned \
60+
--input-base $APIS_PKG \
61+
--input syncagent/v1alpha1
4662

47-
go run github.com/kcp-dev/code-generator/v2 \
48-
"client:headerFile=$BOILERPLATE_HEADER,apiPackagePath=$APIS_PKG,outputPackagePath=$SDK_PKG,singleClusterClientPackagePath=$SDK_PKG/clientset/versioned,singleClusterApplyConfigurationsPackagePath=$SDK_PKG/applyconfiguration" \
49-
"informer:headerFile=$BOILERPLATE_HEADER,apiPackagePath=$APIS_PKG,outputPackagePath=$SDK_PKG,singleClusterClientPackagePath=$SDK_PKG/clientset/versioned" \
63+
$GOBIN/code-generator \
64+
"client:headerFile=$BOILERPLATE_HEADER,apiPackagePath=$APIS_PKG,outputPackagePath=$SDK_MODULE,singleClusterClientPackagePath=$SDK_MODULE/clientset/versioned,singleClusterApplyConfigurationsPackagePath=applyconfiguration" \
65+
"informer:headerFile=$BOILERPLATE_HEADER,apiPackagePath=$APIS_PKG,outputPackagePath=$SDK_MODULE,singleClusterClientPackagePath=$SDK_MODULE/clientset/versioned" \
5066
"lister:headerFile=$BOILERPLATE_HEADER,apiPackagePath=$APIS_PKG" \
51-
"paths=./sdk/apis/..." \
52-
"output:dir=$SDK_DIR"
67+
"paths=./apis/..." \
68+
"output:dir=."
5369

5470
# Use openshift's import fixer because gimps fails to parse some of the files;
5571
# its output is identical to how gimps would sort the imports, but it also fixes
5672
# the misplaced go:build directives.
57-
for submodule in "applyconfiguration" "clientset" "informers" "listers"; do
58-
go run github.com/openshift-eng/openshift-goimports \
59-
--module "$MODULE/$submodule" \
60-
--path "$SDK_DIR/$submodule"
61-
done
73+
$GOBIN/openshift-goimports .

0 commit comments

Comments
 (0)