在 helm 模板中使用正则表达式

Tom*_*ich 5 kubernetes-helm

我试图在我的 helm 模板中提供一个条件,以使用regexMatch函数检查有效(或相当无效)的主机名。

这是我正在使用的代码行:

{{- if regexMatch "(?:[0-9]{1,3}\.){3}[0-9]{1,3}$" .Values.hostname }}
Run Code Online (Sandbox Code Playgroud)

值文件中的相关部分很简单:

hostname: 10.10.10.10
Run Code Online (Sandbox Code Playgroud)

但是,我遇到了语法错误,没有真正的解释:
Error: parse error at (api-gateway/templates/ingress.yml:1): invalid syntax

当我尝试使用文档中的示例时: https: //helm.sh/docs/chart_template_guide/function_list/#regexmatch-mustregexmatch 它显然有效,所以我想知道为什么我的代码不起作用。

Tom*_*ich 10

事实证明,我需要使用双反斜杠才能使其工作:

{{- if regexMatch "(?:[0-9]{1,3}\\.){3}[0-9]{1,3}$" .Values.hostname }}
Run Code Online (Sandbox Code Playgroud)