Skip to content
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

Merged
merged 5 commits into from Apr 3, 2023

Conversation

christarazi
Copy link
Member

@christarazi christarazi commented Mar 29, 2023

  • 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

@christarazi christarazi added kind/cleanup This includes no functional changes. area/misc Impacts miscellaneous areas of the code not otherwise owned by another area. release-note/misc This PR makes changes that have no direct user impact. area/build Anything to do with the build, more general then area/CI labels Mar 29, 2023
@maintainer-s-little-helper maintainer-s-little-helper bot added dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. and removed dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. labels Mar 29, 2023
@christarazi christarazi added the sig/k8s Impacts the kubernetes API, or kubernetes -> cilium internals translation layers. label Mar 29, 2023
@christarazi christarazi changed the title pr/christarazi/refactor crd creation Refactor CRD generation in Makefile Mar 29, 2023
@christarazi christarazi marked this pull request as ready for review March 29, 2023 23:30
@christarazi christarazi requested review from a team as code owners March 29, 2023 23:30
Makefile Outdated Show resolved Hide resolved
@christarazi christarazi force-pushed the pr/christarazi/refactor-crd-creation branch from 22855ab to b2e90a7 Compare March 30, 2023 00:30
@christarazi
Copy link
Member Author

christarazi commented Mar 30, 2023

/test

Job 'Cilium-PR-K8s-1.26-kernel-net-next' failed:

Click to show.

Test Name

K8sDatapathCustomCalls Basic test with byte-counter Loads byte-counter and gets consistent values, with per-endpoint routes

Failure Output

FAIL: Timed out after 240.000s.

If it is a flake and a GitHub issue doesn't already exist to track it, comment /mlh new-flake Cilium-PR-K8s-1.26-kernel-net-next so I can create one.

Copy link
Member

@joestringer joestringer left a 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)

@christarazi
Copy link
Member Author

christarazi commented Mar 30, 2023

@joestringer Good question. I guess we have the GH Action to run make manifests generate-k8s-api and ensure that we don't have a mismatch, but the flip side is to check whether we didn't break legitimate runs to introduce changes to the existing CRDs and checking that we get the same output from this branch vs master.

I applied the following diff to both this branch and master, and ran the make targets:

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?

@mhofstetter
Copy link
Member

mhofstetter commented Mar 30, 2023

regarding generator check: check-k8s-code-gen.sh gets executed in the GH action lint-go.

might be worth to delete the artifacts generated by make manifests before re-generating and checking (delete pkg/k8s/apis/cilium.io/client/crds ?). the same is already performed for deepequal & deepcopy artifacts. This way we also detect stale generated artifacts.

ℹ️ btw: by doing this we have to ensure, that make manifests creates the directories pkg/k8s/apis/cilium.io/client/crds/v2 & pkg/k8s/apis/cilium.io/client/crds/v2alpha1 - otherwise copying the YAMLs from the tmp directory fails due to missing target directory

Makefile Show resolved Hide resolved
@christarazi christarazi force-pushed the pr/christarazi/refactor-crd-creation branch from b2e90a7 to 07ade12 Compare March 30, 2023 23:19
@christarazi
Copy link
Member Author

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
Copy link
Member

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. 👍

Copy link
Member

@qmonnet qmonnet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Comment on lines +271 to +215
# Clean up old CRD state and start with a blank state.
for path in $(CRDS_CILIUM_PATHS); do rm -rf $${path} && mkdir $${path}; done
Copy link
Member

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.

Suggested change
# 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>
@christarazi christarazi force-pushed the pr/christarazi/refactor-crd-creation branch from 07ade12 to 3cb2156 Compare March 31, 2023 22:42
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>
@christarazi christarazi force-pushed the pr/christarazi/refactor-crd-creation branch from 3cb2156 to 3d98466 Compare March 31, 2023 22:44
@christarazi
Copy link
Member Author

christarazi commented Mar 31, 2023

/test

Edit: Hit #24573

@christarazi
Copy link
Member Author

Marking ready to merge as we have approving reviews and CI is passing except for known flakes

@christarazi christarazi added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Apr 1, 2023
@julianwiedmann julianwiedmann merged commit eb7645b into master Apr 3, 2023
42 checks passed
@julianwiedmann julianwiedmann deleted the pr/christarazi/refactor-crd-creation branch April 3, 2023 06:36
@christarazi christarazi added backport/author The backport will be carried out by the author of the PR. affects/v1.13 This issue affects v1.13 branch labels Apr 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects/v1.13 This issue affects v1.13 branch area/build Anything to do with the build, more general then area/CI area/misc Impacts miscellaneous areas of the code not otherwise owned by another area. backport/author The backport will be carried out by the author of the PR. kind/cleanup This includes no functional changes. ready-to-merge This PR has passed all tests and received consensus from code owners to merge. release-note/misc This PR makes changes that have no direct user impact. sig/k8s Impacts the kubernetes API, or kubernetes -> cilium internals translation layers.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants