<p>I've some YAML files which I wanted to apply to create Custom Resources. But before applying it I want to change the spec and ENVs of the YAML snippet. So what could be the best way to do this?</p>
<p>What I'm doing now is:</p>
<p>Let suppose this is the YAML</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: litmuschaos.io/v1alpha1
kind: ChaosEngine
metadata:
  name: nginx-chaos
  namespace: default
spec:
  appinfo:
    appns: 'default'
    applabel: 'app=nginx'
    appkind: 'deployment'
  # It can be true/false
  annotationCheck: 'false'
  # It can be active/stop
  engineState: 'active'
  chaosServiceAccount: pod-delete-sa
  monitoring: false
  # It can be delete/retain
  jobCleanUpPolicy: 'delete'
  experiments:
    - name: pod-delete
      spec:
        components:
          env:
            # set chaos duration (in sec) as desired
            - name: TOTAL_CHAOS_DURATION
              value: '30'

            # set chaos interval (in sec) as desired
            - name: CHAOS_INTERVAL
              value: '10'
              
            # pod failures without '--force' &amp; default terminationGracePeriodSeconds
            - name: FORCE
              value: 'false'
</code></pre>
<ol>
<li>I Download this file from the raw link. (1 function for this)</li>
<li>Replace a field like <code>jobCleanUpPolicy: 'delete'</code> to <code>jobCleanUpPolicy: 'retain'</code> (1 fn)</li>
<li>Replace the next line when a match is found like <code>value: 'false'</code> to <code>value: 'true'</code> for FORCE ENV. (1 fn)</li>
<li>Applying the final manifest created! (1 function)</li>
</ol>
<p>Can this be optimized?</p>

UDIT GAURAV
<p>If you create a struct representing the resource (or, even better, can import the package which defines the CRD) you could take the yaml string, <a href="https://pkg.go.dev/gopkg.in/yaml.v2#Marshaler" rel="nofollow noreferrer">marshal</a> it into the struct and then edit the fields directly as fields of a struct instead</p>
