Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion charts/apps/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ apiVersion: v2
name: apps
description: An argocd app to deploy apps inside the virtual cluster
type: application
version: 0.5.10
version: 0.5.11
3 changes: 3 additions & 0 deletions charts/apps/staging-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ kyverno:
requests:
cpu: 100m
memory: 4Gi
cleanupController:
enabled: true
replicas: 1

sessionspaces:
enabled: true
Expand Down
2 changes: 1 addition & 1 deletion charts/events/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: events
description: Data Analysis event triggering
type: application

version: 0.3.2
version: 0.3.3

dependencies:
- name: argo-events
Expand Down
54 changes: 54 additions & 0 deletions charts/events/templates/populate-trigger-clusterpolicy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,38 @@ spec:
workflows.diamond.ac.uk/source: '{{`{{templateObject.metadata.labels."workflows.diamond.ac.uk/source"}}`}}'
spec: "{{`{{templateObject.spec}}`}}"

---
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: assign-trigger-ttl
spec:
rules:
- name: propagate-user-ttl
match:
resources:
kinds:
- workflows.diamond.ac.uk/v1alpha1/Trigger
operations:
- CREATE
context:
- name: expiration
variable:
jmesPath: request.object.metadata.labels."workflows.diamond.ac.uk/expiration" || ""

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"expiration" could be ambiguous?

Is it the date/time that is expires?

Is it the duration from created until it expires?

If you only support one, suggest something more explicit:

"expires-in" : "24h"
"expires-at": "2026-07-27"
"time-to-live": "24h"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason that you chose an annotation over making this part of the Trigger CRD spec?

default: "24h"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fine for the PR, we should think about what this default should be


preconditions:
all:
- key: "{{`{{ expiration }}`}}"
operator: AnyNotIn
value:
- "never"
mutate:
patchStrategicMerge:
metadata:
labels:
cleanup.kyverno.io/ttl: "{{`{{ expiration }}`}}"

---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
Expand Down Expand Up @@ -68,3 +100,25 @@ subjects:
- kind: ServiceAccount
name: kyverno-admission-controller
namespace: kyverno
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: kyverno:delete-triggers
rules:
- apiGroups: ["workflows.diamond.ac.uk"]
resources: ["triggers"]
verbs: ["get", "list", "watch", "delete"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: kyverno:delete-triggers
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: kyverno:delete-triggers
subjects:
- kind: ServiceAccount
name: kyverno-cleanup-controller
namespace: kyverno
114 changes: 114 additions & 0 deletions charts/events/test-policy/assign-trigger-ttl/chainsaw-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
name: assign-default-trigger-ttl
spec:
steps:
- try:
- create:
resource:
apiVersion: workflows.diamond.ac.uk/v1alpha1
kind: Trigger
metadata:
name: test-template
labels:
workflows.diamond.ac.uk/source: test-source
workflows.diamond.ac.uk/beamline: test-beamline
spec:
enabled: true
eventName: test-eventname
workflow:
template: workflow-template
- assert:
resource:
apiVersion: workflows.diamond.ac.uk/v1alpha1
kind: Trigger
metadata:
name: test-template
labels:
cleanup.kyverno.io/ttl: 24h
workflows.diamond.ac.uk/source: test-source
workflows.diamond.ac.uk/beamline: test-beamline
spec:
enabled: true
eventName: test-eventname
workflow:
template: workflow-template
---
apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
name: propagate-user-defined-trigger-expiration
spec:
steps:
- try:
- create:
resource:
apiVersion: workflows.diamond.ac.uk/v1alpha1
kind: Trigger
metadata:
name: test-template
labels:
workflows.diamond.ac.uk/expiration: 30m
workflows.diamond.ac.uk/source: test-source
workflows.diamond.ac.uk/beamline: test-beamline
spec:
enabled: true
eventName: test-eventname
workflow:
template: workflow-template
- assert:
resource:
apiVersion: workflows.diamond.ac.uk/v1alpha1
kind: Trigger
metadata:
name: test-template
labels:
cleanup.kyverno.io/ttl: 30m
workflows.diamond.ac.uk/expiration: 30m
workflows.diamond.ac.uk/source: test-source
workflows.diamond.ac.uk/beamline: test-beamline
spec:
enabled: true
eventName: test-eventname
workflow:
template: workflow-template
---
apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
name: allow-never-ending-trigger
spec:
steps:
- try:
- create:
resource:
apiVersion: workflows.diamond.ac.uk/v1alpha1
kind: Trigger
metadata:
name: test-template
labels:
workflows.diamond.ac.uk/expiration: never
workflows.diamond.ac.uk/source: test-source
workflows.diamond.ac.uk/beamline: test-beamline
spec:
enabled: true
eventName: test-eventname
workflow:
template: workflow-template
- assert:
resource:
apiVersion: workflows.diamond.ac.uk/v1alpha1
kind: Trigger
metadata:
name: test-template
labels:
workflows.diamond.ac.uk/expiration: never
workflows.diamond.ac.uk/source: test-source
workflows.diamond.ac.uk/beamline: test-beamline
spec:
enabled: true
eventName: test-eventname
workflow:
template: workflow-template

Loading