goopenshiftcommand-promptgo-templatesopenshift-3

OpenShift GoLang Template parsing error in oc.exe command prompt: Unexpected unclosed action in if


Please find the below script which I have used to fetch the running pods from openshift container

oc get pods -o template --template {{range.items}}{{if eq .status.phase "Running"}}{{.metadata.name}}{{.status.phase}}{{end}}{{end}}

Script ran and error shown in the below image


Solution

  • I think you have multiple issues with your command, one being that you need to put a space between range .items and the main issue being that you did not put your template in quotes. This results in the template being read as {{range.items}}{{if, which will lead to the error above.

    To fix this, put your template in quotes, but take care to escape all other quotes in your command as well:

    oc get pods -o template --template "{{range .items}} {{if eq .status.phase \"Running\"}} {{.metadata.name}} {{.status.phase}} {{\"\\n\"}} {{end}} {{end}}"