Skip to content

Commit b2ba043

Browse files
authored
Merge pull request #1605 from ArangoGutierrez/codegen
Update generate scripts to use latest code_gen functions
2 parents fa3fc47 + dd24e8b commit b2ba043

File tree

8 files changed

+99
-42
lines changed

8 files changed

+99
-42
lines changed

Dockerfile_generator

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,7 @@ RUN curl -LO https://github.com/protocolbuffers/protobuf/releases/download/v25.3
2121

2222
# Expect to be working with nfd
2323
WORKDIR /go/node-feature-discovery
24+
25+
# We need to set the /go/node-feature-discovery directory as a safe directory.
26+
# This allows git commands to run in the container on MacOS systems.
27+
RUN git config --file=/.gitconfig --add safe.directory /go/node-feature-discovery

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ generate: .generator.image.stamp
160160
-v "`go env GOMODCACHE`:/go/pkg/mod" \
161161
--user=`id -u`:`id -g`\
162162
nfd-generator \
163-
./hack/generate.sh
163+
./hack/update_codegen.sh
164164

165165
gofmt:
166166
@$(GO_FMT) -w -l $$(find . -name '*.go')

go.mod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@ require (
2929
k8s.io/apiextensions-apiserver v0.29.0
3030
k8s.io/apimachinery v0.29.0
3131
k8s.io/client-go v0.29.0
32+
k8s.io/code-generator v0.29.0
3233
k8s.io/klog/v2 v2.110.1
3334
k8s.io/kubectl v0.29.0
3435
k8s.io/kubelet v0.29.0
3536
k8s.io/kubernetes v1.29.0
3637
k8s.io/pod-security-admission v0.29.0
3738
k8s.io/utils v0.0.0-20230726121419-3b25d923346b
39+
sigs.k8s.io/structured-merge-diff/v4 v4.4.1
3840
sigs.k8s.io/yaml v1.3.0
3941
)
4042

@@ -190,14 +192,14 @@ require (
190192
k8s.io/cri-api v0.29.0 // indirect
191193
k8s.io/csi-translation-lib v0.29.0 // indirect
192194
k8s.io/dynamic-resource-allocation v0.29.0 // indirect
195+
k8s.io/gengo v0.0.0-20230829151522-9cce18d56c01 // indirect
193196
k8s.io/kms v0.29.0 // indirect
194197
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
195198
k8s.io/kube-scheduler v0.0.0 // indirect
196199
k8s.io/legacy-cloud-providers v0.0.0 // indirect
197200
k8s.io/mount-utils v0.25.0 // indirect
198201
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.28.0 // indirect
199202
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
200-
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
201203
)
202204

203205
// The k8s "sub-"packages do not have 'semver' compatible versions. Thus, we

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2174,6 +2174,7 @@ k8s.io/cloud-provider v0.29.0 h1:Qgk/jHsSKGRk/ltTlN6e7eaNuuamLROOzVBd0RPp94M=
21742174
k8s.io/cloud-provider v0.29.0/go.mod h1:gBCt7YYKFV4oUcJ/0xF9lS/9il4MxKunJ+ZKvh39WGo=
21752175
k8s.io/cluster-bootstrap v0.29.0 h1:zCYdZ+LWDj4O86FB5tDKckIEsf2qBHjcp78xtjOzD3A=
21762176
k8s.io/cluster-bootstrap v0.29.0/go.mod h1:PDk+ouXC6bM2FFdo4u53IlWK3ZMWebH4TeE5BGmHWRw=
2177+
k8s.io/code-generator v0.29.0 h1:2LQfayGDhaIlaamXjIjEQlCMy4JNCH9lrzas4DNW1GQ=
21772178
k8s.io/code-generator v0.29.0/go.mod h1:5bqIZoCxs2zTRKMWNYqyQWW/bajc+ah4rh0tMY8zdGA=
21782179
k8s.io/component-base v0.29.0 h1:T7rjd5wvLnPBV1vC4zWd/iWRbV8Mdxs+nGaoaFzGw3s=
21792180
k8s.io/component-base v0.29.0/go.mod h1:sADonFTQ9Zc9yFLghpDpmNXEdHyQmFIGbiuZbqAXQ1M=
@@ -2187,6 +2188,7 @@ k8s.io/csi-translation-lib v0.29.0 h1:we4X1yUlDikvm5Rv0dwMuPHNw6KwjwsQiAuOPWXha8
21872188
k8s.io/csi-translation-lib v0.29.0/go.mod h1:Cp6t3CNBSm1dXS17V8IImUjkqfIB6KCj8Fs8wf6uyTA=
21882189
k8s.io/dynamic-resource-allocation v0.29.0 h1:JQW5erdoOsvhst7DxMfEpnXhrfm9SmNTnvyaXdqTLAE=
21892190
k8s.io/dynamic-resource-allocation v0.29.0/go.mod h1:4T9Fg4J8B2SdRVVj5/1hM7hGAUrBqzyEUIGFY+wQl4Q=
2191+
k8s.io/gengo v0.0.0-20230829151522-9cce18d56c01 h1:pWEwq4Asjm4vjW7vcsmijwBhOr1/shsbSYiWXmNGlks=
21902192
k8s.io/gengo v0.0.0-20230829151522-9cce18d56c01/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E=
21912193
k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE=
21922194
k8s.io/klog/v2 v2.2.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y=

hack/generate.sh

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

hack/tools.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
Copyright 2024 The Kubernetes 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+
*/
16+
17+
// This package imports things required by build scripts, to force `go mod` to see them as dependencies
18+
package tools
19+
20+
import _ "k8s.io/code-generator"

hack/update_codegen.sh

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2024 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -o errexit
18+
set -o nounset
19+
set -o pipefail
20+
21+
GO_CMD=${1:-go}
22+
NFD_ROOT=$(realpath $(dirname ${BASH_SOURCE[0]})/..)
23+
24+
go mod vendor
25+
26+
CODEGEN_PKG=${CODEGEN_PKG:-$(cd "${NFD_ROOT}"; ls -d -1 ./vendor/k8s.io/code-generator 2>/dev/null || echo ../code-generator)}
27+
28+
cd $(dirname ${BASH_SOURCE[0]})/..
29+
30+
source "${CODEGEN_PKG}/kube_codegen.sh"
31+
32+
# TODO: remove the workaround when the issue is solved in the code-generator
33+
# (https://github.com/kubernetes/code-generator/issues/165).
34+
# Here, we create the soft link named "sigs.k8s.io" to the parent directory of
35+
# node-feature-discovery to ensure the layout required by the kube_codegen.sh script.
36+
ln -s .. sigs.k8s.io
37+
trap "rm sigs.k8s.io" EXIT
38+
39+
CODEGEN_PKG=${CODEGEN_PKG:-$(ls -d -1 ./vendor/k8s.io/code-generator 2>/dev/null || echo ../code-generator)}
40+
41+
source "${CODEGEN_PKG}/kube_codegen.sh"
42+
43+
go generate ./cmd/... ./pkg/... ./source/...
44+
45+
controller-gen object crd output:crd:stdout paths=./pkg/apis/... > deployment/base/nfd-crds/nfd-api-crds.yaml
46+
47+
mkdir -p deployment/helm/node-feature-discovery/crds
48+
cp deployment/base/nfd-crds/nfd-api-crds.yaml deployment/helm/node-feature-discovery/crds
49+
50+
# Generating conversion and defaults functions
51+
kube::codegen::gen_helpers \
52+
--input-pkg-root sigs.k8s.io/node-feature-discovery/apis \
53+
--output-base "${NFD_ROOT}" \
54+
--boilerplate ${NFD_ROOT}/hack/boilerplate.go.txt
55+
56+
kube::codegen::gen_client \
57+
--input-pkg-root sigs.k8s.io/node-feature-discovery/pkg/apis \
58+
--output-pkg-root sigs.k8s.io/node-feature-discovery/pkg/generated \
59+
--output-base "${NFD_ROOT}" \
60+
--boilerplate ${NFD_ROOT}/hack/boilerplate.go.txt \
61+
--with-watch
62+
63+
# HACK: manually patching the auto-generated code as code-generator cannot
64+
# properly handle deepcopy of MatchExpressionSet.
65+
sed s'/out = new(map\[string\]\*MatchExpression)/out = new(MatchExpressionSet)/' -i pkg/apis/nfd/v1alpha1/zz_generated.deepcopy.go
66+
67+
# We need to clean up the go.mod file since code-generator adds temporary library to the go.mod file.
68+
"${GO_CMD}" mod tidy

pkg/apis/nfd/v1alpha1/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ type NodeFeatureList struct {
3434
// NodeFeature resource holds the features discovered for one node in the
3535
// cluster.
3636
// +kubebuilder:object:root=true
37-
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
3837
// +genclient
38+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
3939
type NodeFeature struct {
4040
metav1.TypeMeta `json:",inline"`
4141
metav1.ObjectMeta `json:"metadata,omitempty"`

0 commit comments

Comments
 (0)