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

format=duration kubebuilder validation accepts d, w; metav1.Duration does not #56

Closed
2uasimojo opened this issue Feb 10, 2022 · 6 comments
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.

Comments

@2uasimojo
Copy link

2uasimojo commented Feb 10, 2022

Despite validation of type=duration being documented as parsed by time.ParseDuration, which is what the unmarshaller does, it is actually parsed by strfmt.ParseDuration, which is more lenient in that it accepts d (days) and w (weeks).

The result is that the round trip is broken: go type => CRD => CR with d or w => apiserver validation (accepts d/w) => etcd => GET => unmarshal (blows up on d/w) => go type.

Example of such a CRD struct field definition.

And a BZ that uncovered the problem.

cf. kubernetes/apimachinery#131


Unfortunately, any solution that makes format=duration validation stricter could break backward compatibility for use cases that don't ultimately use go's time.ParseDuration.

A possibility would be adding a separate validator (format=strictduration?) that does strictly use time.ParseDuration as advertised. Long term, perhaps it would be appropriate to clone format=duration to format=scaladuration and eventually deprecate/remove the former.


Workaround (suggested by @JoelSpeed): Ditch format=duration and use an explicit regex instead. That would be a pity :(

2uasimojo added a commit to 2uasimojo/hive that referenced this issue Feb 10, 2022
Due to a difference in how apiserver validates `Format=duration` vs how
apimachinery unmarshals `metav1.Duration`, using that format can allow
users to blow up some of our controllers if they provide certain values
for Duration fields (specifically: containing `d` or `w` units).
Upstream issues have been opened against both sides of this discrepancy:
- kubernetes/apimachinery#131
- kubernetes/apiextensions-apiserver#56

In the meantime, work around the problem by using an explicit regex
instead of the built in format validator.

Closes 2050332
2uasimojo added a commit to 2uasimojo/hive that referenced this issue Feb 15, 2022
Due to a difference in how apiserver validates `Format=duration` vs how
apimachinery unmarshals `metav1.Duration`, using that format can allow
users to blow up some of our controllers if they provide certain values
for Duration fields (specifically: containing `d` or `w` units).
Upstream issues have been opened against both sides of this discrepancy:
- kubernetes/apimachinery#131
- kubernetes/apiextensions-apiserver#56

In the meantime, work around the problem by using an explicit regex
instead of the built in format validator.

(cherry picked from commit 665b268)

Conflicts:
	apis/hive/v1/clusterpool_types.go
	config/crds/hive.openshift.io_clusterpools.yaml
	hack/app-sre/saas-template.yaml
	vendor/github.com/openshift/hive/apis/hive/v1/clusterpool_types.go

These were due to the ResumeTimeout field added to ClusterPool since
2.4.

HIVE-1760
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label May 11, 2022
@JoelSpeed
Copy link
Contributor

/remove-lifecycle stale

@k8s-ci-robot k8s-ci-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label May 11, 2022
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Aug 9, 2022
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Sep 8, 2022
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

@k8s-ci-robot
Copy link
Contributor

@k8s-triage-robot: Closing this issue, marking it as "Not Planned".

In response to this:

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 8, 2022
slintes added a commit to slintes/self-node-remediation that referenced this issue Jun 11, 2024
- fix optional vs required
- fix docs
- fix duration validation

For the validation see suggested workaround in
kubernetes/apiextensions-apiserver#56

Signed-off-by: Marc Sluiter <[email protected]>
slintes added a commit to slintes/self-node-remediation that referenced this issue Jun 11, 2024
- fix optional vs required
- fix docs
- fix duration validation

For the validation see suggested workaround in
kubernetes/apiextensions-apiserver#56

Signed-off-by: Marc Sluiter <[email protected]>
slintes added a commit to slintes/self-node-remediation that referenced this issue Jun 11, 2024
- fix optional vs required
- fix docs
- fix duration validation

For the validation see suggested workaround in
kubernetes/apiextensions-apiserver#56

Signed-off-by: Marc Sluiter <[email protected]>
slintes added a commit to slintes/self-node-remediation that referenced this issue Jun 13, 2024
- fix optional vs required
- fix docs
- fix duration validation

For the validation see suggested workaround in
kubernetes/apiextensions-apiserver#56

Signed-off-by: Marc Sluiter <[email protected]>
slintes added a commit to slintes/self-node-remediation that referenced this issue Jun 18, 2024
- fix optional vs required
- fix docs
- fix duration validation

For the validation see suggested workaround in
kubernetes/apiextensions-apiserver#56

Signed-off-by: Marc Sluiter <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.
Projects
None yet
Development

No branches or pull requests

4 participants