<p>I've a question about helm validation of <code>resources</code> field in <code>CronJob</code> chart , any help welcome.</p>

<p>I use apiVersion batch/v1beta1</p>

<p>I get error when I try to retrive values from values.yaml</p>

<p>The error : <code>Error: error validating "": error validating data: found `invalid field requests for v1.Container</code></p>

<p>Command I run : <code>helm install --dry-run --debug my_chart</code> </p>

<p>my CronJob chart as following:</p>

<pre><code>apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: {{ .Chart.Name }}
spec:
  schedule: "0 */2 * * *"
  concurrencyPolicy: Forbid
  jobTemplate:
    spec:
      template:
        metadata:
     ...
     spec:
  containers:
    ...
     spec:
       resources:
{{ toYaml .Values.resources | indent 12 }}
</code></pre>

<p>Error disapierd when I change the resources configuration to </p>

<pre><code>    resources:
      requests:
        cpu: 300m
        memory: 1024Mi
</code></pre>

<p>I don't like the last change and I'd like to follow my regular configuration guide and store values in values.yaml</p>

<p>cluster version are</p>

<p><code>Client Version: version.Info{Major:"1", Minor:"8", GitVersion:"v1.8.4", GitCommit:"9befc2b8928a9426501d3bf62f72849d5cbcd5a3", GitTreeState:"clean", BuildDate:"2017-11-20T05:28:34Z", GoVersion:"go1.8.3", Compiler:"gc", Platform:"linux/amd64"}</code></p>

<p><code>Server Version: version.Info{Major:"1", Minor:"8+", GitVersion:"v1.8.4-gke.0", GitCommit:"04502ae78d522a3d410de3710e1550cfb16dad4a", GitTreeState:"clean", BuildDate:"2017-11-27T19:19:56Z", GoVersion:"go1.8.3b4", Compiler:"gc", Platform:"linux/amd64"}</code></p>

<p>helm versions are :</p>

<p><code>Client: &amp;version.Version{SemVer:"v2.7.0", GitCommit:"08c1144f5eb3e3b636d9775617287cc26e53dba4", GitTreeState:"clean"}</code></p>

<p><code>Server: &amp;version.Version{SemVer:"v2.7.0", GitCommit:"08c1144f5eb3e3b636d9775617287cc26e53dba4", GitTreeState:"clean"}</code></p>

<p>Thanks in advance</p>

<p><strong>TL;DR</strong>: Indent by 14 spaces (instead of 12) and remove the additional <code>spec</code> property in your container definition.</p>

<hr>

<p>Mind the correct indentation in your YAML definitions. For example, the <code>containers</code> property needs to be a sub-property of the CronJob's <code>spec.jobTemplate.spec.template</code> property (with <code>spec.jobTemplate</code> being the <em>template</em> for a <a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.9/#job-v1-batch" rel="nofollow noreferrer">Job</a> object (or a <a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.9/#jobtemplatespec-v1beta1-batch" rel="nofollow noreferrer">JobTemplate</a>), and <code>spec.jobTemplate.spec.template</code> then being the <em>template</em> for that Job's <a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.9/#pod-v1-core" rel="nofollow noreferrer">Pod</a> object (or a <a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.9/#podtemplate-v1-core" rel="nofollow noreferrer">PodTemplate</a>).</p>

<p>Furthermore, the <a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.9/#podspec-v1-core" rel="nofollow noreferrer">Pod's <code>containers</code> attribute</a> does not require an additional <code>spec</code>. Have a look at the API reference for the respective objects (linked above) for the exact specification of these object types.</p>

<p>For a CronJob, this is how the Helm template should look like (again, indentation is important!). Also, note that in this case, the <code>.spec.jobTemplate.spec.template.spec.resources.requests</code> property needs to be indented by <strong>14 spaces, and not 12</strong>. </p>

<pre><code>apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: {{ .Chart.Name }}
spec:
  schedule: "0 */2 * * *"
  concurrencyPolicy: Forbid
  jobTemplate:
    spec:
      template:
        metadata:
          # ...
        spec:
          containers:
          - name: foo
            # ...
            resources:
{{ toYaml .Values.resources | indent 14 }}
</code></pre>

<hr>

<p>Regarding the error you've received: With an indentation of 12 spaces (<code>indent 12</code>), Helm will create a YAML definition for your job similar to the following:</p>

<pre><code>        spec:
          containers:
          - name: foo
            # ...
            resources:
            requests:
              cpu: 300m
              memory: 1024Mi
</code></pre>

<p>As you can see, the <code>requests</code> property (intended to be a sub-property of the <code>resources</code> property), is now actually a property of the <a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.9/#container-v1-core" rel="nofollow noreferrer">Container</a> definition. However, the Container resource does not have a field called <code>requests</code>, resulting in the error message:</p>

<blockquote>
  <p>Error: error validating "": error validating data: found `invalid field requests for v1.Container</p>
</blockquote>
