Files
velero/hack/update-3generated-crd-code.sh
T
cc7b1dbaef Embed CRD manifests via go:embed instead of codegen (#10329)
config/crd/{v1,v2alpha1}/crds/crds.go were generated files that
gzip-compressed the CRD YAML bases into committed []byte literals via
hack/crd-gen, requiring `go generate` and a dedicated CI drift check
(hack/verify-generated-crd-code.sh). This made the files large,
unreviewable in diffs, and a frequent source of merge conflicts.

Replace the generated files with config/crd/{v1,v2alpha1}/crds.go
using `//go:embed bases/*.yaml` to embed the already-committed YAML
manifests directly, decoding them the same way at init. Since Go's
go:embed can't reach outside a file's own directory tree, the crds
package now lives alongside bases/ instead of in a bases-sibling
subdirectory; import paths in pkg/install and pkg/controller were
updated accordingly.

Drop hack/crd-gen and hack/verify-generated-crd-code.sh entirely, and
trim their references from update-3generated-crd-code.sh and the
codespell skip-list. No codegen step remains, so no drift is possible.

Fixes #10328

AI-Tool-Used: Claude Code
AI-Tool-Use-Level: Category 1 (High)
AI-Code-Category: Category 1 (Production)

Signed-off-by: lubronzhan <lubron.zhan@broadcom.com>
Co-authored-by: Daniel Jiang <daniel.jiang@broadcom.com>
2026-08-24 14:17:25 -04:00

61 lines
1.7 KiB
Bash
Executable File

#!/bin/bash
#
# Copyright the Velero contributors.
#
# 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
set -o xtrace
# this script expects to be run from the root of the Velero repo.
if [[ -z "${GOPATH}" ]]; then
GOPATH=~/go
fi
if ! command -v controller-gen > /dev/null; then
echo "controller-gen is missing"
exit 1
fi
# Generate CRD for v1.
controller-gen \
crd:crdVersions=v1 \
paths=./pkg/apis/velero/v1/... \
paths=./pkg/controller/... \
output:crd:artifacts:config=config/crd/v1/bases \
object \
paths=./pkg/apis/velero/v1/...
# Generate CRD for v2alpha1.
controller-gen \
crd:crdVersions=v1 \
paths=./pkg/apis/velero/v2alpha1/... \
paths=./pkg/controller/... \
output:crd:artifacts:config=config/crd/v2alpha1/bases \
object \
paths=./pkg/apis/velero/v2alpha1/...
# Generate RBAC.
controller-gen \
paths=./pkg/apis/velero/v1/... \
paths=./pkg/apis/velero/v2alpha1/... \
paths=./pkg/controller/... \
rbac:roleName=velero-perms
# The CRD manifests above are embedded directly into the binary via
# go:embed (see config/crd/v1/crds.go and config/crd/v2alpha1/crds.go),
# so no further code generation step is required.