New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor CRD generation in Makefile #24615
Conversation
christarazi
commented
Mar 29, 2023
•
edited
edited
- Clarify function for all Cilium CRDs
- Makefile: Extract paths for CRD into variable
- Makefile: Extract CRD groups from generate-k8s-api
- Makefile: Refactor CRD generation to avoid copy-paste pattern
- Makefile: Clean up old CRD state, ensure blank slate
22855ab
to
b2e90a7
Compare
/test Job 'Cilium-PR-K8s-1.26-kernel-net-next' failed: Click to show.Test Name
Failure Output
If it is a flake and a GitHub issue doesn't already exist to track it, comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Broadly looks good to me, how do we test that this doesn't break CRD generation for some of the files? (I'm sure you've done a fine job, but Makefile syntax can be finnicky and surprising at the best of times)
@joestringer Good question. I guess we have the GH Action to run I applied the following diff to both this branch and diff --git a/pkg/policy/api/rule.go b/pkg/policy/api/rule.go
index 6dfeb63244..a0d5484da6 100644
--- a/pkg/policy/api/rule.go
+++ b/pkg/policy/api/rule.go
@@ -100,6 +100,11 @@ type Rule struct {
//
// +kubebuilder:validation:Optional
Description string `json:"description,omitempty"`
+
+ // Foo is a test.
+ //
+ // +kubebuilder:validation:Required
+ Foo string `json:"foo,omitempty"`
}
// MarshalJSON returns the JSON encoding of Rule r. We need to overwrite it to The resulting diff that I get back is identical on both branches, so this should be good to go. Does that resolve your concerns? |
regarding generator check: check-k8s-code-gen.sh gets executed in the GH action might be worth to delete the artifacts generated by ℹ️ btw: by doing this we have to ensure, that |
Documentation/contributing/development/introducing_new_crds.rst
Outdated
Show resolved
Hide resolved
b2e90a7
to
07ade12
Compare
Updated to address Marco's suggestions. There should be a new commit handling the cleaning up of the old artifact state and amending an existing commit to update the docs with the new instructions. |
mv ${TMPDIR}/cilium.io_ciliumnodeconfigs.yaml ./pkg/k8s/apis/cilium.io/client/crds/v2alpha1/ciliumnodeconfigs.yaml | ||
|
||
# Clean up old CRD state and start with a blank state. | ||
for path in $(CRDS_CILIUM_PATHS); do rm -rf $${path} && mkdir $${path}; done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
even though i meant to add it here it's kind of nice to have it in the make target directly! helps to detect stale YAML (of potentially deleted / moved (version) CRDs) even sooner during development. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
# Clean up old CRD state and start with a blank state. | ||
for path in $(CRDS_CILIUM_PATHS); do rm -rf $${path} && mkdir $${path}; done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some nitpick suggestions but they don't really matter, I can't find a case where even mkdir -p
would be necessary. Just “good practices” I guess.
# Clean up old CRD state and start with a blank state. | |
for path in $(CRDS_CILIUM_PATHS); do rm -rf $${path} && mkdir $${path}; done | |
# Clean up old CRD state and start with a blank slate. | |
for path in $(CRDS_CILIUM_PATHS); do $(RM) -rf -- $${path} && mkdir -p $${path}; done |
This clarifies that this function will enumerate all Cilium CRDs, whereas previously it was unclear which CRDs because it said "all CRDs". Signed-off-by: Chris Tarazi <chris@isovalent.com>
This cleans up the invocation of controller-gen so that any new paths don't have to directly change the command line. Signed-off-by: Chris Tarazi <chris@isovalent.com>
07ade12
to
3cb2156
Compare
This will allow the content of the generate-k8s-api to stay the same when needing to add another CRD group. Signed-off-by: Chris Tarazi <chris@isovalent.com>
Now, all a developer is expected to do is to add the name of the CRD they want to generate into the corresponding variable (v2, v2alpha1, etc), and the automation will handle it from there. Signed-off-by: Chris Tarazi <chris@isovalent.com>
With this, we can also detect stale generated artifacts. This is now consistent with how the generate-k8s-api target works as well. Suggested-by: Marco Hofstetter <marco.hofstetter@isovalent.com> Signed-off-by: Chris Tarazi <chris@isovalent.com>
3cb2156
to
3d98466
Compare
/test Edit: Hit #24573 |
Marking ready to merge as we have approving reviews and CI is passing except for known flakes |