Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JMESPath SHA1 and MD5 documentation #1428

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
70 changes: 70 additions & 0 deletions content/en/docs/writing-policies/jmespath.md
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,41 @@ EOF
</p>
</details>

### Md5

<details><summary>Expand</summary>
<p>

The `md5()` function takes a string of any length and returns a fixed hash value. For example, when `md5()` is applied to the string `Alice & Bob`, it produces the hash `def42e1abd2462df1f9f0a4b3d488221`. This function is particularly useful for creating unique yet shorter identifiers, making it a good option when SHA-256’s 64-character output is too long for Kubernetes resource constraints.

| Input 1 | Output |
|--------------------|---------|
| String | String |

**Example:** This policy mutates the names of specified resources to their MD5 hash values.

```yaml
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: md5-demo
spec:
rules:
- name: convert-name-to-hash
match:
any:
- resources:
kinds:
- Pod
mutate:
patchStrategicMerge:
metadata:
name: "{{ md5(request.object.metadata.name) }}"
```
</p>
</details>
### Modulo
<details><summary>Expand</summary>
Expand Down Expand Up @@ -1901,6 +1936,41 @@ spec:
</p>
</details>

### Sha1

<details><summary>Expand</summary>
<p>

The `sha1()` function takes a string of any length and returns a fixed hash value. For example, when `sha1()` is applied to the string `Alice & Bob`, it gives the output as its SHA1 hash, `e3ec484930685a61b0f824cd684a68699d2b98c1`. This function is particularly useful for creating unique yet shorter identifiers, making it a good option when SHA-256’s 64-character output is too long for Kubernetes resource constraints.

| Input 1 | Output |
|--------------------|---------|
| String | String |

**Example:** This policy mutates the names of specified resources to their SHA1 hash values.

```yaml
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: sha1-demo
spec:
rules:
- name: convert-name-to-hash
match:
any:
- resources:
kinds:
- Pod
mutate:
patchStrategicMerge:
metadata:
name: "{{ sha1(request.object.metadata.name) }}"
```

</p>
</details>

### Sha256

<details><summary>Expand</summary>
Expand Down