<p>I am trying my hands on creating my own kubernetes operator by following this <a href="https://sdk.operatorframework.io/docs/building-operators/golang/tutorial/" rel="nofollow noreferrer">link</a>. In the Reconcile function, I need to create multiple Deployments and each will vary in some attributes (like name for e.g.) and the configuration is huge. Instead of creating the deployment by using appsv1.Deployment and creating each attributes within it (like below code), is there a way wherein I can provide a yaml template file and read this file to obtain the appsv1.Deployment object?</p>
<pre><code>    dep := &amp;appsv1.Deployment{
        ObjectMeta: metav1.ObjectMeta{
            Name:      customName,
            Namespace: m.Namespace,
        },
        Spec: appsv1.DeploymentSpec{
            Strategy: appsv1.DeploymentStrategy{
                Type: &quot;RollingUpdate&quot;,
            },
        ... and so on
</code></pre>
<p>Instead of above, can something like below possible with some handy util functions?</p>
<pre><code>dep := utils.parseYaml(deploymentYamlFile)
</code></pre>

Vishal
<p>Yes, you can have your <code>Deployment</code> in a yaml file and read it in code.</p>
<p>Given this file structure:</p>
<pre><code>example.go
manifests/deployment.yaml
</code></pre>
<p>You would have something like this in <code>example.go</code>:</p>
<pre class="lang-golang prettyprint-override"><code>import (
    &quot;io/ioutil&quot;

    appsv1 &quot;k8s.io/api/apps/v1&quot;
    &quot;sigs.k8s.io/yaml&quot;
)

func example() {
    var bs []byte
    {
        bs, err = ioutil.ReadFile(&quot;manifests/deployment.yaml&quot;)
        if err != nil {
            // handle err
        }
    }

    var deployment appsv1.Deployment
    err = yaml.Unmarshal(bs, &amp;deployment)
    if err != nil {
        // handle err
    }

    // now you have your deployment load into `deployment` var
}
</code></pre>
