我的YAML模板有缩进问题。
我不明白为什么limits没有达到正确的缩进水平。
有人知道吗?
spec:
template:
spec:
containers:
- name: argocd-notifications-controller
resources:
requests:
cpu: {% if argocd_total_applications > argocd.totalApplications.level4 -%} "{{ argocd.notificationController.cpu.requests.level4 }}"
{% elif argocd_total_applications > argocd.totalApplications.level3 and argocd_total_applications <= argocd.totalApplications.level4 -%} "{{ argocd.notificationController.cpu.requests.level3 }}"
{% elif argocd_total_applications > argocd.totalApplications.level2 and argocd_total_applications <= argocd.totalApplications.level3 -%} "{{ argocd.notificationController.cpu.requests.level2 }}"
{% elif argocd_total_applications <= argocd.totalApplications.level1 -%} "{{ argocd.notificationController.cpu.requests.level1 }}" {% endif -%}
memory: {% if argocd_total_applications > argocd.totalApplications.level4 -%} "{{ argocd.notificationController.memory.requests.level4 }}"
{% elif argocd_total_applications > argocd.totalApplications.level3 and argocd_total_applications <= argocd.totalApplications.level4 -%} "{{ argocd.notificationController.memory.requests.level3 }}"
{% elif argocd_total_applications > argocd.totalApplications.level2 and argocd_total_applications <= argocd.totalApplications.level3 -%} "{{ argocd.notificationController.memory.requests.level2 }}"
{% elif argocd_total_applications <= argocd.totalApplications.level1 -%}"{{ argocd.notificationController.memory.requests.level1 }}"{% endif -%}
limits:
memory: {% if argocd_total_applications > argocd.totalApplications.level4 -%} "{{ argocd.notificationController.memory.limits.level4 }}"
{% elif argocd_total_applications > argocd.totalApplications.level3 and argocd_total_applications <= argocd.totalApplications.level4 -%} "{{ argocd.notificationController.memory.limits.level3 }}"
{% elif argocd_total_applications > argocd.totalApplications.level2 and argocd_total_applications <= argocd.totalApplications.level3 -%} "{{ argocd.notificationController.memory.limits.level2 }}"
{% elif argocd_total_applications <= argocd.totalApplications.level1 -%} "{{ argocd.notificationController.memory.limits.level1 }}"
{% endif -%}结果:
spec:
template:
spec:
containers:
- name: argocd-notifications-controller
resources:
requests:
cpu: "150m"
memory: "500Mi"
limits: ################# PROBLEM HERE WRONG LOCATION
memory: "750Mi" 发布于 2022-10-17 12:23:24
下面是您的问题的一个最小的可重复的例子:
resources:
requests:
cpu: {% if true -%} "150m"
{% elif true -%} "" {% endif -%}
memory: {% if true -%} "500Mi"
{% elif true -%} "" {% endif -%}
limits:
memory: {% if true -%} "750Mi"
{% elif true -%} "" {% endif -%}实际上,它使下列情况成为:
resources:
requests:
cpu: "150m"
memory: "500Mi"
limits:
memory: "750Mi" 这些不正确的缩进发生的原因是,在使用白空间控制删除所有endif的空格之后。
删除空白控件--或者更好地修复它们,以便它们删除正确的空白--您将生成预期的YAML:
resources:
requests:
cpu: {% if true -%} "150m"
{%- elif true -%} "" {%- endif %}
memory: {% if true -%} "500Mi"
{%- elif true -%} "" {%- endif %}
limits:
memory: {% if true -%} "750Mi"
{%- elif true -%} "" {%- endif %}将呈现为
resources:
requests:
cpu: "150m"
memory: "500Mi"
limits:
memory: "750Mi"https://stackoverflow.com/questions/74096645
复制相似问题