<p>How do I have to specify the comments like <code>+kubebuilder:printcolumn</code> to add columns to the output of the command <code>kubectl get my-crd.my-group.my-domain.com</code>?</p>
<p>I've a CRD (Custom Resource Definition) with the usual <code>struct</code>s for the specs and the status (similar to what's explained in the Kubebuilder tutorial here <a href="https://book.kubebuilder.io/cronjob-tutorial/new-api.html#adding-a-new-api" rel="nofollow noreferrer">https://book.kubebuilder.io/cronjob-tutorial/new-api.html#adding-a-new-api</a>).</p>
<p>I've a <strong>Status</strong> <code>struct</code> like this:</p>
<pre class="lang-golang prettyprint-override"><code>type ScheduleSetStatus struct {
    // When was the last time the Schedule Set
    // was successfully deployed.
    LastDeployTime string `json:&quot;lastDeployTime&quot;` // metav1.Time
    // The CronJobs that have been successfully deployed
    DeployedCronJobs []string `json:&quot;deployedCronJobs&quot;`
    // The CronJobs that had errors when the deployment
    // has been attempted.
    ErroredCronJobs map[string]string `json:&quot;erroredCronJobs&quot;` // TODO `error` JSON serialisable
}
</code></pre>
<p>Which has a few problems:</p>
<p><strong>The time field</strong></p>
<ul>
<li>I've tried that to be of type <code>metav1.Time</code> (handy formatting as they state at <a href="https://book.kubebuilder.io/cronjob-tutorial/api-design.html?highlight=metav1.Time#designing-an-api" rel="nofollow noreferrer">https://book.kubebuilder.io/cronjob-tutorial/api-design.html?highlight=metav1.Time#designing-an-api</a>), but then this comment <code>// +kubebuilder:printcolumn:name=&quot;Last Deploy&quot;,type=&quot;date&quot;,JSONPath=</code>.status.lastDeployTime`` shows as empty in the output of <code>kubectl</code>.</li>
<li>So I changed the type to be <code>string</code> (then in the controller doing <code>oess.Status.LastDeployTime = fmt.Sprintf(&quot;%s&quot;, metav1.Time{Time: time.Now().UTC()})</code>), then adding the comment <code>+kubebuilder:printcolumn:name=&quot;Last Deploy&quot;,type=string,JSONPath=</code>.status.lastDeployTime`` but still the field is shown as empty in the output of <code>kubectl</code>.</li>
</ul>
<p><strong>The slice field <code>[]string</code> and the map field <code>map[string]string</code></strong></p>
<ul>
<li>How do I configure these? Here there's no mention (when clicking on &quot;Show Detailed Argument Help&quot;): <a href="https://book.kubebuilder.io/reference/markers/crd.html" rel="nofollow noreferrer">https://book.kubebuilder.io/reference/markers/crd.html</a></li>
<li>In case these are not &quot;simple types&quot; with formatting issues when using <code>kubectl</code>, does that mean the only option I have is to make them <code>string</code> with some sort of <code>fmt.Sprintf(...)</code>?</li>
<li>Any other option?</li>
</ul>

<p>The solution was to add the code to update the resource status in
the <strong>reconciler method</strong> of the controller - <code>Reconcile(ctx context.Context, req ctrl.Request)</code>, like this:</p>
<pre class="lang-golang prettyprint-override"><code>    // Update the status for &quot;last deploy time&quot; of a ScheduleSet
    myStruct.Status.LastDeployTime = metav1.Time{Time: time.Now().UTC()} // https://book.kubebuilder.io/cronjob-tutorial/api-design.html?highlight=metav1.Time#designing-an-api
    if err := r.Status().Update(ctx, &amp;myStruct); err != nil {
        log.Error(err, &quot;unable to update status xyz&quot;)
        return ctrl.Result{}, err
    }
</code></pre>
<p>The special Kubebuilder annotation was all right:</p>
<pre class="lang-golang prettyprint-override"><code>//+kubebuilder:printcolumn:name=&quot;Last Deploy&quot;,type=&quot;date&quot;,JSONPath=`.status.lastDeployTime`
</code></pre>
<p>Also, Go slices and Go maps work out of the box with comments like:</p>
<pre class="lang-golang prettyprint-override"><code>...

    DeployedCronJobs []string `json:&quot;deployedCronJobs&quot;`

...

    ErroredCronJobs map[string]string `json:&quot;erroredCronJobs&quot;`
...

//+kubebuilder:printcolumn:name=&quot;Deployed CJs&quot;,type=string,JSONPath=`.status.deployedCronJobs`
//+kubebuilder:printcolumn:name=&quot;Errored CJs&quot;,type=string,JSONPath=`.status.erroredCronJobs`
</code></pre>
