kubernetes: Validation type error when creating / updating CRDs that use scale subresource

What happened:

When a CRD that uses the scale subresource is created or updated using server-side apply an unexpected error occurs:

The WishIHadChosenNoxu "test" is invalid: .spec.cReplicas: Invalid value: 0: .spec.cReplicas accessor error: 3 is of the type float64, expected int64

What you expected to happen:

No error and CRD instance created or updated.

How to reproduce it (as minimally and precisely as possible):

Given a file crddef.yaml:

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: noxus.mygroup.example.com
spec:
  scope: Cluster
  names:
    plural: noxus
    singular: nonenglishnoxu
    kind: WishIHadChosenNoxu
  group: mygroup.example.com
  versions:
    - name: v1
      served: true
      storage: true
      schema:
        openAPIV3Schema:
          type: object
          properties:
            spec:
              type: object
              properties:
                cReplicas:
                  type: integer
      subresources:
        scale:
          specReplicasPath: .spec.cReplicas
          statusReplicasPath: .status.cReplicas

and a filecrd.yaml

apiVersion: mygroup.example.com/v1
kind: WishIHadChosenNoxu
metadata:
  name: test
spec:
  cReplicas: 3

Run the following:

$ kubectl apply -f crddef.yaml
$ kubectl apply --server-side -f crd.yaml

Anything else we need to know?:

The error is the same as the one reported for this other issue which reported the error when using default values for the replicas field. I have tested it, and it seems that default values work using server-side apply as well.

The error comes from the validation of the scale subresource here.

Environment:

  • Kubernetes version (use kubectl version):
Client Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.2", GitCommit:"f5743093fd1c663cb0cbc89748f730662345d44d", GitTreeState:"clean", BuildDate:"2020-09-16T21:51:49Z", GoVersion:"go1.15.2", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.1", GitCommit:"206bcadf021e76c27513500ca24182692aabd17e", GitTreeState:"clean", BuildDate:"2020-09-14T07:30:52Z", GoVersion:"go1.15", Compiler:"gc", Platform:"linux/amd64"}

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 17 (17 by maintainers)

Most upvoted comments

The JSON parser does by default, and probably the yaml-to-json one inherits that.

Use of something like https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/apimachinery/pkg/util/json/json.go#L43 is required to make JSON integers turn into int64 fields in memory.