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 generate-k8s-api in Makefile #24651

Conversation

mhofstetter
Copy link
Member

@mhofstetter mhofstetter commented Mar 30, 2023

  • Makefile: Support for executing make generate-k8s-api outside of GOPATH by generating into tmp directory
  • Makefile: Restructure generation by executing the generators by "type" instead of per package and get rid of "nested make functions"
  • Makefile: Get rid of hardcoded deepcopy & deepequal packages (evaluate them via the go tags)
  • CI: Removing k8s-client & protobuf artifacts in the k8s-api generation check
  • deepequal: Fixing missing deepequal reuse of dependent go-types (this became relevant when building all deepequal types in one batch)

@mhofstetter mhofstetter added kind/cleanup This includes no functional changes. sig/k8s Impacts the kubernetes API, or kubernetes -> cilium internals translation layers. 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 30, 2023
@mhofstetter mhofstetter marked this pull request as ready for review March 30, 2023 16:29
@mhofstetter mhofstetter requested review from a team as code owners March 30, 2023 16:29
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.

Nice work! One minor nit on $(QUIET) usage. I don't understand the k8s generator in patch 2 well enough to review, so I skipped that. I looked at the rest of the patches.

Makefile Outdated
@@ -56,48 +56,50 @@ TEST_LDFLAGS=-ldflags "-X github.com/cilium/cilium/pkg/kvstore.consulDummyAddres
TEST_UNITTEST_LDFLAGS=-ldflags "-X github.com/cilium/cilium/pkg/datapath.DatapathSHA256=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"

define generate_k8s_api
cd "./vendor/k8s.io/code-generator" && \
GO111MODULE=off bash ./generate-groups.sh $(1) \
$(QUIET) cd "./vendor/k8s.io/code-generator" && \
Copy link
Member

Choose a reason for hiding this comment

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

I think that we end up potentially duplicating these $(QUIET) statements if we have them inside the templates like this. For instance

	$(QUIET) $(call generate_k8s_api_deepcopy_deepequal_client,client,github.com/cilium/cilium/pkg/k8s/slim/k8s/api,"$\ ...

=>

$(call generate_k8s_api,deepcopy,github.com/cilium/cilium/pkg/k8s/client,$(1),$(2),$(3))

=>

$(QUIET) cd "./vendor/k8s.io/code-generator" && \ ...

Maybe we should only use those statements in the main targets and not inside the templates?

Copy link
Member Author

Choose a reason for hiding this comment

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

hey @joestringer , thanks for your input!

over the whole PR - they ended up being only in the template - and not in both (main target and template) 😄

but would be definitely nicer to have them only in the main targets. it's just that this only works as intended if the template only contains one command. otherwise (e.g. generate_k8s_protobuf (where tools are getting installed first)) only the first commands gets silenced.

-> i moved the $(QUIET)'s to the main target and chained the installation commands with the generation command in the mentioned case!

Makefile Show resolved Hide resolved
Copy link
Member

@christarazi christarazi left a comment

Choose a reason for hiding this comment

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

🚀

K8s generators behave quite differently when building within or outside
of the GOPATH. Before these changes, when building outside of GOPATH,
the generated artifacts have been generated within the directory
'github.com/cilium/cilium' within the working directory itself.

With this commit, the artifacts are built into a temporary directory and
copied into the right place.

Signed-off-by: Marco Hofstetter <marco.hofstetter@isovalent.com>
Before this commit, the generator has been triggered for every package
with the necessary types.

This commit changes this, by generating per type (proto, deepcopy,
deepequal, client, ...) which eases the use of understanding, optimizes
performance in case of building outside of GOPATH and allows better
reuse of generated deepequal methods from other types.

Signed-off-by: Marco Hofstetter <marco.hofstetter@isovalent.com>
By generating deepequal files for all packages at once - an issue arised
around reusing the deepequal methods of referenced types. Depending on
the order and building in-/ouside of GOPATH, the generated artifacts
differed.

Upgrading to a new version of github.com/cilium/deepequal-gen fixes the
issue and adds the missing reusages.

Signed-off-by: Marco Hofstetter <marco.hofstetter@isovalent.com>
Signed-off-by: Marco Hofstetter <marco.hofstetter@isovalent.com>
Signed-off-by: Marco Hofstetter <marco.hofstetter@isovalent.com>
This commit removes the hardcoded list of deepequal & deepcopy go
packages. Instead the relevant packages are getting evaluated by looking
up packages which contain go files with the corresponding markers.

Signed-off-by: Marco Hofstetter <marco.hofstetter@isovalent.com>
This commit enforces deletion of generated k8s-client & protobuf
artifacts before generating and checking for diffs in
'check-k8s-code-gen.sh'. This helps in detecting issues and stale
artifacts.

Signed-off-by: Marco Hofstetter <marco.hofstetter@isovalent.com>
make generate-k8s-api no longer relies on the GOPATH. Therefore, it can
be moved when executing the checks in the GH action.

Signed-off-by: Marco Hofstetter <marco.hofstetter@isovalent.com>
@mhofstetter mhofstetter force-pushed the pr/mhofstetter/generate-k8s-api-worktree branch from c95dcad to 06a366b Compare March 31, 2023 05:34
Copy link
Member

@sayboras sayboras left a comment

Choose a reason for hiding this comment

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

Nice work 💯 🎖️

@mhofstetter
Copy link
Member Author

/test

@michi-covalent michi-covalent merged commit d789655 into cilium:master Mar 31, 2023
42 checks passed
@mhofstetter mhofstetter deleted the pr/mhofstetter/generate-k8s-api-worktree branch April 1, 2023 07:24
@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. 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

8 participants