2

我想检查命名空间中是否存在注释,如果不拒绝。我有这个代码,但不工作。如何获得正确的对象路径 (namespace.annotation) 进行比较?

  violation[{"msg": msg, "details": {}}] {
        input.request.kind.kind == "Namespace"
        not input.review.object.metadata.annotations.hostPath
        msg := sprintf("no hostpath defined in namespace for this pod %v, [input.review.object.metadata.name])
    }

我在我的约束中指定了 pod 和命名空间,因为我需要在我的模板中检查两者的规则

spec:
  match:
    kinds:
      - apiGroups: [""]
        kinds: ["Pod"]
      - apiGroups: [""]
        kinds: ["Namespace"]

谢谢 !

4

1 回答 1

1

从看门人库存储库中查看这个几乎相同的示例。
我认为具体问题在于您提取注释本身的方式(请注意,当您使用点表示法时,该示例使用方括号)。

于 2020-09-19T19:06:36.380 回答