<p>I have a Custom Resource Definition which has nested fields with default values (some boilerplate omitted for brevity):</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
spec:
  scope: Namespaced
  group: thismatters.stackoverflow
  names:
    kind: BadDefault
  versions:
  - name: v1alpha
    schema:
      openAPIV3Schema:
        type: object
        properties:
          spec:
            type: object
            properties:
              regularThing:
                type: integer
                default: 6
              shouldDefault:
                type: object
                properties:
                  nestedThing:
                    type: integer
                    default: 12
</code></pre>
<p>Whenever I create a resource of this kind without specifying the <code>shouldDefault</code> object:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: thismatters.stackoverflow/v1alpha
kind: BadDefault
metadata:
  name: blank-demo
spec: 
  regularThing: 7
</code></pre>
<p>The default value for <code>.shouldDefault.nestedThing</code> doesn't appear when the resource is <code>describe</code>d:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: thismatters.stackoverflow/v1alpha
kind: BadDefault
metadata:
  name: blank-demo
spec: 
  regularThing: 7
</code></pre>
<p>If I update the resource with this manifest:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: thismatters.stackoverflow/v1alpha
kind: BadDefault
metadata:
  name: blank-demo
spec: 
  regularThing: 7
  shouldDefault: {}
</code></pre>
<p>Then the nested field default value is populated when <code>describe</code>d:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: thismatters.stackoverflow/v1alpha
kind: BadDefault
metadata:
  name: blank-demo
spec: 
  regularThing: 7
  shouldDefault:
    nestedThing: 12
</code></pre>
<p>Is there anything I can do in the CRD to remove the need for the <code>shouldDefault: {}</code> line in the resource manifest and have the default values populate in the nested fields?</p>
<p>My cluster is on Kubernetes version 1.19.</p>

<p>Adding a <code>default</code> property to the <code>shouldDefault</code> object fixes this:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
spec:
  scope: Namespaced
  group: thismatters.stackoverflow
  names:
    kind: BadDefault
  versions:
  - name: v1alpha
    schema:
      openAPIV3Schema:
        type: object
        properties:
          spec:
            type: object
            properties:
              regularThing:
                type: integer
                default: 6
              shouldDefault:
                type: object
                default: {}   #  &lt;-- this was added
                properties:
                  nestedThing:
                    type: integer
                    default: 12
</code></pre>
