From 8e7087a11b7ea2b7d1d06bdadd1b12dc9e0edc1d Mon Sep 17 00:00:00 2001 From: ayu-ch Date: Tue, 5 Nov 2024 15:43:07 +0530 Subject: [PATCH] Add JMESPath SHA1 and MD5 documentation Signed-off-by: ayu-ch --- content/en/docs/writing-policies/jmespath.md | 70 ++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/content/en/docs/writing-policies/jmespath.md b/content/en/docs/writing-policies/jmespath.md index 92be54ea3..3cf30587a 100644 --- a/content/en/docs/writing-policies/jmespath.md +++ b/content/en/docs/writing-policies/jmespath.md @@ -1084,6 +1084,41 @@ EOF

+### Md5 + +
Expand +

+ +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) }}" +``` + +

+
+ ### Modulo
Expand @@ -1901,6 +1936,41 @@ spec:

+### Sha1 + +
Expand +

+ +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) }}" +``` + +

+
+ ### Sha256
Expand