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

KEP 1645: add labels and annotations export #4922

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MrFreezeex
Copy link
Member

@MrFreezeex MrFreezeex commented Oct 16, 2024

  • One-line PR description: add labels and annotations export

@k8s-ci-robot
Copy link
Contributor

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

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Oct 16, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: MrFreezeex
Once this PR has been reviewed and has the lgtm label, please assign skitt for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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

@k8s-ci-robot k8s-ci-robot added kind/kep Categorizes KEP tracking issues and PRs modifying the KEP directory sig/multicluster Categorizes an issue or PR as relevant to SIG Multicluster. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 16, 2024
@MrFreezeex MrFreezeex force-pushed the KEP1645-sync-labels-annotations branch 2 times, most recently from 939b732 to 2ae4c68 Compare October 16, 2024 13:16
@MrFreezeex MrFreezeex marked this pull request as ready for review October 16, 2024 13:20
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 16, 2024
@MrFreezeex MrFreezeex force-pushed the KEP1645-sync-labels-annotations branch 2 times, most recently from 6b7282b to a849f28 Compare October 16, 2024 13:27
// +optional
ExportedLabels map[string]string `json:"exportedLabels"`
// +optional
ExportedAnnotations map[string]string `json:"exportedAnnotations"`
Copy link
Contributor

Choose a reason for hiding this comment

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

My understanding of the motivation for this is to provide a way to specify which labels/annotations should be synced/transferred from the exported Service to the derived Service. Therefore, shouldn't these fields specify only the names of the corresponding labels/annotations on the exported Service and the implementation would extract the values from exported Service instance (and also handle subsequent updates to the exported Service's values)?

Copy link
Member Author

@MrFreezeex MrFreezeex Oct 16, 2024

Choose a reason for hiding this comment

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

You mean like that we would have some filters instead of the actual values? If so yes that might be one alternative approach that would work too, let's see what others think!

Copy link
Member

@skitt skitt Oct 16, 2024

Choose a reason for hiding this comment

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

If the ServiceExport stores the values, we need to describe how updates to those values (in the Service) are handled. I don’t think we’d ever want different values on a Service and its ServiceExport, so having only the names of the labels/annotations is sufficient IMO and avoids some complexity.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm maybe it's not clear but what I wrote in the KEP is not supposed to look at the corresponding Service at all, like all the labels/annotations exported would be in the ServiceExport spec a bit like what's done in gateway API (which makes me realize that I haven't posted the link to gateway API doc in the description: https://gateway-api.sigs.k8s.io/geps/gep-1762/#labels-and-annotations)

Copy link
Member Author

@MrFreezeex MrFreezeex Oct 16, 2024

Choose a reason for hiding this comment

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

Although I was originally in favor of not adding any fields to the ServiceExport object at all, but with @mikemorris suggestion in the meeting I was a bit more inclined to do it a bit like GatewayAPI and tried to advocate for the reasons we would like to do that in this PR but a different approach is definitely doable!

Copy link
Contributor

Choose a reason for hiding this comment

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

  • Specify the exact keys and values to copy in the ServiceExport spec.

  • Specify the keys that are copied from the Service instance.

How about a CEL expression that takes a key and returns true or false? It's expensive to evaluate but the set of keys is typically stable so the filter shouldn't be recomputed often.

Potentially two expressions: one for labels, one for annotations

Why is this good?

  • flexible
  • lets you do things like wildcards but with an exception
  • very configurable handling for unrecognized labels / annotations
  • allows for rules like "export either both of these labels or neither of them" or "export label A or B, but never both"
  • extensible (I think) to filtering on values as well

Copy link
Contributor

Choose a reason for hiding this comment

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

AIUI server-side apply lets us go further and decide whether to become a field manager for a particular key, and if so to:

  • take over management
  • jointly manage the key
  • set / update the value but only if there is no other declared manager
  • skip this key and not copy it to the target

A CEL expression could return which of those four options to pick, per label / annotation key.

Copy link
Member Author

@MrFreezeex MrFreezeex Nov 11, 2024

Choose a reason for hiding this comment

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

AIUI server-side apply lets us go further and decide whether to become a field manager for a particular key

I don't think this is a case where server-side apply would be relevant here because this is not a conflict problem within the same cluster between different actors.

The context is that we need to figure out a set of labels/annotations that are getting exported from each "local Services" in a way that would reasonably not result in a "cross-cluster conflict" even if third party tools are used that might add extra labels/annotations (kubectl with the last applied annotation, argocd with the application labels are example of that).

How about a CEL expression that takes a key and returns true or false? It's expensive to evaluate but the set of keys is typically stable so the filter shouldn't be recomputed often.

This is quite an interesting idea to apply CEL here. I see it as a "copy-filter" approach but in a much more flexible way. But it's also way more complex I am not sure if as a user of an MCS-API implementation, I would want to write some CEL expressions to filter my labels/annotations and also probably making sure that this expression would be the same on all similar ServiceExport across clusters...

So IMO this has the same benefits of "copy-filter" approach (for instance a list of prefix) which is consistency with the rest of the API: the source of truth is on the Service itself with more flexibility but also more complex for users in respect to other "copy-filter" solutions.

I am not entirely sure if this is really better than the way this KEP is currently proposing which is trying to skip this copy-filter problem entirely by adding dedicated fields in the spec that won't be touched by third party tooling which may result in a conflict when reconciling those cross clusters.

Copy link
Contributor

Choose a reason for hiding this comment

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

@MrFreezeex I'd like the CEL expression idea to appear in the list of alternatives; it doesn't have to get listed as the winning choice.

What I disagreed with, lightly, was the implication that we had to choose between exactly 2 design options here. Actually there are more.

Copy link
Member Author

@MrFreezeex MrFreezeex Nov 11, 2024

Choose a reason for hiding this comment

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

Well we never considered CEL but AFAICT it's still is fundamentally a "copy-filter" approach which we discussed here and with some points against it in Exporting labels/annotations from the Service/ServiceExport objects. The only thing that might not be relevant for the CEL proposal is the last point about flexibility which is traded by more complexity. Will try to rephrase that last point to include CEL expressions.

@MrFreezeex MrFreezeex force-pushed the KEP1645-sync-labels-annotations branch from a849f28 to 4960c5b Compare October 16, 2024 14:46
@MrFreezeex MrFreezeex force-pushed the KEP1645-sync-labels-annotations branch 5 times, most recently from b33c1eb to 83d1af6 Compare October 18, 2024 11:10
// +optional
ExportedLabels map[string]string `json:"exportedLabels"`
// +optional
ExportedAnnotations map[string]string `json:"exportedAnnotations"`
Copy link
Contributor

Choose a reason for hiding this comment

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

  • Specify the exact keys and values to copy in the ServiceExport spec.

  • Specify the keys that are copied from the Service instance.

How about a CEL expression that takes a key and returns true or false? It's expensive to evaluate but the set of keys is typically stable so the filter shouldn't be recomputed often.

Potentially two expressions: one for labels, one for annotations

Why is this good?

  • flexible
  • lets you do things like wildcards but with an exception
  • very configurable handling for unrecognized labels / annotations
  • allows for rules like "export either both of these labels or neither of them" or "export label A or B, but never both"
  • extensible (I think) to filtering on values as well

// +optional
ExportedLabels map[string]string `json:"exportedLabels"`
// +optional
ExportedAnnotations map[string]string `json:"exportedAnnotations"`
Copy link
Contributor

Choose a reason for hiding this comment

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

AIUI server-side apply lets us go further and decide whether to become a field manager for a particular key, and if so to:

  • take over management
  • jointly manage the key
  • set / update the value but only if there is no other declared manager
  • skip this key and not copy it to the target

A CEL expression could return which of those four options to pick, per label / annotation key.

Signed-off-by: Arthur Outhenin-Chalandre <arthur@cri.epita.fr>
@MrFreezeex MrFreezeex force-pushed the KEP1645-sync-labels-annotations branch from 83d1af6 to 271740f Compare November 12, 2024 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/kep Categorizes KEP tracking issues and PRs modifying the KEP directory sig/multicluster Categorizes an issue or PR as relevant to SIG Multicluster. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants