-
Notifications
You must be signed in to change notification settings - Fork 428
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
Spec of API machinery's Quantity is wrong (incomplete) #328
Comments
/assign |
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
/remove-lifecycle stale |
huh? The code in k8s.io/apimachinery says otherwise: https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/apimachinery/pkg/api/resource/quantity.go#L393 |
Isn't https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/apimachinery/pkg/api/resource/quantity.go#L646 the relevant line? Quotes are optional. The OpenAPI spec you link to is incomplete (OpenAPI v2 ...). |
Interesting... was that intended? Generally our OpenAPI is less restrictive that what we accept (i.e. we validate more than what our OpenAPI says), but in this case the OpenAPI is more restrictive that what we accept. |
Technically, neither is right (it should be |
IMO the v2 spec is just wrong. A published spec should never be too restrictive. It may be incomplete server side validation will do the final check anyway. I agree, we could add a regex to specify |
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
@sttts and @DirectXMan12, isn't it true that a quantity can be float (i.e. 1.2 not "1.2")? If that's the case, then isn't a stringOrInt is too restrictive? |
I think when you specify a decimal, it needs to be in quotes, otherwise other systems will parse it as a float, voiding the entire purpose of resource.Quantity. @sttts thoughts? |
You can specify decimal without quotes. The following valid: apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deploy
spec:
template:
spec:
containers:
- name: nginx
image: nginx:latest
resources:
requests:
cpu: 0.5
... The normalized version of In our CRD, when generating the OpenAPI validation spec for a field which is of properties:
limits:
additionalProperties:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
type: object
requests:
additionalProperties:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
type: object Which does not allow decimals. To work around this, we currently have to surgically remove the |
Technically float is allowed by quantities. The problem here is that CRDs don't do the conversion of 0.5 to |
Yeah, I'm aware that it's incorrect, but I wanted to check to see what the story was here, because, as noted by @sttts, since CRDs don't get normalized, you're gonna read back
or We probably need to drop the int-or-string designation here, but I'm not really certain how to proceed -- if we can't say "intorstring", the quantity declaration becomes non-structural (i.e. according to kubernetes CRD rules we're not allowed to say "int or string or float"). it should currently accept |
@jessesuen I'm curious as to what your desired behavior would be here -- non-structural means no server-side defaulting, etc, which seems like a big trade-off for accepting unquoted floats. |
(no intention of sounding passive-agressive here -- I'm just curious about your usecase) |
@jessesuen and I are maintainors of a project called Argo Rollouts, and it has a CRD called a Rollout that replaces the Deployment object with other deployment strategies like blue-green or canary. For a user to start using a Rollout, they only need to change the apiVersion and kind and add a new deployment strategy. If a user has a float value for their container's limits or requests, then the validation rejects their rollout. To work around this, we removed the validation for the request and limit fields so we can have the same feature parity as the Deployment object. |
Stale issues rot after 30d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
@sttts is there any way here then for us to have a valid structural deployment object embedded in a CRD? It kinda seems like the answer is "no". |
No, nobody tried to solve the type reference problem in schemas. |
Ah, slightly different question: the schema for anything containing resource.Quantity is non-structural, correct? |
If you use |
yeah, so you can't represent what vanilla kubernetes accepts as a structural OpenAPI schema, since kubernetes accepts floats |
Rotten issues close after 30d of inactivity. Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
@fejta-bot: Closing this issue. In response to this:
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. |
/reopen |
@jessesuen: You can't reopen an issue/PR unless you authored it or you are a collaborator. In response to this:
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. |
controller-tools/pkg/crd/known_types.go
Line 58 in 538d4b2
x-kubernetes-int-or-string
. That would make the spec more complete than today.The text was updated successfully, but these errors were encountered: