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

Policy merging discrepancy between Kubernetes and Universal with defaults #6070

Open
michaelbeaumont opened this issue Feb 20, 2023 · 7 comments
Labels
kind/bug A bug triage/accepted The issue was reviewed and is complete enough to start working on it

Comments

@michaelbeaumont
Copy link
Contributor

What happened?

We use the kubebuilder:default annotation to generate an OpenAPI spec describing our resources. When we create our CRDs with these OpenAPI specs, Kubernetes then sets the value of omitted fields to the default. On Universal, we don't do the same, this part of the spec serves only as documentation

This means:

  • Merging won't work as intended. Given a kubebuilder:default=30s for interval:
---
targetRef:
kind: Mesh
to:
  - default:
      interval: 100s
      timeout: 200s
---
targetRef:
  kind: MeshService
  name: backend
to:
  - default:
      timeout: 300s

on Universal we get {interval: 100s, timeout: 300s} but on Kubernetes we get {interval: 30s, timeout: 300s} because the API server sets interval: 30s on the second resource.

  • when writing policy implementations, we have to duplicate the default everywhere we use the fields for the universal case, even though on Kubernetes they'll always be set
@michaelbeaumont michaelbeaumont added triage/pending This issue will be looked at on the next triage meeting kind/bug A bug labels Feb 20, 2023
@jakubdyszkiewicz jakubdyszkiewicz added triage/accepted The issue was reviewed and is complete enough to start working on it and removed triage/pending This issue will be looked at on the next triage meeting labels Feb 20, 2023
@github-actions github-actions bot added the triage/stale Inactive for some time. It will be triaged again label May 22, 2023
@github-actions
Copy link
Contributor

This issue was inactive for 90 days. It will be reviewed in the next triage meeting and might be closed.
If you think this issue is still relevant, please comment on it or attend the next triage meeting.

@michaelbeaumont michaelbeaumont removed the triage/stale Inactive for some time. It will be triaged again label May 30, 2023
@github-actions github-actions bot added the triage/stale Inactive for some time. It will be triaged again label Aug 29, 2023
@github-actions
Copy link
Contributor

This issue was inactive for 90 days. It will be reviewed in the next triage meeting and might be closed.
If you think this issue is still relevant, please comment on it or attend the next triage meeting.

@lukidzi lukidzi removed the triage/stale Inactive for some time. It will be triaged again label Sep 11, 2023
@michaelbeaumont michaelbeaumont changed the title Policy merging discrepancy between Kubernetes and Universal Policy merging discrepancy between Kubernetes and Universal with defaults Dec 4, 2023
Copy link
Contributor

github-actions bot commented Mar 4, 2024

This issue was inactive for 90 days. It will be reviewed in the next triage meeting and might be closed.
If you think this issue is still relevant, please comment on it or attend the next triage meeting.

@github-actions github-actions bot added the triage/stale Inactive for some time. It will be triaged again label Mar 4, 2024
@jakubdyszkiewicz jakubdyszkiewicz removed the triage/stale Inactive for some time. It will be triaged again label Mar 4, 2024
@github-actions github-actions bot added the triage/stale Inactive for some time. It will be triaged again label Jun 3, 2024
Copy link
Contributor

github-actions bot commented Jun 3, 2024

This issue was inactive for 90 days. It will be reviewed in the next triage meeting and might be closed.
If you think this issue is still relevant, please comment on it or attend the next triage meeting.

@michaelbeaumont michaelbeaumont removed the triage/stale Inactive for some time. It will be triaged again label Jun 3, 2024
@github-actions github-actions bot added the triage/stale Inactive for some time. It will be triaged again label Sep 2, 2024
Copy link
Contributor

github-actions bot commented Sep 2, 2024

This issue was inactive for 90 days. It will be reviewed in the next triage meeting and might be closed.
If you think this issue is still relevant, please comment on it or attend the next triage meeting.

@michaelbeaumont michaelbeaumont removed the triage/stale Inactive for some time. It will be triaged again label Sep 2, 2024
@lahabana lahabana added triage/pending This issue will be looked at on the next triage meeting and removed triage/accepted The issue was reviewed and is complete enough to start working on it labels Sep 19, 2024
@jakubdyszkiewicz jakubdyszkiewicz added triage/accepted The issue was reviewed and is complete enough to start working on it and removed triage/pending This issue will be looked at on the next triage meeting labels Sep 23, 2024
@lahabana
Copy link
Contributor

lahabana commented Sep 25, 2024

Looking at the code we have a Defaulter interface that does this fairly well:

if defaulter, ok := resource.(model.Defaulter); ok {
if err := defaulter.Default(); err != nil {
return err
}
}
if err := model.Validate(resource); err != nil {
return err
}

We should likely make it work in a similar way as Validate in the generator (if there's a validate method do something) we could then auto generate the defaulter that use kubebuilder annotations.

If we are to do this and always rely on kubebuilder annotations for defaults we should remove this:

if defaulter, ok := resource.(core_model.Defaulter); ok {
if err := defaulter.Default(); err != nil {
return admission.Errored(http.StatusInternalServerError, err)
}
}
and fix MeshService and Mesh which are the 2 existing implems of Defaulter

The other alternative is to disallow the use of kubebuilder:default but this is unfortunate as this generates nice API specs (.e.g: this annotation generates this openAPI spec).

This also seems to be in the openAPI spec, can't we just use openAPI magic to have the defaults ensured? A bit like we do in:

validator := validate.NewSchemaValidator(desc.Schema, nil, "", strfmt.Default)

@michaelbeaumont
Copy link
Contributor Author

This also seems to be in the openAPI spec, can't we just use openAPI magic to have the defaults ensured? A bit like we do in:

yeah this was the original plan I had in mind at least

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug A bug triage/accepted The issue was reviewed and is complete enough to start working on it
Projects
None yet
Development

No branches or pull requests

4 participants