<p>In a custom Kubernetes operator implemented with the operator-sdk in golang is it possible to call the custom API directly and retrieve the object as YAML?</p>

<p>For example. I have a custom resource</p>

<pre><code>apiVersion: test.com/v1alpha1
kind: TEST
metadata::
  name: example-test
spec:
  replicas: 3
  randomname: value
</code></pre>

<p>I don't know ahead of time what the fields in the spec are going to be apart from replicas. So I am not able to create a go type that includes structs to hold the entries.</p>

<p>So rather than doing:</p>

<pre><code>instance := &amp;testv1alpha1.Test{}
err := r.client.Get(context.TODO(), nameSpaceName, instance)
</code></pre>

<p>I want to be able to do something like:</p>

<pre><code>instanceYAML := genericContainer{}
err := r.client.GetGeneric(context.TODO(), nameSpaceName, instance)
</code></pre>

<p>and then parse the instanceYAML to check the entries.</p>

Kerry Gunn
<p>This is called the "unstructured" client. The docs are pretty light so I recommend looking over the tests as examples <a href="https://github.com/kubernetes-sigs/controller-runtime/blob/ea32729106c995d9df310ac4731c2061490addfb/pkg/client/client_test.go#L1536-L1566" rel="nofollow noreferrer">https://github.com/kubernetes-sigs/controller-runtime/blob/ea32729106c995d9df310ac4731c2061490addfb/pkg/client/client_test.go#L1536-L1566</a></p>
