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

Use go embed and remove go-bindata dependency #15834

Merged
merged 2 commits into from
Apr 23, 2021
Merged

Conversation

aanm
Copy link
Member

@aanm aanm commented Apr 22, 2021

Read per commit basis

@aanm aanm added kind/cleanup This includes no functional changes. sig/k8s Impacts the kubernetes API, or kubernetes -> cilium internals translation layers. release-blocker/1.10 labels Apr 22, 2021
@aanm aanm added this to the 1.10.0 milestone Apr 22, 2021
@aanm aanm requested a review from christarazi April 22, 2021 18:08
@aanm aanm requested review from a team as code owners April 22, 2021 18:08
@aanm aanm requested a review from a team April 22, 2021 18:08
@aanm aanm requested review from a team as code owners April 22, 2021 18:08
@aanm aanm requested a review from nathanjsweet April 22, 2021 18:08
@maintainer-s-little-helper maintainer-s-little-helper bot added the dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. label Apr 22, 2021
@aanm aanm requested a review from tklauser April 22, 2021 18:08
@aanm aanm added the release-note/misc This PR makes changes that have no direct user impact. label Apr 22, 2021
@maintainer-s-little-helper maintainer-s-little-helper bot removed the dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. label Apr 22, 2021
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.

🚀 Fantastic!

.gitattributes Show resolved Hide resolved
@christarazi christarazi removed their assignment Apr 22, 2021
Makefile Outdated Show resolved Hide resolved
@christarazi
Copy link
Member

generate-k8s-api is failing because the CI workflow is still trying to use go-bindata

In Golang 1.16 we can use go embed to embed files without using a 3rd
party library. Thus we can remove the go-bindata from our list of
dependencies.

Signed-off-by: André Martins <andre@cilium.io>
@aanm aanm force-pushed the pr/go-embed branch 2 times, most recently from 37ef971 to d4b2e94 Compare April 22, 2021 19:44
Copy link
Member

@aditighag aditighag left a comment

Choose a reason for hiding this comment

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

🚀 There are other references [1] of go-bindata in Makefile that need to be removed as well?

[1] https://github.com/cilium/cilium/blob/master/Makefile#L434

Makefile Outdated Show resolved Hide resolved
@aanm
Copy link
Member Author

aanm commented Apr 22, 2021

There are other references [1] of go-bindata in Makefile that need to be removed as well?

[1] https://github.com/cilium/cilium/blob/master/Makefile#L434

@aditighag it's already gone 🧙

@aanm
Copy link
Member Author

aanm commented Apr 22, 2021

test-me-please

pkg/k8s/cnp.go Outdated
@@ -78,7 +78,7 @@ func (c *CNPStatusUpdateContext) updateStatus(ctx context.Context, cnp *types.Sl
if option.Config.K8sEventHandover {
err = c.updateViaKVStore(ctx, cnp, false, false, policyImportErr, rev, cnp.Annotations)
} else {
err = c.updateViaAPIServer(cnp, false, false, policyImportErr, rev, cnp.Annotations)
err = c.UpdateViaAPIServer(cnp, false, false, policyImportErr, rev, cnp.Annotations)
Copy link
Member

Choose a reason for hiding this comment

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

Why export the function if it's only used in unit tests?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's in the commit message. I had to the unit tests a dedicated package to avoid import cycle

Copy link
Member

Choose a reason for hiding this comment

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

Why is there an import cycle? Is this the only way to avoid it?

Copy link
Member

Choose a reason for hiding this comment

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

That's not what I was referring to. I meant to ask if you tried doing something like this to avoid exporting a method for unit tests only - https://medium.com/@robiplus/golang-trick-export-for-test-aa16cbd7b8cd.

Copy link
Member Author

Choose a reason for hiding this comment

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

@christarazi the unit tests (pkg/k8s) imports pkg/k8s/apis/cilium.io/v2/client which imports pkg/k8s

Copy link
Member Author

Choose a reason for hiding this comment

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

@aditighag Maybe I'm missing something but I don't see how that can work since the link referes to a package function where this is a structure's method?

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 you'd need to have a test file specifically be a part of the package k8s which does var UpdateViaAPIServer = updateViaAPIServer which then you use in the package k8s_test. However, that's moot because of the import cycle problem.

Do you think that we should refactor so we avoid the import cycle to begin with? I feel that when we run into an import cycle, that usually means we should reorg the code a bit, no?

Copy link
Member Author

Choose a reason for hiding this comment

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

@christarazi but that won't work because updateViaAPIServer is a method, not a function, like in the example from the medium link.

Do you think that we should refactor so we avoid the import cycle to begin with? I feel that when we run into an import cycle, that usually means we should reorg the code a bit, no?

I would say so but the import cycle happens in the testing package. I only found it when the CI complained as far as "production" code, it's not affected. I thought about on having a benchmark package inside pkg/k8s dedicated to this _test.go file but in the end it would be the same as simply renaming package k8s to package k8s_test, which is what the PR is doing.

Copy link
Member

Choose a reason for hiding this comment

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

@aanm Sure, the trick works - aditighag@aec66c0.

Copy link
Member Author

Choose a reason for hiding this comment

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

@aditighag PTAL again.

@aanm
Copy link
Member Author

aanm commented Apr 23, 2021

The entire CI was green, I only added a new change suggested by Aditi so there's no need to run the entire CI again.

The CRDs should be self-contained in a directory with different
versions. By also moving the registration of the CRDs into a
self-contained package, the operator, the entity that registers the CRDs
since Cilium 1.9, will be the only binary that will load these files
into memory, reducing the memory consumption of the cilium-agent.

The test cnp_test.go had to be put in a dedicated package to avoid
import cycle.

Signed-off-by: André Martins <andre@cilium.io>
Copy link
Member

@tklauser tklauser left a comment

Choose a reason for hiding this comment

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

Nice 🎉

Copy link
Member

@rolinh rolinh left a comment

Choose a reason for hiding this comment

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

🚀

@aditighag aditighag removed their assignment Apr 23, 2021
@aanm aanm merged commit b667f01 into cilium:master Apr 23, 2021
@aanm aanm deleted the pr/go-embed branch April 23, 2021 18:35
@aanm aanm mentioned this pull request Apr 23, 2021
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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
No open projects
1.10.0
Awaiting triage
Development

Successfully merging this pull request may close these issues.

None yet

6 participants