Skip to content

Conversation

@aaron-prindle
Copy link
Contributor

One-line PR description: This addresses how we intend to handle referencing fields for cross-field validations with Declarative Validation.

Issue link: #5073

@k8s-ci-robot k8s-ci-robot added 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/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. labels Jun 3, 2025
@k8s-ci-robot k8s-ci-robot requested review from jpbetz and sttts June 3, 2025 07:41
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jun 3, 2025
@aaron-prindle aaron-prindle force-pushed the kep-5073-update-cross-field-field-references branch from 29293ad to d635349 Compare June 3, 2025 07:42
@aaron-prindle
Copy link
Contributor Author

/assign @deads2k @jpbetz @thockin
/cc @yongruilin


```go
type Config struct {
// +k8s:reference(name: minValue)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we switch examples?

How about we use the union example for virtual fields, and we use the min/max example for field paths?

I think this better highlights our best practices.

If we ever do need min/max to support references we can add that, but it feels more natural to use the simple sibling reference approach for the common case.

Copy link
Contributor Author

@aaron-prindle aaron-prindle Jun 3, 2025

Choose a reason for hiding this comment

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

I have changed this example to be as suggested. The field path section uses a min/max example currently so I believe we are good there. The initial idea was to show how to use all the tags in the virtual field but I agree it is better to show the best practice/practical cases.


Limits LimitConfig

// +k8s:subfield(resources)=+k8s:subfield(cpu)=+k8s:maximum(constraint: maxCpu)
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh interesting. Here, maxCpu references the MaxCpu field of Config using a field path? This implies that the field path is relative to the Config and not SettingsConfig, which was not immediately obvious to me because this tag is injected into the SettingsConfig type with subfield.

Copy link
Contributor Author

@aaron-prindle aaron-prindle Jun 3, 2025

Choose a reason for hiding this comment

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

This is based off the below section in the original DD:

Field Path Resolution & Chained Tags
Explicit Path Context: Field paths always resolve from the original tag location

// 'minValue' always refers to Config.MinValue, not Nested siblings
type Config struct {
  MinValue int
  // +k8s:subfield(nestedCurrent)=+k8s:minimum(limit: minValue)
  Nested Nested
}

type Nested struct {
  NestedCurrent int
}

In thinking through the implications of this though, it is not feasible with the current implementation of subfield. This would be a potential case to use +k8s:reference. I will remove this tag examples for now as I don't believe there are actually any subfield cases on shared objects that have cross-field validation with the parent object

@aaron-prindle aaron-prindle force-pushed the kep-5073-update-cross-field-field-references branch from 6703f2f to ee52f7e Compare June 3, 2025 17:24
Copy link
Contributor

@deads2k deads2k left a comment

Choose a reason for hiding this comment

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

questions

type Config struct {
// +k8s:listType=map
// +k8s:listMapKey=type
// +k8s:union(union: terminalStatus)
Copy link
Contributor

Choose a reason for hiding this comment

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

Need to update the above table for +k8s:union(...).
Actually, I'm unclear about the union tag usage here. Is it only used for declaring the group?

Copy link
Contributor Author

@aaron-prindle aaron-prindle Jun 3, 2025

Choose a reason for hiding this comment

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

The KEP differs from the tags in the dev-branch which need to be updated to be in line with this KEP Update. In the dev branch there is +k8s:unionMember which has implicit virtual fields for the groups. For +k8s:unionMember that tag is essentially +k8s:union and +k8s:memberOf in a single tag. This KEP Update decouples these concepts to have a generic way of grouping fields via virtual fields and then having +k8s:union consume the virtual field grouping.

+k8s:union in this case is the only tag in this example that validates exclusivity for each member in the group terminalStatus. +k8s:memberOf generically groups the values

@deads2k
Copy link
Contributor

deads2k commented Jun 3, 2025

@aaron-prindle
Copy link
Contributor Author

aaron-prindle commented Jun 3, 2025

this is in addition to https://github.com/kubernetes/enhancements/pull/5290/files?diff=split&w=0#diff-ee5e894a755c55c5e78fa01f4d06cfc09d7ea1868f3c6ee1e905da474fe00352R1048, right?

Yes, there will be a separate KEP update to address the tags/approach to immutability

EDIT: This is submitted and out for review now: https://github.com/kubernetes/enhancements/pull/5373/files

@deads2k deads2k added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Jun 5, 2025
@aaron-prindle aaron-prindle force-pushed the kep-5073-update-cross-field-field-references branch from a11b170 to a8589d7 Compare June 5, 2025 21:57
@deads2k
Copy link
Contributor

deads2k commented Jun 5, 2025

lgtm. I see Joe has a review on this too

/assign @jpbetz

@jpbetz
Copy link
Contributor

jpbetz commented Jun 6, 2025

/lgtm
/approve

This sets up a solid set of core principals to build on. Thanks!

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 6, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: aaron-prindle, jpbetz

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 6, 2025
@k8s-ci-robot k8s-ci-robot merged commit b4738e0 into kubernetes:master Jun 6, 2025
4 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.34 milestone Jun 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. 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 lgtm "Looks good to me", indicates that a PR is ready to be merged. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants