kyverno 如何处理生成资源的清理

发布于 2025-01-11 11:40:52 字数 1185 浏览 0 评论 0原文

假设我在 kyverno 集群策略中有一条规则来生成 configmap。现在,在将来的某个时间点,我会从集群策略中删除该规则(集群策略仍然存在)。 kyverno 能够对 configmap 进行垃圾收集吗?

具有两个生成规则(r1 和 r2)的集群策略:

apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
  name: cp1
spec:
  rules:
  - name: r1
    match:
      resources:
        kinds:
        - Namespace
        selector:
          matchLabels:
            test: "true"
    generate:
      synchronize: true
      kind: ConfigMap
      name: cm1
      namespace: "{{request.object.metadata.name}}"
      data:
        kind: ConfigMap
        data:
          # Enter all your target logging info below
          test.yml: |-
            cm1
  - name: r2
    match:
      resources:
        kinds:
        - Namespace
        selector:
          matchLabels:
            test: "true"
    generate:
      synchronize: true
      kind: ConfigMap
      name: cm2
      namespace: "{{request.object.metadata.name}}"
      data:
        kind: ConfigMap
        data:
          # Enter all your target logging info below
          test.yml: |-
            cm2

一旦应用,如果您删除生成规则之一并再次应用策略,它不会删除配置映射。

Let's say I have a rule in kyverno cluster policy to generate configmap. Now at some point of time in future I remove that rule from cluster policy(cluster policy still exists). Is kyverno capable of garbage collecting the configmap?

Cluster Policy with two generate rules(r1 and r2):

apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
  name: cp1
spec:
  rules:
  - name: r1
    match:
      resources:
        kinds:
        - Namespace
        selector:
          matchLabels:
            test: "true"
    generate:
      synchronize: true
      kind: ConfigMap
      name: cm1
      namespace: "{{request.object.metadata.name}}"
      data:
        kind: ConfigMap
        data:
          # Enter all your target logging info below
          test.yml: |-
            cm1
  - name: r2
    match:
      resources:
        kinds:
        - Namespace
        selector:
          matchLabels:
            test: "true"
    generate:
      synchronize: true
      kind: ConfigMap
      name: cm2
      namespace: "{{request.object.metadata.name}}"
      data:
        kind: ConfigMap
        data:
          # Enter all your target logging info below
          test.yml: |-
            cm2

Once applied if you remove one of the generate rules and apply policy again it does not remove config map.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

英雄似剑 2025-01-18 11:40:52

如果您有一个 generate 规则,该规则使用带有 synchronize: falsedata 声明(而不是 clone 声明),删除规则将导致下游资源的删除。我们目前有一个错误影响了这一点,但它应该以这种方式工作。

If you have a generate rule which uses a data declaration (not a clone one) with synchronize: false, deleting of the rule will cause deletion of the downstream resource(s). We currently have a bug impacting this, but it's supposed to work this way.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文