kyverno: [Bug] UpdateRequests stuck in Pending status - background and admission controller unable to manage UpdateRequests due to ownership of source secret
Kyverno Version
1.11.4
Kubernetes Version
1.27.x
Kubernetes Platform
AKS
Kyverno Rule Type
Generate
Description
Latest version of Kyverno deployed using helm chart, including annotation ‘admissions.enforcer/disabled’: ‘true’ from notes on AKS. I have 15 policies on the AKS cluster, majority of policies are cloning secrets to other namespaces using example provided in your documentation. 1 mutate policy is modifying dnsPolicy to set ndots also per example in documentation. Would like to deploy actual validation polices, but I’m seeing memory spike through 3gb over a 7 day period on the 3 admission controllers and 1 of the background controllers.
An example of the type of policy being deployed:
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: commitments-user-sync
spec:
generateExisting: true
useServerSideApply: true
rules:
- name: commitments-user-sync
match:
any:
- resources:
kinds:
- Namespace
selector:
matchLabels:
commitments-user: user
generate:
apiVersion: v1
kind: Secret
name: commitments-user
namespace: "{{request.object.metadata.name}}"
synchronize: true
clone:
namespace: kafka
name: commitments-user
I was asked to open a discussion initially, but it’s been 4 days and nobody is interacting, so opening an issue instead https://github.com/kyverno/kyverno/discussions/9518
Steps to reproduce
- Deploy Kyverno with helm on AKS cluster
- Deploy 14 policies to copy secrets to namespaces with a label - secrets are largely generated by Strimzi KafkaUser, previously using kubed or cert-manager - therefore source is technically owned by another operator.
- Memory climbs along with UpdateRequests stuck in a Pending status
Expected behavior
It seems that cloning a secret that’s managed by another resource and keeping them in sync would be a common generate activity in a cluster. Other products like kubed have been successful at this without issue, I moved to Kyverno for more advanced policies in addition to replacing kubed and having more flexiblity in policy application
Screenshots
Kyverno logs
background controller:
E0129 14:47:02.210264 1 clone.go:45] "failed to add labels to the source" err="Operation cannot be fulfilled on secrets \"scm-kafka-forwarder-user\": the object has been modified; please apply your changes to the latest version and try again" logger="background" policy="scm-kafka-forwarder-user-sync" resource="v1/Namespace//" target="v1/Secret/sipapicatqa4/scm-kafka-forwarder-user" type="clone" kind="Secret" namespace="kafka" name="scm-kafka-forwarder-user"
I0129 14:47:02.461548 1 labels.go:78] "resource managed by strimzi-user-operator, kyverno wont over-ride the label"
admission controller:
E0129 14:34:07.224374 1 generator.go:83] "failed to create UpdateRequest, retrying" err="updaterequests.kyverno.io "ur-nzs4z" already exists, the server was not able to generate a unique name for the object" logger="updaterequest-generator" ruleType="generate" resource="v1/Namespace//" name="ur-" namespace="kyverno"
Slack discussion
No response
Troubleshooting
- I have read and followed the documentation AND the troubleshooting guide.
- I have searched other issues in this repository and mine is not recorded.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 22 (12 by maintainers)
After testing this in a lab cluster, the reason this is happening is as I theorized here. After creation of the KafkaUser CR, the Strimzi operator creates and then owns the resulting Secret. When the Kyverno generate policy is installed, it attempts to label the source Secret with the label
generate.kyverno.io/clone-source: "". The Strimzi operator sees this and removes the label. This constant assignment/unassignment causes UpdateRequests to be created endlessly. These are actually different URs each time with a status ofPending. The downstream (generated) resource is not the one which is being changed.According to the resource schema for KafkaUser, it offers the ability to define custom metadata which the operator will create as part of the Secret it owns:
If I modify your
user-intKafkaUser to add this label, the Secret is created with it already assigned and creation of the subsequent Kyverno policy does not produce a UR storm and generate happens correctly.Here, you can see the entire UpdateRequest activity via a watch from the moment the Kyverno policy is installed. The first UR is created for the
existingNamespace which receives a cloned secret as a result ofspec.generateExisting: true. The two following are new Namespaces created after the policy has been installed, each one receiving a generated secret.I think if you try to modify this KafkaUser CR to predefine the Kyverno tracking label that it should resolve the issue.
No, but some users have used a separate mutate rule to remove metadata they don’t want cloned in cases such as Argo CD.
It’s probably not the case where Kyverno doesn’t think the Secret is being cloned; it’s more likely that something else like this Strimzi operator is modifying the cloned resource which Kyverno is then trying to revert. As I suggested, disable synchronization for this policy (only having one and not multiple to test is necessary) and see if the UpdateRequest storm ends.