oc.exe命令提示符中的OpenShift GoLang模板解析错误:if中发生意外的未关闭操作

问题描述 投票:0回答:2

请找到以下我用来从openshift容器中获取正在运行的pod的脚本

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

go openshift command-prompt go-templates openshift-3
2个回答
0
投票

您稍后必须使用大写字母您无法访问小写字母的字段。

    {{range .items}}
              {{if .Status.Phase "Running"}}
                   {{.Metadata.Name}}
                   {{.Status.Phase}}
               {{end}}

    {{end}}

0
投票

我认为您的命令有多个问题,一个是您需要在range .items之间放置一个空格,而主要的问题是您没有将模板放在引号中。这导致模板被读取为{{range.items}}{{if,这将导致上述错误。

要解决此问题,请将您的模板放在引号中,但也请注意在命令中也转义所有其他引号:

oc get pods -o template --template "{{range .items}} {{if eq .status.phase \"Running\"}} {{.metadata.name}} {{.status.phase}} {{\"\\n\"}} {{end}} {{end}}"
© www.soinside.com 2019 - 2024. All rights reserved.