Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added condition for resource sync #2247

Merged
merged 3 commits into from
Aug 30, 2021

Conversation

NoSkillGirl
Copy link
Contributor

@NoSkillGirl NoSkillGirl commented Aug 9, 2021

Signed-off-by: NoSkillGirl singhpooja240393@gmail.com

Related issue

closes #2181

What type of PR is this

/kind bug

Proposed Changes

Added logic to update the label and generated resource according to the synchronize flag in generate policy.

Logic:
In case synchronize is true - update the resource label and generated resource according to the data available in generate policy.
In case synchronize is false - update the resource label only if it does not match with the generate policy label and do not update the old generated resource.

Proof Manifests

  1. Apply the following policy:
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
  annotations:
    policies.kyverno.io/category: Workload Isolation
    policies.kyverno.io/description: To limit the number of objects, as well as the total amount of compute that may be consumed by a single namespace, create a default resource quota for each namespace.
  labels:
    app.kubernetes.io/version: v1.4.1
  name: add-ns-quota
spec:
  background: false
  rules:
    - generate:
        data:
          spec:
            hard:
              limits.cpu: 1600m
              limits.memory: 8Gi
              pods: 8
        kind: ResourceQuota
        name: default-resourcequota
        namespace: '{{request.object.metadata.name}}'
        synchronize: false
      match:
        resources:
          kinds:
            - Namespace
      name: generate-resourcequota
      preconditions:
        all:
          - key: '{{request.object.metadata.labels.businessunit}}'
            operator: NotEquals
            value: ""
  1. Apply following resource :
apiVersion: v1
kind: Namespace
metadata:
  labels:
    businessunit: supplychain
    dataclassification: nonpci
    env: dev3
    networkzone: internal
  name: supplychainontario-wsigateway-dev3
  1. Edit the generated resource:
kubectl edit ResourceQuota -n supplychainontario-wsigateway-dev3 
  1. Wait for the next time trigger (approx 15min ) - the resource should not get updated by the kyverno. The changes should be still present in the generated resource.

Checklist

  • I have read the contributing guidelines.
  • [] I have added tests that prove my fix is effective or that my feature works.
  • [] My PR contains new or altered behavior to Kyverno and
    • [] I have added or changed the documentation myself in an existing PR and the link is:
    • [] I have raised an issue in kyverno/website to track the doc update and the link is:
    • [] I have read the PR documentation guide and followed the process including adding proof manifests to this PR.

Further Comments

@NoSkillGirl NoSkillGirl added the wip work in progress label Aug 9, 2021
Signed-off-by: NoSkillGirl <singhpooja240393@gmail.com>
Signed-off-by: NoSkillGirl <singhpooja240393@gmail.com>
Signed-off-by: NoSkillGirl <singhpooja240393@gmail.com>
@NoSkillGirl NoSkillGirl merged commit 15e16e8 into kyverno:main Aug 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Generate policies with background:false and synchronize:false are still re-evaluated every 15mins
2 participants