Skip to content

Commit 13d0bcd

Browse files
chore(tools): refactor CRD generation and add validation workflow
Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>
1 parent 49be876 commit 13d0bcd

File tree

5 files changed

+15
-7
lines changed

5 files changed

+15
-7
lines changed

.github/workflows/validate-crd.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
- name: Set up Go
3232
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0
3333
with:
34-
go-version-file: 'go.tool.mod'
34+
go-version-file: 'go.mod'
3535

3636
- name: Regenerate CRDs
3737
run: ./scripts/generate-crd.sh

charts/external-dns/crds/dnsendpoints.externaldns.k8s.io.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ spec:
8989
format: int64
9090
type: integer
9191
type: object
92+
required:
93+
- metadata
94+
- spec
95+
- status
9296
type: object
9397
served: true
9498
storage: true

config/crd/standard/dnsendpoints.externaldns.k8s.io.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ spec:
9090
format: int64
9191
type: integer
9292
type: object
93+
required:
94+
- metadata
95+
- spec
96+
- status
9397
type: object
9498
served: true
9599
storage: true

go.tool.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module sigs.k8s.io/external-dns/tools
22

3-
go 1.25.5
3+
go 1.25.0
44

55
tool (
66
github.com/google/yamlfmt/cmd/yamlfmt

scripts/generate-crd.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,19 @@ CONTROLLER_GEN="go tool -modfile=go.tool.mod controller-gen"
5555
YQ="go tool -modfile=go.tool.mod yq"
5656
YAMLFMT="go tool -modfile=go.tool.mod yamlfmt"
5757

58-
echo "Generating CRDs using controller-gen..."
58+
echo " Generating CRDs using controller-gen..."
5959

6060
# Step 1: Generate deepcopy methods for endpoint types
6161
# This creates zz_generated.deepcopy.go with DeepCopy/DeepCopyInto/DeepCopyObject methods
6262
# The 'object' generator adds these methods for types marked with +kubebuilder:object markers
63-
echo "→ Generating deepcopy for endpoint package..."
63+
echo " → Generating deepcopy for endpoint package..."
6464
${CONTROLLER_GEN} object crd:crdVersions=v1 paths="./endpoint/..."
6565

6666
# Step 2: Generate CRD manifests for API types
6767
# - Generates CRDs from Go types with kubebuilder markers
6868
# - Outputs to stdout, formats with yamlfmt, then splits into individual files
6969
# - Each CRD is saved to config/crd/standard/<crd-name>.yaml
70-
echo "→ Generating CRDs for apis package..."
70+
echo " → Generating CRDs for apis package..."
7171
${CONTROLLER_GEN} object crd:crdVersions=v1 paths="./apis/..." output:crd:stdout | \
7272
${YAMLFMT} - | \
7373
${YQ} eval '.' --no-doc --split-exp '"./config/crd/standard/" + .metadata.name + ".yaml"'
@@ -76,9 +76,9 @@ ${CONTROLLER_GEN} object crd:crdVersions=v1 paths="./apis/..." output:crd:stdout
7676
# - Reads CRDs from config/crd/standard/
7777
# - Filters annotations to only keep kubernetes.io/* (removes controller-gen annotations)
7878
# - Splits and saves to charts/external-dns/crds/ for Helm chart packaging
79-
echo "→ Copying CRDs to chart directory..."
79+
echo " → Copying CRDs to chart directory..."
8080
${YQ} eval '.metadata.annotations |= with_entries(select(.key | test("kubernetes\.io")))' \
8181
--no-doc --split-exp '"./charts/external-dns/crds/" + .metadata.name + ".yaml"' \
8282
./config/crd/standard/*.yaml
8383

84-
echo "✅ CRD generation complete"
84+
echo -e " ✅ CRD generation complete"

0 commit comments

Comments
 (0)