2024-03-08 18:44:42 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# Copyright 2024 The Kubernetes Authors.
|
|
|
|
#
|
|
|
|
# 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
|
|
|
|
|
2024-04-09 14:26:16 +00:00
|
|
|
TMP_VENDOR_DIR=gen-vendor
|
|
|
|
|
|
|
|
function cleanup() {
|
|
|
|
echo "Cleaning up..."
|
|
|
|
rm -rf ${TMP_VENDOR_DIR}
|
|
|
|
# We need to clean up the go.mod file since code-generator adds temporary library to the go.mod file.
|
|
|
|
"${GO_CMD}" mod tidy
|
|
|
|
}
|
|
|
|
|
2024-04-17 12:33:01 +00:00
|
|
|
# Temporal work around until https://github.com/kubernetes/kubernetes/pull/125051 is merged
|
|
|
|
# and added to a release.
|
|
|
|
find api/generated/ -name 'nodefeature*' | xargs rm
|
|
|
|
|
2024-04-09 14:26:16 +00:00
|
|
|
trap cleanup EXIT
|
2024-03-08 18:44:42 +00:00
|
|
|
GO_CMD=${1:-go}
|
|
|
|
NFD_ROOT=$(realpath $(dirname ${BASH_SOURCE[0]})/..)
|
|
|
|
|
2024-04-09 14:26:16 +00:00
|
|
|
"${GO_CMD}" mod vendor
|
2024-03-08 18:44:42 +00:00
|
|
|
|
2024-04-09 14:26:16 +00:00
|
|
|
# Go generate
|
|
|
|
"${GO_CMD}" generate ./cmd/... ./pkg/... ./source/...
|
2024-03-08 18:44:42 +00:00
|
|
|
|
2024-04-09 14:26:16 +00:00
|
|
|
# Generate CRDs
|
|
|
|
controller-gen object crd output:crd:stdout paths=./api/... > deployment/base/nfd-crds/nfd-api-crds.yaml
|
|
|
|
mkdir -p deployment/helm/node-feature-discovery/crds
|
|
|
|
cp deployment/base/nfd-crds/nfd-api-crds.yaml deployment/helm/node-feature-discovery/crds
|
2024-03-08 18:44:42 +00:00
|
|
|
|
2024-04-09 14:26:16 +00:00
|
|
|
# Generate clientset and informers
|
|
|
|
mv vendor ${TMP_VENDOR_DIR}
|
|
|
|
CODEGEN_PKG=${CODEGEN_PKG:-$(ls -d -1 ./${TMP_VENDOR_DIR}/k8s.io/code-generator 2>/dev/null || echo ../code-generator)}
|
2024-03-08 18:44:42 +00:00
|
|
|
|
2024-04-09 14:26:16 +00:00
|
|
|
cd $(dirname ${BASH_SOURCE[0]})/..
|
2024-03-08 18:44:42 +00:00
|
|
|
|
|
|
|
source "${CODEGEN_PKG}/kube_codegen.sh"
|
|
|
|
|
|
|
|
# Generating conversion and defaults functions
|
|
|
|
kube::codegen::gen_helpers \
|
2024-04-26 09:54:01 +00:00
|
|
|
${NFD_ROOT}/api/nfd \
|
2024-03-08 18:44:42 +00:00
|
|
|
--boilerplate ${NFD_ROOT}/hack/boilerplate.go.txt
|
|
|
|
|
2024-04-09 14:26:16 +00:00
|
|
|
# HACK: manually patching the auto-generated code as code-generator cannot
|
|
|
|
# properly handle deepcopy of MatchExpressionSet.
|
|
|
|
sed s'/out = new(map\[string\]\*MatchExpression)/out = new(MatchExpressionSet)/' -i api/nfd/v1alpha1/zz_generated.deepcopy.go
|
|
|
|
|
2024-04-26 09:54:01 +00:00
|
|
|
# Switch to work in the api worktree
|
|
|
|
pushd "${NFD_ROOT}/api/nfd" > /dev/null
|
|
|
|
|
2024-03-08 18:44:42 +00:00
|
|
|
kube::codegen::gen_client \
|
2024-04-26 09:54:01 +00:00
|
|
|
--with-watch \
|
|
|
|
--output-dir "${NFD_ROOT}/api/generated" \
|
|
|
|
--output-pkg "sigs.k8s.io/node-feature-discovery/api/generated" \
|
|
|
|
--boilerplate "${NFD_ROOT}/hack/boilerplate.go.txt" \
|
|
|
|
${NFD_ROOT}/api
|
|
|
|
|
|
|
|
popd > /dev/null
|