Skip to content

Default values in OpenAPI, patternProperties are not properly handled #371

@piotrminkina

Description

@piotrminkina

Expected behavior (what you expected to happen):
The configuration is validated correctly. The default values for the fields in the object defined as patternProperties should be in the file pointed to by the VALUES_PATH variable.

Actual behavior (what actually happened):
The configuration is validated correctly. The default values for the fields in the object defined as patternProperties are not available in the file pointed to by the VALUES_PATH variable.

Steps to reproduce:

  1. Create ConfigMap with the following content:
    apiVersion: v1
    kind: ConfigMap
    metadata:
      # ...
    data:
      global: |
        parent: {}
  2. Create a file /global-hooks/openapi/config-values.yaml with the following content:
    type: object
    additionalProperties: false
    patternProperties:
      ^parent$:
        type: object
        required:
          - child
        properties:
          child:
            type: object
            default: {} # Deleting this field causes the global configuration to be invalid, as expected,
  3. Create a executable hook file /global-hooks/check-if-child-object-exists.bash with the following content:
    #!/usr/bin/env bash
    
    declare VALUES_PATH
    declare BINDING_CONTEXT_PATH
    
    if [[ "${1:-}" == "--config" ]]; then
        cat <<EOF
        {
            "configVersion": "v1",
            "beforeAll": 1
        }
    EOF
        exit 0
    fi
    
    declare binding="$(jq -r '.[0].binding' "${BINDING_CONTEXT_PATH}")"
    
    if [[ "${binding}" == 'beforeAll' ]]; then
        jq '.global.parent | if .child != null then "Child Object exists! " + (.child | tostring) else "Child Object does NOT exist!" end' < "${VALUES_PATH}"
    fi
  4. You should see the msg="\"Child Object exists! {}\"" message in the console log, but you will see msg="\"Child Object does NOT exist!\"".

Environment:

  • Addon-operator version: v1.1.2
  • Helm version: v3.10.3+g835b733
  • Kubernetes version: v1.23.6+k3s1
  • Installation type (kubectl apply, helm chart, etc.): Own Helm Chart

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions