2.6.4.2.4. lookup function
lookup
功能将 Kubernetes 资源作为 JSON 兼容映射返回。请注意,如果请求的资源不存在,则会返回一个空映射。查看该功能的以下语法:
func lookup (apiversion string, kind string, namespace string, name string) (value string, err Error)
使用功能时,输入 Kubernetes 资源的 API 版本、类型、命名空间和名称。查看在目标受管集群上强制执行 Kubernetes 资源的配置策略示例。metrics-url
数据键的值是一个模板,它从 default
命名空间中获取 v1/Service
Kubernetes metrics
资源,并设置为查询的资源中的 Spec.ClusterIP
的值:
apiVersion: policy.open-cluster-management.io/v1 kind: ConfigurationPolicy metadata: name: demo-lookup namespace: test-templates spec: namespaceSelector: exclude: - kube-* include: - default object-templates: - complianceType: musthave objectDefinition: kind: ConfigMap apiVersion: v1 metadata: name: demo-app-config namespace: test data: # Configuration values can be set as key-value properties app-name: sampleApp app-description: "this is a sample app" metrics-url: | http://{{ (lookup "v1" "Service" "default" "metrics").spec.clusterIP }}:8080 remediationAction: enforce severity: low