华为云UCS-k8srequiredannotations:策略实例示例

时间:2025-02-12 15:05:17

策略实例示例

以下策略实例展示了策略定义生效的资源类型,parameters中指定了提示信息message以及annotations的约束定义。

apiVersion: constraints.gatekeeper.sh/v1beta1kind: K8sRequiredAnnotationsmetadata:  name: all-must-have-certain-set-of-annotationsspec:  match:    kinds:      - apiGroups: [""]        kinds: ["Service"]  parameters:    message: "All services must have a `a8r.io/owner` and `a8r.io/runbook` annotations."    annotations:      - key: a8r.io/owner        # Matches email address or github user        allowedRegex: ^([A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}|[a-z]{1,39})$      - key: a8r.io/runbook        # Matches urls including or not http/https        allowedRegex: ^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$
support.huaweicloud.com/usermanual-ucs/ucs_01_0233.html