Conditional block in manifest

Hello,

I have a config field for CPU limit, and I want to include the CPU limit in my Deployment manifest only if the field has a value. I tried the following in the deployment manifest since I read in the documentation that the full Go templating library is supported:

    resources:
      requests:
        cpu: 50m
        memory: 500Mi
      {{ if repl ConfigOption "cpu_limit" }}
      limits:
          cpu: repl {{ ConfigOption "cpu_limit" }}
          #memory: 500Mi
      {{ end}}

But I get the following error at lint:

$ replicated release lint --app "gitguardian-seal" --yaml-dir manifests
RULE            TYPE     FILENAME                         LINE    MESSAGE
invalid-yaml    error    manifests/app-deployment.yaml    133     yaml: line 133: could not find expected ':'    
Error: One or more errors of severity "error" or higher were found

I believe that using something like repl if only really works if you use it for the value of a key, not an entire block of a manifest. There is an example of using this here.

While maybe not the ideal solution, you could instead have two manifests, one with the limits and one without. Then use the kots.io/when label annotation (example here ) to only deploy the one based on the config option.

Hello, this is unfortunate since we need to disable some manifest mapping depending on the configuration, on all our deployments. This force us to duplicate hundreds of lines.

Hi @chbrosso - your alternative option is to package your app as a Helm Chart, in which case you get to use full plain-text templating. About Packaging with Helm | Replicated Docs

Yes that’s what we want to do but existing customers can’t be easily migrated to Helm.

Hi @chbrosso - can you help me understand that a little better? What is making that difficult for you? If there is a manual workaround involved, what steps would you use and how long do you expect it to take per customer?

As another option, have you considered exposing the options to your customers via the kustomize.io guide: Patching with Kustomize | Replicated Docs