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

kubectl explain template fails when array includes boolean value #1590

Closed
ardaguclu opened this issue Apr 24, 2024 · 7 comments · Fixed by kubernetes/kubernetes#124506
Closed
Assignees
Labels
kind/bug Categorizes issue or PR as related to a bug. priority/backlog Higher priority than priority/awaiting-more-evidence. triage/accepted Indicates an issue or PR is ready to be actively worked on.

Comments

@ardaguclu
Copy link
Member

What happened:

apply the example CRD and running kubectl explain fails with;

CRD
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: mock-resources.test.tectonic.com
spec:
  group: test.tectonic.com
  scope: Namespaced
  names:
    plural: mock-resources
    singular: mock-resource
    kind: MockResource
    listKind: MockResources
  versions:
    - name: v1
      storage: true
      served: true
      schema:
        openAPIV3Schema:
          type: object
          properties:
            status:
              type: object
              properties:
                statuses:
                  type: object
                  properties:
                    status1:
                      type: string
                    status2:
                      type: string
                podStatuses:
                  type: object
                  additionalProperties:
                    type: array
                    items:
                      type: string
                otherStatuses:
                  type: object
                  additionalProperties:
                    type: array
                    items:
                      type: string
                customConditions:
                  type: array
                  items:
                    type: object
                    properties:
                      lastTransitionTime:
                        type: string
                      lastUpdateTime:
                        type: string
                      message:
                        type: string
                      reason:
                        type: string
                      status:
                        type: string
                      type:
                        type: string
                otherCustomConditions:
                  type: array
                  items:
                    type: object
                    properties:
                      lastTransitionTime:
                        type: string
                      lastUpdateTime:
                        type: string
                      message:
                        type: string
                      reason:
                        type: string
                      status:
                        type: string
                      type:
                        type: string
              additionalProperties: true
            spec:
              type: object
              required:
                - password
                - select
              properties:
                password:
                  type: string
                  minLength: 1
                  maxLength: 25
                  pattern: "^[a-zA-Z0-9._\\-%]*$"
                number:
                  type: integer
                  minimum: 2
                  maximum: 4
                select:
                  type: string
                fieldGroup:
                  type: object
                  description: "[SCHEMA] field group - Quis cupidatat in sint occaecat quis dolore irure ea minim sint aliquip nisi aliquip."
                  title: "[SCHEMA] Field Group"
                  properties:
                    itemOne:
                      type: string
                    itemTwo:
                      type: integer
                arrayFieldGroup:
                  type: array
                  title: "[SCHEMA] Array Field Group"
                  description: "[SCHEMA] array field group - Quis excepteur nostrud qui sunt reprehenderit reprehenderit deserunt eu aute laboris id aliqua."
                  items:
                    type: object
                    properties:
                      itemOne:
                        type: string
                      itemTwo:
                        type: integer
                hiddenFieldGroup:
                  type: object
                  properties:
                    hiddenItem:
                      type: object
                podCount:
                  type: integer
                endpointList:
                  type: array
                  items:
                    type: object
                    additionalProperties: true
                resourceRequirements:
                  type: object
                  additionalProperties: true
                k8sResourcePrefix:
                  type: string
                booleanSwitch:
                  type: boolean
                checkbox:
                  type: boolean
                imagePullPolicy:
                  type: string
                updateStrategy:
                  type: object
                  additionalProperties: true
                text:
                  type: string
                nodeAffinity:
                  type: object
                  additionalProperties: true
                podAffinity:
                  type: object
                  additionalProperties: true
                podAntiAffinity:
                  type: object
                  additionalProperties: true
                advanced:
                  type: string
                fieldDependencyControl:
                  type: boolean
                fieldDependency:
                  type: string
                nestedFieldDependency:
                  type: object
                  properties:
                    enabled:
                      type: boolean
                    settings:
                      type: object
                      properties:
                        enabled:
                          type: boolean
                arrayFieldDependency:
                  type: array
                  items:
                    type: object
                    properties:
                      enabled:
                        type: boolean
                      dependent:
                        type: string
                hidden:
                  type: string
                objectWithArray:
                  type: object
                  properties:
                    name:
                      type: string
                    tags:
                      type: array
                      items:
                        type: string
                    birthday:
                      type: object
                      properties:
                        month:
                          type: number
                        day:
                          type: number
                        year:
                          type: number
                arrayWithObject:
                  type: array
                  items:
                    type: object
                    properties:
                      organization:
                        type: object
                        properties:
                          name:
                            type: string
                          address:
                            type: object
                            properties:
                              street:
                                type: string
                              city:
                                type: string
                              state:
                                type: string
                      current:
                        type: boolean
                      resourceRequirements:
                        type: object
                        properties: {}
                deeplyNested:
                  type: object
                  properties:
                    foo:
                      type: object
                      properties:
                        bar:
                          type: object
                          properties:
                            baz:
                              type: object
                              properties:
                                bat:
                                  type: object
                                  additionalProperties: true
GROUP:      test.tectonic.com
KIND:       MockResource
VERSION:    v1

error: template: plaintext:39:13: executing "plaintext" at <include "schema" (dict "gvk" $gvk "Document" $.Document "FieldPath" $.FieldPath "Recursive" $.Recursive)>: error calling include: template: plaintext:63:21: executing "schema" at <include "output" (set $ "schema" .)>: error calling include: template: plaintext:101:17: executing "output" at <include "fieldList" (dict "schema" $resolved "level" 1 "Document" $.Document "Recursive" $.Recursive)>: error calling include: template: plaintext:257:15: executing "typeGuess" at <.items>: can't evaluate field items in type bool

What you expected to happen:

kubectl explain properly renders the CRD to template

How to reproduce it (as minimally and precisely as possible):
Apply CRD and run kubectl explain

Anything else we need to know?:

Environment:

  • Kubernetes client and server versions (use kubectl version): 1.28, 1.29, 1.30
  • Cloud provider or hardware configuration:
  • OS (e.g: cat /etc/os-release):
@ardaguclu ardaguclu added the kind/bug Categorizes issue or PR as related to a bug. label Apr 24, 2024
@k8s-ci-robot k8s-ci-robot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Apr 24, 2024
@ardaguclu
Copy link
Member Author

I verified that CRD is successfully applied to API server.

/triage accepted
/priority backlog

@alexzielenski @ah8ad3 do you have any insights about how to troubleshoot this?. I spent some time on it but couldn't sort out. Thanks.

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. priority/backlog Higher priority than priority/awaiting-more-evidence. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Apr 24, 2024
@ah8ad3
Copy link
Member

ah8ad3 commented Apr 24, 2024

Thanks for raising this issue Arda. Tested it with some CRD's few months ago and it worked fine, i will take a look at this.
I will add my finding and troubleshoot after i can reproduce it.

@alexzielenski
Copy link
Contributor

alexzielenski commented Apr 24, 2024

I haven’t dug too deeply into it my guess would be that the problem is your schema uses ‘additionalProperties: true’ while the template assumes it is always a schema in a few places:

{{- if $resolved.additionalProperties}}{{- template "fieldList" (set $nextContext "schema" $resolved.additionalProperties)}}{{end}}

the template should be changed to handle/ignore bool case

@ah8ad3
Copy link
Member

ah8ad3 commented Apr 24, 2024

@ardaguclu After some debugging i find out if you remove line 77 of schema. It would work fine.

@ah8ad3
Copy link
Member

ah8ad3 commented Apr 24, 2024

Thanks @alexzielenski, code wants to iterate over true value of additionalProperties. I can fix that if you want.

@alexzielenski
Copy link
Contributor

That’d be helpful, thanks @ah8ad3 !

/assign @ah8ad3

@ardaguclu
Copy link
Member Author

Thanks a lot for taking care of this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug. priority/backlog Higher priority than priority/awaiting-more-evidence. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants