2.6.4.2.10. toBool function
toBool 函数将输入字符串转换为布尔值,并返回布尔值。另外,如果这是模板中的最后一个功能,也会进一步处理源内容。这是为了确保该值被 YAML 解释为布尔值。查看该功能的以下语法:
func toBool (input string) (output bool)
使用函数时,输入需要转换为布尔值的字符串数据。查看以下使用 toBool 函数的配置策略示例:
apiVersion: policy.open-cluster-management.io/v1
kind: ConfigurationPolicy
metadata:
name: demo-template-function
namespace: test
spec:
namespaceSelector:
exclude:
- kube-*
include:
- default
object-templates:
- complianceType: musthave
objectDefinition:
...
spec:
enabled: |
{{ (fromConfigMap "site-config" "site1" "enabled") | toBool }}