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

Optimize package organization to reduce antctl binary size #6037

Merged
merged 1 commit into from
Mar 29, 2024

Conversation

tnqn
Copy link
Member

@tnqn tnqn commented Feb 29, 2024

As a client, antctl needs to know some well-known resource names and the structs of the API responses. However, the code placement makes antctl import a lot of packages which are supposed to be consumed by server side code, e.g. antrea-controller, antrea-agent.

This patch refactors relevant packages, extracts well-known resources names and API structs to separate common packages, mostly apis packages. It reduces antctl binary size by 10MB, from 55MB to 45MB. The placement also makes it more explicit that these constants and structs are API related and should be changed more carefully.

The major changes are as follows:

  1. Move well-known CRD resource names to types.go files which declare these CRD structs.
  2. Move other well-known resource names to package pkg/apis.
  3. Move structs of API responses to package apis of components which provide the corresponding APIs.

For #5883


Before:

-rwxr-xr-x  1 root root  55M Feb 29 09:45 antctl

antrea/antrea-controller-ubuntu           v2.0.0-dev-d28e282d0   a171ba592d24   8 seconds ago    197MB
antrea/antrea-agent-ubuntu                v2.0.0-dev-d28e282d0   7e84ada052f8   15 seconds ago   350MB

After:

-rwxr-xr-x  1 root root  45M Feb 29 09:49 antctl

antrea/antrea-controller-ubuntu           v2.0.0-dev-c94b2155a   15c6096c8ef2   27 seconds ago   187MB
antrea/antrea-agent-ubuntu                v2.0.0-dev-c94b2155a   648ab7d783ca   38 seconds ago   340MB

@tnqn tnqn added action/release-note Indicates a PR that should be included in release notes. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. labels Feb 29, 2024
@tnqn tnqn force-pushed the reduce-antctl-size branch 6 times, most recently from 9abb34a to 8735ba7 Compare February 29, 2024 10:49
@tnqn
Copy link
Member Author

tnqn commented Feb 29, 2024

/test-all
/test-windows-containerd-all
/test-flexible-ipam-e2e
/test-multicast-e2e
/test-multicluster-e2e
/test-ipv6-e2e

@tnqn tnqn requested a review from antoninbas February 29, 2024 13:36
@tnqn
Copy link
Member Author

tnqn commented Feb 29, 2024

/test-ipv6-e2e

antoninbas
antoninbas previously approved these changes Feb 29, 2024
Copy link
Contributor

@antoninbas antoninbas left a comment

Choose a reason for hiding this comment

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

Very nice, I was thinking of the exact same improvement yesterday.

@antoninbas
Copy link
Contributor

/test-ipv6-e2e

@tnqn tnqn mentioned this pull request Mar 1, 2024
3 tasks
@antoninbas antoninbas added this to the Antrea v2.0 release milestone Mar 7, 2024
@antoninbas
Copy link
Contributor

@tnqn anything blocking this?

@tnqn
Copy link
Member Author

tnqn commented Mar 8, 2024

@tnqn anything blocking this?

I was waiting for other large PRs to merge to avoid their rework, e.g. NetworkPolicyEvaluation, K8s lib upgrade.

@tnqn tnqn force-pushed the reduce-antctl-size branch 5 times, most recently from e1ce909 to 3c5f96c Compare March 27, 2024 03:55
@tnqn tnqn requested a review from antoninbas March 27, 2024 10:04
@tnqn
Copy link
Member Author

tnqn commented Mar 27, 2024

/test-all

antoninbas
antoninbas previously approved these changes Mar 27, 2024
Copy link
Contributor

@antoninbas antoninbas left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines 59 to 64
// GetServiceDNSNames returns the DNS names that can be used to access the given Service.
func GetServiceDNSNames(namespace, serviceName string) []string {
antreaServerName := serviceName + "." + namespace + ".svc"
// TODO: Although antrea-agent and kube-aggregator only verify the server name "antrea.<Namespace>.svc",
// We should add the whole FQDN "antrea.<Namespace>.svc.<Cluster Domain>" as an alternate DNS name when
// other clients need to access it directly with that name.
return []string{antreaServerName}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The location in this package and the name of the function make it sound like it is "generic", but then the variable name antreaServerName and the TODO comment kind of make it Antrea-specific.
It's kind of a minor comment though. Maybe we could just rename the variable to something more appropriate.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch. I missed updating it when moving the function.
Updated.

As a client, antctl needs to know some well-known resource names and
the structs of the API responses. However, the code placement makes
antctl import a lot of packages which are supposed to be consumed by
server side code, e.g.  antrea-controller, antrea-agent.

This patch refactors relevant packages, extracts well-known resources
names and API structs to separate common packages, mostly apis packages.
It reduces antctl binary size by 10MB, from 55MB to 45MB. The placement
also makes it more explicit that these constants and structs are API
related and should be changed more carefully.

The major changes are as follows:
1. Move well-known CRD resource names to types.go files which declare
   these CRD structs.
2. Move other well-known resource names to package pkg/apis.
3. Move structs of API responses to package apis of components which
   provide the corresponding APIs.

Signed-off-by: Quan Tian <qtian@vmware.com>
@tnqn
Copy link
Member Author

tnqn commented Mar 28, 2024

/test-all

@tnqn tnqn merged commit abf9e3f into antrea-io:main Mar 29, 2024
52 of 56 checks passed
@tnqn tnqn deleted the reduce-antctl-size branch March 29, 2024 02:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action/release-note Indicates a PR that should be included in release notes. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants