kubernetes - 在我的 Helm 模板中,为什么 pluck 评估为 float64?
问题描述
作为我帖子Helm 函数的后续问题,基于变量设置值?,并根据 Helm 图表中的变量值修改动态访问值中给出的答案,我正在尝试这个
$ helm version --short
v3.5.2+g167aac7
values.yaml
-----------
env: sandbox
environments:
sandbox: 0
staging: 1
production: 2
replicaCount:
- 1
- 2
- 4
templates/deployments.yaml
--------------------------
apiVersion: apps/v1
kind: Deployment
metadata:
...
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ index .Values.replicaCount (pluck .Values.env .Values.environments | first | default .Values.environments.sandbox) }}
但我明白了
$ helm template . --dry-run
Error: template: guestbook/templates/deployment.yaml:10:15: executing "guestbook/templates/deployment.yaml" at <index .Values.replicaCount (pluck .Values.env .Values.environments | first | default .Values.environments.sandbox)>: error calling index: cannot index slice/array with type float64
为什么pluck
返回 afloat64
而不是整数,因为我的environments
字典值是整数,所以我期望它?
解决方案
如果我这样做,即pluck
使用int
转换器进行管道传输,它可以工作,但它没有解释为什么pluck
返回一个float64
值。
templates/deployments.yaml
--------------------------
apiVersion: apps/v1
kind: Deployment
metadata:
...
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ index .Values.replicaCount ((pluck .Values.env .Values.environments | first | default .Values.environments.sandbox) | int) }}
更新:事实证明这是一个已知的错误。见https://github.com/kubernetes-sigs/yaml/issues/45
推荐阅读
- jmeter - 在 JMeter 中,随着被测用户数量的增加,预计样本数量会增加一倍还是显着增加?
- html - 自述文件图像未显示在 repo 主页上
- r - 在R中的数据框中求和重复的列
- android - Jetpack compose 中的 [NestedScrollView + RecyclerView] 或 [Nested RecyclerView (Recycler inside another recycler) 相当于什么
- reactjs - 如何通过 id 或 value 从另一个组件中的一个组件获取元素?
- python-3.x - Python (stdout) readline 错误:从控制台应用程序读取时丢失/重复字符
- gradle - 只有带有自定义任务的 jar 中包含的 Java 文件
- python - 如何了解段落颜色docx python?
- javascript - 我需要帮助从
带有javascript的元素
- java - Java Swing GUI JLabel不显示