Files
homelab/cluster-config/components/kyverno/overlays/policies/annotate-route-argo-external-link.yaml

65 lines
2.1 KiB
YAML

apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: annotate-argo-cd-external-link
annotations:
policies.kyverno.io/title: Annotate Route with Argo CD External Link
policies.kyverno.io/category: Argo
policies.kyverno.io/minversion: 1.0.0
policies.kyverno.io/severity: medium
policies.kyverno.io/subject: Route
policies.kyverno.io/description: >-
This policy adds an annotation to a route that will cause the Argo CD UI
to display an icon representing a clickable link for the route.
spec:
validationFailureAction: audit
rules:
- name: add-annotations-for-https
match:
any:
- resources:
kinds:
- route.openshift.io/v1/Route
operations:
- UPDATE
preconditions:
all:
- key: "{{ request.object.spec.host || '' }}"
operator: NotEquals
value: ""
- key: "{{ request.object.metadata.annotations.\"argocd.argoproj.io/tracking-id\" || '' }}"
operator: NotEquals
value: ""
- key: "{{ request.object.spec.tls.termination || '' }}"
operator: NotEquals
value: ""
mutate:
patchStrategicMerge:
metadata:
annotations:
+(link.argocd.argoproj.io/external-link): https://{{ request.object.spec.host }}/{{ request.object.spec.path || '' }}
- name: add-annotations-for-http
match:
any:
- resources:
kinds:
- route.openshift.io/v1/Route
operations:
- UPDATE
preconditions:
all:
- key: "{{ request.object.spec.host || '' }}"
operator: NotEquals
value: ""
- key: "{{ request.object.metadata.annotations.\"argocd.argoproj.io/tracking-id\" || '' }}"
operator: NotEquals
value: ""
- key: "{{ request.object.spec.tls.termination || '' }}"
operator: Equals
value: ""
mutate:
patchStrategicMerge:
metadata:
annotations:
+(link.argocd.argoproj.io/external-link): http://{{ request.object.spec.host }}/{{ request.object.spec.path || '' }}