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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate alias for types instead of copies #3188

Merged
merged 1 commit into from
May 20, 2024

Conversation

howardjohn
Copy link
Member

For #3127

Depends on istio/tools#2921.

Currently builds on #3186, so merge that first and I will rebase.


This PR refactors our API strategy. Instead of copies of everything, we just have one single source of truth proto. This has benefits in maintenance in this repo (its really confusing and tedious), and real runtime costs (i.e. we don't need to load multiple MB of copies of protos into our binaries).

There are a few facets of backwards compatibility here. Usage (Via CRD json/yaml, Proto wire, and Go types), and type (first party or third party).

CRD: 馃憤 Absolutely zero changes here.

Go types: 馃憤 Istio currently uses only the oldest types, so it doesn't really matter for first party. However, we will want to use newer ones in the future probably, and we will not want to have to change the versioning here. Third party are already using new versions.
This PR maintains effectively full compatibility with the Go API. While its theoretically possible you are doing crazy reflection stuff that now changes behavior, its not an expected use case. Both the kubernetes client-go and protobuf-go fully handle this change without issues, as does just normal use (e.g. creating a struct). Due to the aliasing, users do not need to change imports at all. Note that Gateway API did the same thing and it was fine.

Protobuf types: 馃敶 this is technically incompatible. Today we have .proto files that are checked into our repo, and a user could theoretically take those and send them on the wire. However:

  • We don't document, test, or claim any support for this general usage
  • We do have a feature (also undocumented and tested, but has usage) of receiving and sending Istio APIs over proto on the wire ("MCP over XDS"). However, this always uses the oldest versions today -- the ones that we are keeping.
    Based on this, I believe this is an acceptably small breakage. If a user is somehow impacted, they can take our scripts to replicate the protos and/or move to the canonical version.

This PR has been manually tested in istio.io/istio to ensure all tests pass.

@istio-testing
Copy link
Collaborator

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@istio-testing istio-testing added do-not-merge/work-in-progress Block merging of a PR because it isn't ready yet. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels May 10, 2024
@keithmattix
Copy link
Contributor

What's the process for when we actually need to have 2 versions of a resource? Or is the plan to not ever do that and to rely solely on admission?

@howardjohn
Copy link
Member Author

@keithmattix it is not possible in Kubernetes to have 2 distinct schemas across versions without a conversion webhook which we don't (currently?) plan to ever do.

That being said, if we legitimately do we can just have those type(s) do things the old way I suppose

@keithmattix
Copy link
Contributor

It would be more like the v1alpha1 and a v1 upgrade story. Istiod would need to be able to read both to prevent breakage. So the rule would be that you can't make a change (i.e adding a field) while promoting a version. If we don't document that, we should. I think that prevents the issue

@howardjohn
Copy link
Member Author

@keithmattix you can still read both versions from k8s (see info in the "Go types"). Actually it would make it much easier, since the types are actually the same. In todays world, you would either need to have a slow conversion or duplicate code for each version.

@howardjohn
Copy link
Member Author

Discussed in TOC today; there were no objections that came up there. Feel free to comment here if you were not there/disagree/changed your mind/etc

@istio-testing istio-testing added the needs-rebase Indicates a PR needs to be rebased before being merged label May 13, 2024
@howardjohn howardjohn marked this pull request as ready for review May 14, 2024 22:14
@howardjohn howardjohn requested review from a team as code owners May 14, 2024 22:14
@istio-testing istio-testing removed do-not-merge/work-in-progress Block merging of a PR because it isn't ready yet. needs-rebase Indicates a PR needs to be rebased before being merged labels May 14, 2024
@howardjohn
Copy link
Member Author

/retest

1 similar comment
@howardjohn
Copy link
Member Author

/retest

Copy link
Member

@linsun linsun left a comment

Choose a reason for hiding this comment

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

LGTM overall

What is not clear to me (might be good to have it doc-ed) is if I need to introduce a new API change (for example, add a field) in a resource, I update the proto file in the alpha version first if it exists (then beta). Assuming I added to the proto file in the alpha version, what to do if I want to include the change in beta version? Not clear to me how to update the corresponding alias.gen.go file.

@howardjohn
Copy link
Member Author

LGTM overall

What is not clear to me (might be good to have it doc-ed) is if I need to introduce a new API change (for example, add a field) in a resource, I update the proto file in the alpha version first if it exists (then beta). Assuming I added to the proto file in the alpha version, what to do if I want to include the change in beta version? Not clear to me how to update the corresponding alias.gen.go file.

Today: find the source of truth proto among 3 that look the same, edit it, and run make gen. If you picked the wrong one, your changes are reverted

With this PR: there is only 1 proto per type. Edit it and run make gen.

@istio-testing istio-testing added the needs-rebase Indicates a PR needs to be rebased before being merged label May 16, 2024
@howardjohn howardjohn requested a review from linsun May 16, 2024 21:48
@istio-testing istio-testing removed the needs-rebase Indicates a PR needs to be rebased before being merged label May 16, 2024
@linsun
Copy link
Member

linsun commented May 16, 2024

LGTM overall
What is not clear to me (might be good to have it doc-ed) is if I need to introduce a new API change (for example, add a field) in a resource, I update the proto file in the alpha version first if it exists (then beta). Assuming I added to the proto file in the alpha version, what to do if I want to include the change in beta version? Not clear to me how to update the corresponding alias.gen.go file.

Today: find the source of truth proto among 3 that look the same, edit it, and run make gen. If you picked the wrong one, your changes are reverted

With this PR: there is only 1 proto per type. Edit it and run make gen.

I mean how to indicate this type is only for alpha but not for beta for example?

@howardjohn
Copy link
Member Author

I mean how to indicate this type is only for alpha but not for beta for example?

This is impossible both before and after this change. Before it was impossible because our tests assert you do not do this (and if we didn't, Kubenetes will reject it). Now its impossible because there is only 1 proto

Copy link
Member

@linsun linsun left a comment

Choose a reason for hiding this comment

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

LGTM seems a great simplification!

@ericvn
Copy link
Contributor

ericvn commented May 20, 2024

I know that some of the work I had started earlier tried to update the apiVersion in the various snippets. Is that something we want to do outside of this work, or maybe pull into this PR (but agree it doesn't seem to fit this PR as titled)?

@howardjohn
Copy link
Member Author

I know that some of the work I had started earlier tried to update the apiVersion in the various snippets. Is that something we want to do outside of this work, or maybe pull into this PR (but agree it doesn't seem to fit this PR as titled)?

@whitneygriffith already has a PR doing this, built on top of this PR. This PR makes it easier since there is ~1/3 as many places to update

@ericvn
Copy link
Contributor

ericvn commented May 20, 2024

Just found that PR, #3192. And unfortunately, the other merge caused some conflicts.

@whitneygriffith
Copy link
Contributor

Just found that PR, #3192. And unfortunately, the other merge caused some conflicts.

Once this PR merges, I will rebase #3192

@istio-testing istio-testing merged commit b9c26ac into istio:master May 20, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants