Dynamic key/value input properties to CRD in Kubernetes

Viewed 1092

While defining a K8 CRD, I need a flexibility to pass any key/value pairs as input while submitting a resource object. https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/

schema:
        openAPIV3Schema:
          type: object
          properties:
            spec:
              type: object
              properties:
                cronSpec:
                  type: string
                image:
                  type: string
                replicas:
                  type: integer

From the link above, if you see properties can only hold cronSpec, image and/or replicas. Can it be free-form? Meaning I can pass any key/value pairs and in my code I get a collection (may be a map) that can contain key/value pairs.

https://stackoverflow.com/users/14044/mike-bryant I tried with this CRD:

schema:
    openAPIV3Schema:
      type: object
      properties:
        apiVersion:
          type: string
        spec:
          type: object
          properties:
            appProperties:
              type: object
              properties:
                messages:
                  type: array
                  items:
                    type: object
                    properties:
                      key:
                        type: string
                      value:
                        type: string

with custom object having input like this:

messages:
      - key: "server1"
        value: "ping failed"
      - key: "server2"
        value: "abort"
      - key: "server3"
        value: "succes"

but when I patch the crd with some update status, k8 fails with below error:

kind=Status, message=the server rejected our request due to an error in our request, metadata=ListMeta(_continue=null, remainingItemCount=null, resourceVersion=null, selfLink=null, additionalProperties={}), reason=Invalid, status=Failure, additionalProperties={}).:
1 Answers
Related