Skip to content

Commit a5c717d

Browse files
committed
TMP: crd-generator-work
Signed-off-by: Todd Short <[email protected]>
1 parent cecd003 commit a5c717d

File tree

15 files changed

+1571
-17
lines changed

15 files changed

+1571
-17
lines changed

Makefile

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,20 +129,14 @@ tidy:
129129
go mod tidy
130130

131131
.PHONY: manifests
132-
KUSTOMIZE_CATD_CRDS_DIR := config/base/catalogd/crd/bases
133132
KUSTOMIZE_CATD_RBAC_DIR := config/base/catalogd/rbac
134133
KUSTOMIZE_CATD_WEBHOOKS_DIR := config/base/catalogd/manager/webhook
135-
KUSTOMIZE_OPCON_CRDS_DIR := config/base/operator-controller/crd/bases
136134
KUSTOMIZE_OPCON_RBAC_DIR := config/base/operator-controller/rbac
137-
CRD_WORKING_DIR := crd_work_dir
138135
# Due to https://github.com/kubernetes-sigs/controller-tools/issues/837 we can't specify individual files
139136
# So we have to generate them together and then move them into place
140137
manifests: $(CONTROLLER_GEN) #EXHELP Generate WebhookConfiguration, ClusterRole, and CustomResourceDefinition objects.
141-
mkdir $(CRD_WORKING_DIR)
142-
$(CONTROLLER_GEN) --load-build-tags=$(GO_BUILD_TAGS) crd paths="./api/v1/..." output:crd:artifacts:config=$(CRD_WORKING_DIR)
143-
mv $(CRD_WORKING_DIR)/olm.operatorframework.io_clusterextensions.yaml $(KUSTOMIZE_OPCON_CRDS_DIR)
144-
mv $(CRD_WORKING_DIR)/olm.operatorframework.io_clustercatalogs.yaml $(KUSTOMIZE_CATD_CRDS_DIR)
145-
rmdir $(CRD_WORKING_DIR)
138+
# Generate CRDs via our own generator
139+
hack/tools/update-crds.sh
146140
# Generate the remaining operator-controller manifests
147141
$(CONTROLLER_GEN) --load-build-tags=$(GO_BUILD_TAGS) rbac:roleName=manager-role paths="./internal/operator-controller/..." output:rbac:artifacts:config=$(KUSTOMIZE_OPCON_RBAC_DIR)
148142
# Generate the remaining catalogd manifests
@@ -181,8 +175,8 @@ bingo-upgrade: $(BINGO) #EXHELP Upgrade tools
181175
.PHONY: verify-crd-compatibility
182176
CRD_DIFF_ORIGINAL_REF := git://main?path=
183177
CRD_DIFF_UPDATED_REF := file://
184-
CRD_DIFF_OPCON_SOURCE := config/base/operator-controller/crd/bases/olm.operatorframework.io_clusterextensions.yaml
185-
CRD_DIFF_CATD_SOURCE := config/base/catalogd/crd/bases/olm.operatorframework.io_clustercatalogs.yaml
178+
CRD_DIFF_OPCON_SOURCE := config/base/operator-controller/crd/standard/olm.operatorframework.io_clusterextensions.yaml
179+
CRD_DIFF_CATD_SOURCE := config/base/catalogd/crd/standard/olm.operatorframework.io_clustercatalogs.yaml
186180
CRD_DIFF_CONFIG := crd-diff-config.yaml
187181
verify-crd-compatibility: $(CRD_DIFF) manifests
188182
$(CRD_DIFF) --config="${CRD_DIFF_CONFIG}" "${CRD_DIFF_ORIGINAL_REF}${CRD_DIFF_OPCON_SOURCE}" ${CRD_DIFF_UPDATED_REF}${CRD_DIFF_OPCON_SOURCE}

api/v1/clustercatalog_types_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"sigs.k8s.io/yaml"
2121
)
2222

23-
const crdFilePath = "../../config/base/catalogd/crd/bases/olm.operatorframework.io_clustercatalogs.yaml"
23+
const crdFilePath = "../../config/base/catalogd/crd/standard/olm.operatorframework.io_clustercatalogs.yaml"
2424

2525
func TestImageSourceCELValidationRules(t *testing.T) {
2626
validators := fieldValidatorsFromFile(t, crdFilePath)

config/base/catalogd/crd/experimental/olm.operatorframework.io_clustercatalogs.yaml

Lines changed: 442 additions & 0 deletions
Large diffs are not rendered by default.

config/base/catalogd/crd/kustomization.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
# since it depends on service name and namespace that are out of this kustomize package.
33
# It should be run by config/default
44
resources:
5-
- bases/olm.operatorframework.io_clustercatalogs.yaml
5+
- standard/olm.operatorframework.io_clustercatalogs.yaml
66
#+kubebuilder:scaffold:crdkustomizeresource

config/base/catalogd/crd/bases/olm.operatorframework.io_clustercatalogs.yaml renamed to config/base/catalogd/crd/standard/olm.operatorframework.io_clustercatalogs.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ kind: CustomResourceDefinition
44
metadata:
55
annotations:
66
controller-gen.kubebuilder.io/version: v0.17.3
7+
olm.operatorframework.io/channel: standard
78
name: clustercatalogs.olm.operatorframework.io
89
spec:
910
group: olm.operatorframework.io

config/base/operator-controller/crd/experimental/olm.operatorframework.io_clusterextensions.yaml

Lines changed: 590 additions & 0 deletions
Large diffs are not rendered by default.

config/base/operator-controller/crd/kustomization.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# since it depends on service name and namespace that are out of this kustomize package.
33
# It should be run by config/default
44
resources:
5-
- bases/olm.operatorframework.io_clusterextensions.yaml
5+
- standard/olm.operatorframework.io_clusterextensions.yaml
66

77
# the following config is for teaching kustomize how to do kustomization for CRDs.
88
configurations:

config/base/operator-controller/crd/bases/olm.operatorframework.io_clusterextensions.yaml renamed to config/base/operator-controller/crd/standard/olm.operatorframework.io_clusterextensions.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ kind: CustomResourceDefinition
44
metadata:
55
annotations:
66
controller-gen.kubebuilder.io/version: v0.17.3
7+
olm.operatorframework.io/channel: standard
78
name: clusterextensions.olm.operatorframework.io
89
spec:
910
group: olm.operatorframework.io

go.mod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ require (
4141
k8s.io/kubernetes v1.32.3
4242
k8s.io/utils v0.0.0-20241210054802-24370beab758
4343
sigs.k8s.io/controller-runtime v0.20.4
44+
sigs.k8s.io/controller-tools v0.17.3
4445
sigs.k8s.io/yaml v1.4.0
4546
)
4647

@@ -97,7 +98,7 @@ require (
9798
github.com/evanphx/json-patch v5.9.0+incompatible // indirect
9899
github.com/evanphx/json-patch/v5 v5.9.11 // indirect
99100
github.com/exponent-io/jsonpath v0.0.0-20210407135951-1de76d718b3f // indirect
100-
github.com/fatih/color v1.16.0 // indirect
101+
github.com/fatih/color v1.18.0 // indirect
101102
github.com/felixge/httpsnoop v1.0.4 // indirect
102103
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
103104
github.com/go-errors/errors v1.4.2 // indirect
@@ -117,6 +118,7 @@ require (
117118
github.com/go-openapi/strfmt v0.23.0 // indirect
118119
github.com/go-openapi/swag v0.23.1 // indirect
119120
github.com/go-openapi/validate v0.24.0 // indirect
121+
github.com/gobuffalo/flect v1.0.3 // indirect
120122
github.com/gobwas/glob v0.2.3 // indirect
121123
github.com/gogo/protobuf v1.3.2 // indirect
122124
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect

go.sum

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ github.com/evanphx/json-patch/v5 v5.9.11 h1:/8HVnzMq13/3x9TPvjG08wUGqBTmZBsCWzjT
142142
github.com/evanphx/json-patch/v5 v5.9.11/go.mod h1:3j+LviiESTElxA4p3EMKAB9HXj3/XEtnUf6OZxqIQTM=
143143
github.com/exponent-io/jsonpath v0.0.0-20210407135951-1de76d718b3f h1:Wl78ApPPB2Wvf/TIe2xdyJxTlb6obmF18d8QdkxNDu4=
144144
github.com/exponent-io/jsonpath v0.0.0-20210407135951-1de76d718b3f/go.mod h1:OSYXu++VVOHnXeitef/D8n/6y4QV8uLHSFXX4NeXMGc=
145-
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
146-
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
145+
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
146+
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=
147147
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
148148
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
149149
github.com/foxcpp/go-mockdns v1.1.0 h1:jI0rD8M0wuYAxL7r/ynTrCQQq0BVqfB99Vgk7DlmewI=
@@ -204,6 +204,8 @@ github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1v
204204
github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8=
205205
github.com/go-test/deep v1.1.1 h1:0r/53hagsehfO4bzD2Pgr/+RgHqhmf+k1Bpse2cTu1U=
206206
github.com/go-test/deep v1.1.1/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
207+
github.com/gobuffalo/flect v1.0.3 h1:xeWBM2nui+qnVvNM4S3foBhCAL2XgPU+a7FdpelbTq4=
208+
github.com/gobuffalo/flect v1.0.3/go.mod h1:A5msMlrHtLqh9umBSnvabjsMrCcCpAyzglnDvkbYKHs=
207209
github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
208210
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
209211
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
@@ -386,8 +388,12 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8m
386388
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
387389
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f h1:y5//uYreIhSUg3J1GEMiLbxo1LJaP8RfCpH6pymGZus=
388390
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw=
391+
github.com/nxadm/tail v1.4.11 h1:8feyoE3OzPrcshW5/MJ4sGESc5cqmGkGCWlco4l0bqY=
392+
github.com/nxadm/tail v1.4.11/go.mod h1:OTaG3NK980DZzxbRq6lEuzgU+mug70nY11sMd4JXXHc=
389393
github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4=
390394
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
395+
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
396+
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
391397
github.com/onsi/ginkgo/v2 v2.23.4 h1:ktYTpKJAVZnDT4VjxSbiBenUjmlL/5QkBEocaWXiQus=
392398
github.com/onsi/ginkgo/v2 v2.23.4/go.mod h1:Bt66ApGPBFzHyR+JO10Zbt0Gsp4uWxu5mIOTusL46e8=
393399
github.com/onsi/gomega v1.37.0 h1:CdEG8g0S133B4OswTDC/5XPSzE1OeP29QOioj2PID2Y=
@@ -763,6 +769,8 @@ gopkg.in/evanphx/json-patch.v4 v4.12.0 h1:n6jtcsulIzXPJaxegRbvFNNrZDjbij7ny3gmSP
763769
gopkg.in/evanphx/json-patch.v4 v4.12.0/go.mod h1:p8EYWUEYMpynmqDbY58zCKCFZw8pRWMG4EsWvDvM72M=
764770
gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
765771
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
772+
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
773+
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
766774
gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=
767775
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
768776
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
@@ -813,6 +821,8 @@ sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.31.1 h1:uOuSLOMBWkJH0
813821
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.31.1/go.mod h1:Ve9uj1L+deCXFrPOk1LpFXqTg7LCFzFso6PA48q/XZw=
814822
sigs.k8s.io/controller-runtime v0.20.4 h1:X3c+Odnxz+iPTRobG4tp092+CvBU9UK0t/bRf+n0DGU=
815823
sigs.k8s.io/controller-runtime v0.20.4/go.mod h1:xg2XB0K5ShQzAgsoujxuKN4LNXR2LfwwHsPj7Iaw+XY=
824+
sigs.k8s.io/controller-tools v0.17.3 h1:lwFPLicpBKLgIepah+c8ikRBubFW5kOQyT88r3EwfNw=
825+
sigs.k8s.io/controller-tools v0.17.3/go.mod h1:1ii+oXcYZkxcBXzwv3YZBlzjt1fvkrCGjVF73blosJI=
816826
sigs.k8s.io/gateway-api v1.1.0 h1:DsLDXCi6jR+Xz8/xd0Z1PYl2Pn0TyaFMOPPZIj4inDM=
817827
sigs.k8s.io/gateway-api v1.1.0/go.mod h1:ZH4lHrL2sDi0FHZ9jjneb8kKnGzFWyrTya35sWUTrRs=
818828
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 h1:gBQPwqORJ8d8/YNZWEjoZs7npUVDpVXUUOFfW6CgAqE=

hack/tools/update-crds.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env bash
2+
# This uses a custom CRD generator to create "standard" and "experimental" CRDs
3+
4+
# The names of the generated CRDs
5+
CE="olm.operatorframework.io_clusterextensions.yaml"
6+
CC="olm.operatorframework.io_clustercatalogs.yaml"
7+
8+
# order for modules and crds must match
9+
# each item in crds must be unique, and should be associated with a module
10+
modules=("operator-controller" "catalogd")
11+
crds=("${CE}" "${CC}")
12+
13+
# Channels must much those in the generator
14+
channels=("standard" "experimental")
15+
16+
# Create the temp output directories
17+
CRD_TMP=$(mktemp -d)
18+
for c in ${channels[@]}; do
19+
mkdir -p ${CRD_TMP}/${c}
20+
done
21+
22+
CONTROLLER_TOOLS_VER=$(go list -m sigs.k8s.io/controller-tools | awk '{print $2}')
23+
24+
# Generate the CRDs
25+
go run ./pkg/crd-generator ${CRD_TMP} ${CONTROLLER_TOOLS_VER}
26+
27+
# Create the destination directories for each base/channel combo
28+
for c in ${channels[@]}; do
29+
for b in ${modules[@]}; do
30+
mkdir -p config/base/${b}/crd/${c}
31+
done
32+
done
33+
34+
# Copy the generated files
35+
for b in ${!modules[@]}; do
36+
for c in ${channels[@]}; do
37+
cp ${CRD_TMP}/${c}/${crds[${b}]} config/base/${modules[${b}]}/crd/${c}
38+
done
39+
done
40+
41+
# Clean up the temp output directories
42+
rm -rf ${CRD_TMP}

internal/operator-controller/controllers/suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ var (
138138
func TestMain(m *testing.M) {
139139
testEnv := &envtest.Environment{
140140
CRDDirectoryPaths: []string{
141-
filepath.Join("..", "..", "..", "config", "base", "operator-controller", "crd", "bases"),
141+
filepath.Join("..", "..", "..", "config", "base", "operator-controller", "crd", "standard"),
142142
},
143143
ErrorIfCRDPathMissing: true,
144144
}

pkg/crd-generator/README.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Guide to Operator-Controller CRD extensions
2+
3+
All operator-controller (`opcon` for short) extensions to CRDs are part of the
4+
comments to fields within the APIs. The fields look like XML tags, to distinguish
5+
them from kubebuilder tags.
6+
7+
All tags start with `<opcon:`, end with `>` and have additional fields in between.
8+
Usually the second field is `experimental`. Some tags may have an end tag (like XML)
9+
that starts with `</`.
10+
11+
## Experimental Field
12+
13+
* Tag: `<opcon:experimental>`
14+
15+
The field that follows is experimental, and is not included in the standard CRD. It *is* included
16+
in the experimental CRD.
17+
18+
## Experimental Validation
19+
20+
* Tag: `<opcon:standard:valiudation:VALIDATION>`
21+
* Tag: `<opcon:experimental:validation:VALIDATION>`
22+
23+
A standard and/or experimental validation which may differ from one another. For example, where the
24+
experimental CRD has extra enumerations.
25+
26+
Where `VALIDATION` is one of:
27+
28+
* `Enum=list;of;enums`
29+
30+
A semi-colon separated list of enumerations, similar to the `+kubebuilder:validation:Enum` scheme.
31+
32+
* `XValidation:message="something",rule="something"`
33+
34+
An XValidation scheme, similar to the `+kubebuilder:validation:XValidation` scheme, but more limited.
35+
36+
## Experimental Description
37+
38+
* Start Tag: `<opcon:experimental:description>`
39+
* End Tag: `</opcon:experimental:description>`
40+
41+
Descriptive text that is only included as part of the field description within the experimental CRD.
42+
All text between the tags is included in the experimental CRD, but removed from the standard CRD.
43+
44+
This is only useful if the field is included in the standard CRD, but there's additional meaning in
45+
the experimental CRD when feature gates are enabled.
46+
47+
## Exclude from CRD Description
48+
49+
* Start Tag: `<opcon:util:excludeFromCRD>`
50+
* End Tag: `</opcon:util:excludeFromCRD>`
51+
52+
Descriptive text that is excluded from the CRD description. This is similar to the use of `---`, except
53+
the three hypens excludes *all* following text.
54+
55+
## IP Address Validation
56+
57+
* Tag: `<opcon:validateIPAddress>`
58+
59+
This modifies the following field to append IPv4 or IPv6 address validation.
60+
61+
*Part of the original gateway-api generator.*
62+

0 commit comments

Comments
 (0)