英文:
How can evaluate field in range?
问题
我正在尝试为许多类似的应用程序创建一个默认模板,我需要在两个或多个 pod 之间共享相同的 PVC,并且需要修改图表以创建或不创建 PVC(如果已存在)。
这是我在 values.yml 中关于卷的部分:
persistence:
enabled: true
volumeMounts:
- name: vol1
mountPath: /opt/vol1
- name: vol2
mountPath: /opt/vol2
volumes:
- name: vol1
create: true
claimName: claim-vol1
storageClassName: gp2
accessModes: ReadWriteOnce
storage: 1Gi
- name: vol2
create: false
claimName: claim-vol2
storageClassName: gp2
accessModes: ReadWriteOnce
storage: 1Gi
这是我的 pvclaim.yml:
{{- if .Values.persistence.enabled }}
{{- if .Values.volumes.create }}
{{- range .Values.volumes }}
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {{ .claimName }}
spec:
storageClassName: {{ .storageClassName }}
accessModes:
- {{ .accessModes }}
resources:
requests:
storage: {{ .storage }}
{{- end }}
{{- end }}
{{- end }}
我想在 volumes
的范围内添加 create
字段来管理 PVC 的创建(假设在此示例中,PVC vol2
已经存在于其他 Helm Chart 中)。
如果可能的话,我希望 Helm 能够读取范围内的 create
字段,这样我就不会得到错误信息:evaluate field create in type interface {}
。
如果你有其他想法,欢迎分享,谢谢!
英文:
I trying to create a default template for many similar applications, I need share same PVC with two or more pod and need modify the chart for create ot not PVC, if already exists.
This is my portion of values.yml about volumes:
persistence:
enabled: true
volumeMounts:
- name: vol1
mountPath: /opt/vol1
- name: vol2
mountPath: /opt/vol2
volumes:
- name: vol1
create: true
claimName: claim-vol1
storageClassName: gp2
accessModes: ReadWriteOnce
storage: 1Gi
- name: vol2
create: false
claimName: claim-vol2
storageClassName: gp2
accessModes: ReadWriteOnce
storage: 1Gi
And this is my pvclaim.yml:
{{- if .Values.persistence.enabled }}
{{- if .Values.volumes.create }}
{{- range .Values.volumes }}
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {{ .claimName }}
spec:
storageClassName: {{ .storageClassName }}
accessModes:
- {{ .accessModes }}
resources:
requests:
storage: {{ .storage }}
{{- end }}
{{- end }}
{{- end }}
I thought I'd add the field create
into range of volumes
to manage creations of PVC (assuming in this example that PVC vol2
already exists from other helm chart).
If it were possible I would like helm to read the create
field inside the range, this way I get an error:
evaluate field create in type interface {}
If you have any other ideas they are welcome, thanks!
答案1
得分: 1
volumes
是一个数组,它没有create
字段。
volumes
的元素才有该字段。因此,.Values.volumes.create
没有任何意义。在range
内,您可以使用.create
来检查元素的create
字段,例如:
{{- range .Values.volumes }}
{{if .create}}在这里执行某些操作{{end}}
{{- end}}
英文:
volumes
is an array, it does not have a create
field.
Elements of volumes have that field. So .Values.volumes.create
does not make any sense. Inside the range
you may check the create
field of the element using .create
, e.g.
{{- range .Values.volumes }}
{{if .create}}do something here{{end}}
{{- end}}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论