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

Add option to use native binaries in dep factory #2683

Merged
merged 6 commits into from
Jul 11, 2022

Conversation

g-gaston
Copy link
Member

@g-gaston g-gaston commented Jul 7, 2022

Description of changes

Until now, the executable builder always decided if docker needed to be used or not, based on an env var. This made the constructor take all the arguments, even when some of them aren't needed. Moreover, in order to build local native executables programmatically through the factory, we needed to set an env var and force the use of a "fake" tools image.

Now the factory has an specific option to use docker or not. If it's not set, it will default to the value of the env var, keeping current behavior. But it allows to override it.

The executables builder has changed quite a bit. Now we have two constructors for it, one for the docker implementation and another one for the local binaries one. The deps factory decided which one to call.

I also separated the builder construction from the container initialization. I added a helper that does both together in order to keep the refactor of all usages at a minimum.

You'll see a lot of tests (and some changes) that seem unrelated to this feature. They are. The code was difficult to test and was missing a lot of tests, so I had to change some things around in order to be able to test. It's not perfect but I think it's better than what we had. If we want to make it good, we probably need a bigger more focused refactor, most probably splitting this package and moving things around.

Testing (if applicable)

Unit tests

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@eks-distro-bot eks-distro-bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jul 7, 2022
@g-gaston g-gaston force-pushed the docker-builder-from-factory branch from d616d12 to b885139 Compare July 7, 2022 21:44
@codecov
Copy link

codecov bot commented Jul 7, 2022

Codecov Report

Merging #2683 (6923062) into main (b4f644f) will increase coverage by 0.48%.
The diff coverage is 87.70%.

@@            Coverage Diff             @@
##             main    #2683      +/-   ##
==========================================
+ Coverage   57.87%   58.35%   +0.48%     
==========================================
  Files         311      312       +1     
  Lines       25561    25594      +33     
==========================================
+ Hits        14793    14935     +142     
+ Misses       9452     9341     -111     
- Partials     1316     1318       +2     
Impacted Files Coverage Δ
pkg/executables/builder.go 59.15% <81.25%> (+59.15%) ⬆️
pkg/dependencies/factory.go 63.40% <86.95%> (+2.26%) ⬆️
pkg/executables/dockerbuilder.go 100.00% <100.00%> (ø)
pkg/executables/dockercontainer.go 79.62% <100.00%> (+39.24%) ⬆️
pkg/executables/dockerlinux.go 18.51% <100.00%> (+18.51%) ⬆️
pkg/executables/local.go 100.00% <100.00%> (ø)
pkg/types/resources.go 35.29% <0.00%> (ø)
controllers/vsphere_machineconfig_controller.go
pkg/executables/kubectl.go 42.64% <0.00%> (+0.10%) ⬆️
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b4f644f...6923062. Read the comment docs.

@g-gaston g-gaston force-pushed the docker-builder-from-factory branch from b885139 to 1ea2fb0 Compare July 8, 2022 02:03
@eks-distro-bot eks-distro-bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 8, 2022
@g-gaston g-gaston force-pushed the docker-builder-from-factory branch 2 times, most recently from 2d8a4d6 to 32f1a58 Compare July 8, 2022 17:08
Until now, the executable builder always decided if docker needed to be
used or not, based on an env var. This made the constructor take all the
arguments, even when some of them aren't needed. Moreover, in order to
build local native executables programmatically through the factory, we
needed to set an env var and force the use of a "fake" tools image.

Now the factory has an specific option to use docker or not. If it's not
set, it will default to the value of the env var, keeping current
behavior. But it allows to override it.
// UserExecutablesDockerClient forces a specific DockerClient to build
// Executables as opposed to follow the normal building flow
// This is only for testing
func (f *Factory) UserExecutablesDockerClient(client executables.DockerClient) *Factory {
Copy link
Member

Choose a reason for hiding this comment

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

Is it supposed to be this?

Suggested change
func (f *Factory) UserExecutablesDockerClient(client executables.DockerClient) *Factory {
func (f *Factory) UseExecutablesDockerClient(client executables.DockerClient) *Factory {

Copy link
Member

Choose a reason for hiding this comment

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

If this is only used for testing, it might be clearer to mention in the method name that it is for Testing. But I would understand not doing that if we want to extend it to be able to pass it in other situations

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed typo

As for adding Testing to the method, unless you feel strongly about this, I prefer to keep it just in the description doc. In general, I think method names should indicate what they do, not what they are used for.

executablesImage string
executablesInDocker bool
Copy link
Member

Choose a reason for hiding this comment

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

If we have a WithDocker, why not call this something like containerExecutables, and then if we have WithPodman in the future, it would use the same logic here? Just want to see if that is possible vs calling everything executableInDocker or InitInDocker or something, but I understand that it would be more refactoring and something we can pick up later when we actually support the different ones.

Copy link
Member Author

Choose a reason for hiding this comment

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

containerExecutables seems a bit ambiguous. If you prefer executablesInContainer, I'm ok with that.

However, as you are saying, if we want to support more container runtimes/clients, there would more stuff we would need to change.

pkg/executables/builder.go Outdated Show resolved Hide resolved
pkg/executables/builder.go Outdated Show resolved Hide resolved
pkg/dependencies/factory.go Outdated Show resolved Hide resolved
@g-gaston
Copy link
Member Author

/approve

@eks-distro-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: g-gaston

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@eks-distro-bot eks-distro-bot merged commit 8b89b4d into aws:main Jul 11, 2022
YoyoTT pushed a commit to YoyoTT/eks-anywhere that referenced this pull request Jul 12, 2022
* Add option to use native binaries in dep factory

Until now, the executable builder always decided if docker needed to be
used or not, based on an env var. This made the constructor take all the
arguments, even when some of them aren't needed. Moreover, in order to
build local native executables programmatically through the factory, we
needed to set an env var and force the use of a "fake" tools image.

Now the factory has an specific option to use docker or not. If it's not
set, it will default to the value of the env var, keeping current
behavior. But it allows to override it.

* Fix typo in factory method name

* Fixed typo in doc comment

Co-authored-by: Joey Wang <jiayiwang7@yahoo.com>

* Fixed typo in doc comment

* Nest executables fields in factory

* Remove unnecessary tests

Co-authored-by: Joey Wang <jiayiwang7@yahoo.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants