<p>Using the following code:</p>

<pre class="lang-golang prettyprint-override"><code>func GetPods(clientset *kubernetes.Clientset, name, namespace string) ([]corev1.Pod, error) {
    list, err := clientset.CoreV1().Pods(namespace).List(metav1.ListOptions{
        LabelSelector: fmt.Sprintf("app=%s", name),
    })
    if err != nil {
        return nil, err
    }
return list.Items, nil
}
</code></pre>

<p>And then dump the results into yaml using <code>gopkg.in/yaml.v2</code>, and here's the yaml clause that describes container resource:</p>

<pre><code>resources:
  limits:
    cpu:
      format: DecimalSI
    memory:
      format: BinarySI
  requests:
    cpu:
      format: DecimalSI
    memory:
      format: BinarySI
</code></pre>

<p>Which includes none of the actual resource amount that I'm actually interested in, which should look like this using <code>kubectl get pod xxx -o yaml</code>:</p>

<pre><code>resources:
  limits:
    cpu: "4"
    memory: 8Gi
  requests:
    cpu: 200m
    memory: 100Mi
</code></pre>

<p>So how can I properly get the pod spec yaml, that includes all the resource info, using the golang library? What did I do wrong in the above process?</p>

<h2>Update</h2>

<p>I noticed the <a href="https://godoc.org/k8s.io/api/core/v1#PodSpec.String" rel="nofollow noreferrer"><code>Pod.String</code></a> and <a href="https://godoc.org/k8s.io/api/core/v1#PodSpec.Marshal" rel="nofollow noreferrer"><code>Pod.Marshal</code></a> methods.</p>

<p>The <code>pod.String()</code> output seems to be a formatted string of the <code>core.v1.Pod</code> instance, this isn't much use to me since it's not serialized.</p>

<p><code>Pod.Marshal()</code> gives a byte array, contains lots of gibberish when printed. The method itself is one of those undocumented methods inside <code>k8s.io/api/core/v1/generated.pb.go</code>, I really don't know what to do with its output:</p>

<pre class="lang-golang prettyprint-override"><code>func (p *PodResolver) SpecYaml() (string, error) {
    bs, err := p.pod.Marshal()
    fmt.Println(string(bs))
    return string(bs), err
}
// prints a whole lot of gibberish like cpu\x12\x03\n\x014\n\x0f\n\x06memory\x12\x05\n\x038Gi\x12\r\n\x03cpu\x12\x06\n\x04200m\x12\x11\n\x06memory\x12\a\n\x05100MiJ-\n\n
</code></pre>

timfeirg
<p>You can simply call the String() method on the quantity fields which would return something like "100m"</p>

<p>There doesnt seem to be any yaml tags on the <code>Quantity</code> type.</p>
