の設定ミスがあると分散配置されないため、 マニフェスト更新のプルリクエスト作成時に バリデーションを実⾏する • Rego ⾔語でルールを記述し、OPA/Conftest を 使⽤して Label の設定チェックを実⾏ package main deny[msg] { target_kind := ["Deployment", "StatefulSet", "Rollout"] input[i].contents.kind == target_kind[_] target := input[i].contents is_replicated(target) not match_topology_spread_constraints_selector(target) msg := sprintfPod is("Pods owned by %v ¥"%v¥" must be distributed to dif ferent nodes or availability zones with topologySpreadConstraints. Configure topologySpreadConstraints field to ensure that at least node-level failures do not impact availability. If a single Pod is enough, simply set replicas t o 1 so that this rule will be passed.", [target.kind, target.metadata.name]) } # Multiple is_replicated functions are processed as OR conditions. # ref. https://www.openpolicyagent.org/docs/latest/policy-language/#incremen tal-definitions is_replicated(target) { target.spec.replicas > 1 } # If replicas field is not present, it is assumed that the number of Pods # is replicated and controlled by HPA. is_replicated(target) { not target.spec.replicas } match_topology_spread_constraints_selector(target) { labels := target.spec.template.metadata.labels constraint := target.spec.template.spec.topologySpreadConstraints[i] object.subset(labels, constraint.labelSelector.matchLabels) } +,-./012 3435678 !