亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何修復 helm _helpers.tpl 中的“無法評估類型接口 {} 中的字段”

如何修復 helm _helpers.tpl 中的“無法評估類型接口 {} 中的字段”

Go
當年話下 2023-07-10 15:01:54
我試圖從舵中的傘圖中獲取一些值_helpers.tpl,但由于某種原因我收到了錯誤executing "gluu.ldaplist" at <.Values.ldap.extraHo...>: can't evaluate field extraHosts in type interface {}這就是我正在努力做的事情。 _helpers.ptl{{- define "gluu.ldaplist" -}}{{- $hosts := .Values.ldap.extraHosts -}}{{- $genLdap := dict "host" (printf "%s-%s" .Release.Name .Values.ldapType) "port" .Values.ldapPort -}}{{- $hosts := prepend $hosts $genLdap -}}{{- $local := dict "first" true -}}{{- range $k, $v := $hosts -}}{{- if not $local.first -}},{{- end -}}{{- printf "%s:%.f" $v.host $v.port -}}{{- $_ := set $local "first" false -}}{{- end -}}{{- end -}}這是values.yml傘圖的 一部分values.ymlldap:  enabled: true  type: opendj  extraHosts: [    host: opendj,    port: 3434  ] #array of k,v e.g host: host1, port: port1目錄結構helm/  charts/     chart_a/       templates/          configMap.yml ----->>> this is where I want to use it  templates/     _helpers.tpl ---->>>> where the failing function is  requirements.yml  values.yml ---------->>> where the ldap values are看起來configMap.yml像下面這樣apiVersion: v1kind: ConfigMapmetadata:  name: {{ template "oxauth.fullname" . }}-cmdata:  GLUU_CONFIG_ADAPTER: {{ .Values.global.configAdapterName | quote }}  GLUU_LDAP_URL: {{ template "gluu.ldaplist" . }}注意:_helpers.tpl位于主/傘圖下方。chart_a是一個子圖。預期結果類似于GLUU_LDAP_URL:"opendj:3434"頭盔版本:Client: &version.Version{SemVer:"v2.10.0", GitCommit:"9ad53aac42165a5fadc6c87be0dea6b115f93090", GitTreeState:"clean"}Server: &version.Version{SemVer:"v2.10.0", GitCommit:"9ad53aac42165a5fadc6c87be0dea6b115f93090", GitTreeState:"clean"}預期結果是,即使數組中未提供任何值,函數{{- define "gluu.ldaplist" -}}也會順利完成。_helpers.tpl如果提供了值,則預期的字符串將host:port作為輸出。如果可以以其他方式完成此操作,我歡迎任何建議。
查看完整描述

1 回答

?
繁花不似錦

TA貢獻1851條經驗 獲得超4個贊

這可以通過全局值來解決,全局值允許父圖表中的值覆蓋(或提供未指定的)子子圖表中的值。

來自關于子圖和全局值的 Helm 文檔:

  1. 子圖被視為“獨立”,這意味著子圖永遠不能顯式依賴于其父圖。

  2. 因此,子圖無法訪問其父圖的值。

  3. 父圖表可以覆蓋子圖表的值。

  4. Helm 有一個全局值的概念,所有圖表都可以訪問它。

(起初我并沒有想到要搜索“helm subchart”,但當我在互聯網上搜索該術語時,這是第一個或第二個結果)

這是解決您的問題的最小示例:

目錄結構

helm

├── Chart.yaml

├── charts

│? ?└── chart_a

│? ? ? ?├── Chart.yaml

│? ? ? ?└── templates

│? ? ? ? ? ?└── configMap.yml

├── templates

│? ?└── _helpers.tpl

└── values.yaml

注意:我添加了Chart.yaml文件以使其實際工作,重命名values.yml為values.yaml,以便它默認工作而無需額外的標志,并刪除requirements.yml,因為沒有必要重現問題和解決方案。


values.yaml

global:

? ldap:

? ? enabled: true

? ? type: opendj

? ? extraHosts:

? ? - host: opendj

? ? ? port: 3434

? ldapType: xxx

? ldapPort: 123

關鍵是將你擁有的東西嵌套在一個特殊的global鍵下。請注意,我還添加了ldapType和 ,ldapPort因為它們在您的 中_helpers.tpl,并且我修復了您在 下的 YAML 結構extraHosts。host之前的內容實際上并不代表帶有和鍵的地圖列表port。如果沒有此修復,該helm命令不會失敗,但也不會輸出您想要的內容。


結果

$ helm template .

---

# Source: helm/charts/chart_a/templates/configMap.yml

apiVersion: v1

kind: ConfigMap

metadata:

? name: cm

data:

? GLUU_LDAP_URL: release-name-xxx:123,opendj:3434


查看完整回答
反對 回復 2023-07-10
  • 1 回答
  • 0 關注
  • 196 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號