Skip to content

Commit

Permalink
fix: docs
Browse files Browse the repository at this point in the history
Signed-off-by: Vishal Choudhary <[email protected]>
  • Loading branch information
vishal-chdhry committed Sep 26, 2024
1 parent e7fa774 commit 08d2ef5
Showing 1 changed file with 6 additions and 40 deletions.
46 changes: 6 additions & 40 deletions content/en/docs/writing-policies/external-data-sources.md
Original file line number Diff line number Diff line change
Expand Up @@ -714,53 +714,19 @@ The data returned by GlobalContextEntries may vary depending on whether it is a
GlobalContextEntries must be in a healthy state (i.e., there is a response received from the remote endpoint) in order for the policies which reference them to be considered healthy. A GlobalContextEntry which is in a `not ready` state will cause any/all referenced policies to also be in a similar state and therefore will not be processed. Creation of a policy referencing a GlobalContextEntry which either does not exist or is not ready will print a warning notifying users.
{{% /alert %}}

## Default
Default is an optional arbitrary JSON object that the context may take if the apiCall returns an error. Default value can also used in case of a server error.
#### Default values for API calls
In the case where the api server returns an error, `default` can be used to provide a fallback value for the api call context entry. The following example shows how to add default value to context entries

For example, the policy below uses `default` values to validate:
```yaml
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: default
spec:
rules:
- name: default-apicall
match:
any:
- resources:
kinds:
- Pod
operations:
- CREATE
...
context:
- name: testString
- name: currentnamespace
apiCall:
urlPath: "/api/v1/namespaces/{{ request.namespace }}/invalid"
urlPath: "/api/v1/namespaces/{{ request.namespace }}"
jmesPath: metadata.name
default: default
- name: testJSON
apiCall:
urlPath: "/api/v1/namespaces/{{ request.namespace }}/invalid"
default: '{"metadata": {"name": "default"}}'
- name: testInteger
apiCall:
urlPath: "/api/v1/namespaces/{{ request.namespace }}/invalid"
jmesPath: metadata.resourceVersion
default: 1
validate:
deny:
conditions:
all:
- key: "{{ testString }}"
operator: Equals
value: "{{ request.namespace }}"
- key: "{{ testJSON.metadata.name }}"
operator: Equals
value: "{{ request.namespace }}"
- key: "{{ testInteger }}"
operator: GreaterThan
value: 2
...
```

## Variables from Image Registries
Expand Down

0 comments on commit 08d2ef5

Please sign in to comment.