Skip to content

[Bug] DeletingPolicy: the example policy does not work #1675

@scraly

Description

@scraly

Page link

https://kyverno.io/docs/policy-types/deleting-policy/

Description

The example policy does not work:

apiVersion: policies.kyverno.io/v1alpha1
kind: DeletingPolicy
metadata:
  name: cleanup-old-test-pods
spec:
  schedule: "0 1 * * *"  # Run daily at 1 AM
  matchConstraints:
    resourceRules:
      - apiGroups: [""]
        apiVersions: ["v1"]
        operations: ["*"]
        resources: ["pods"]
        scope: "Namespaced"
    namespaceSelector:
      matchLabels:
        environment: test
  conditions:
    - name: isOld
      expression: "now() - object.metadata.creationTimestamp > duration('72h')"
  variables:
    - name: isEphemeral
      expression: "has(object.metadata.labels.ephermal) && object.metadata.labels.ephemeral == 'true'"

Apply error:

$ kubectl apply -f dpol.yaml
Error from server: error when creating "dpol.yaml": admission webhook "validate-policy.kyverno.svc" denied the request: spec.conditions[0].expression: Invalid value: "now() - object.metadata.creationTimestamp > duration('72h')": ERROR: <input>:1:4: undeclared reference to 'now' (in container '')
 | now() - object.metadata.creationTimestamp > duration('72h')
 | ...^

Expected behavior

No error during the apply and a working policy.

Slack discussion

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions