gpt4 book ai didi

Terraform helm chart 设置值容差

转载 作者:行者123 更新时间:2023-12-05 01:53:18 27 4
gpt4 key购买 nike

我正在尝试使用 terraform 将容差值传递到 helm 中。但是我收到了不同的错误消息。

chart are here 的默认值.

...
tolerations:
[]
...

我使用这个代码。

locals {
victoria_tolerations = [{ "key" : "k8s-app", "operator" : "Equal", "value" : "grafana", "effect" : "NoSchedule" }]
}


resource "helm_release" "victoria_metrics" {
name = var.vm_release_name
chart = var.vm_chart
repository = var.vm_chart_repository_url
version = var.vm_chart_version
namespace = local.namespace_victoria
max_history = var.max_history

set {
name = "vmselect.tolerations"
value = jsonencode(local.victoria_tolerations)
}
}

得到错误信息:

Error: failed parsing key "vmselect.tolerations" with value [{"effect":"NoSchedule","key":"k8s-app","operator":"Equal","value":"grafana"}], key "\"key\":\"k8s-app\"" has no value (cannot end with ,)

如果我使用这个变量

victoria_tolerations = <<EOF
- key: k8s-app
operator: Equal
value: grafana
effect: NoSchedule
EOF

我遇到了这个错误:

Error: unable to build kubernetes objects from release manifest: error validating "": error validating data: ValidationError(Deployment.spec.template.spec.tolerations): invalid type for io.k8s.api.core.v1.PodSpec.tolerations: got "string", expected "array"

附言此外,我尝试以 values 的形式传递。这在这种情况下不起作用。

locals {
victoria_values = {
"tolerations" : [
{
"key" : "k8s-app",
"operator" : "Equal",
"value" : "grafana",
"effect" : "NoSchedule"
}
]
}
}
resource "helm_release" "victoria_metrics" {
name = var.vm_release_name
...
values = [
yamlencode(local.victoria_values)
]
}

最佳答案

尝试动态 block

dynamic "toleration" {
for_each = var.tolerations
content {
key = toleration.value["key"]
operator = toleration.value["operator"]
value = toleration.value["value"]
effect = toleration.value["effect"]
}
}

var 文件

variable "tolerations" {
type = list(map(string))
default = []
description = "Tolerations to apply to deployment"
}

参数

tolerations = [
{
key = "node.kubernetes.io/role",
operator = "Equal",
value = "true",
effect = "NoSchedule"
}
]

关于Terraform helm chart 设置值容差,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71126527/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com