From 49950ada20df82e9773646b48974e59015d8d429 Mon Sep 17 00:00:00 2001 From: sophie Date: Sun, 29 Sep 2024 20:19:51 -0400 Subject: [PATCH] docs: fieldoverrider docs Signed-off-by: sophie --- docs/userguide/scheduling/override-policy.md | 54 +++++++++++++++++++ .../userguide/scheduling/override-policy.md | 54 +++++++++++++++++++ 2 files changed, 108 insertions(+) diff --git a/docs/userguide/scheduling/override-policy.md b/docs/userguide/scheduling/override-policy.md index b285e3e6..ffeb43d5 100644 --- a/docs/userguide/scheduling/override-policy.md +++ b/docs/userguide/scheduling/override-policy.md @@ -180,6 +180,7 @@ Karmada offers various alternatives to declare the override rules: - `LabelsOverrider`: overrides labels for workloads. - `AnnotationsOverrider`: overrides annotations for workloads. - `PlaintextOverrider`: a general-purpose tool to override any kind of resources. +- `FieldOverrider`: partially override values inside JSON and YAML fields. ### ImageOverrider The `ImageOverrider` is a refined tool to override images with format `[registry/]repository[:tag|@digest]`(e.g.`/spec/template/spec/containers/0/image`) for workloads such as `Deployment`. @@ -426,6 +427,59 @@ spec: Note: `AnnotationsOverrider` functions the similar way as `LabelsOverrider`. You can refer to the `LabelsOverrider` examples. +### FieldOverrider +The `FieldOverrider` allows users to partially override values inside JSON and YAML fields. + +The allowed operations are as follows: + ++ `add`: appends new key-value pairs at the specified sub path. ++ `remove`: removes specific key-value pairs at the specified sub path. ++ `replace`: replaces existing values with new values at the specified sub path. + +Suppose we have a ConfigMap named myconfigmap that contains some nested YAML data: +```yaml +apiVersion: v1 +kind: ConfigMap +metadata: + name: myconfigmap +data: + config.yaml: | + app: + database: + port: 5432 +``` + +Example 1: Replace the database port within the ConfigMap using YAML Patch operations. + +```yaml +apiVersion: policy.karmada.io/v1alpha1 +kind: OverridePolicy +metadata: + name: example +spec: + #... + overrideRules: + - overriders: + fieldOverrider: + - fieldPath: /data/config.yaml + yaml: + - subPath: /app/database/port + operator: replace + value: "3306" +``` +After applying this OverridePolicy, the ConfigMap will be updated as follows: +```yaml +apiVersion: v1 +kind: ConfigMap +metadata: + name: myconfigmap +data: + config.yaml: | + app: + database: + port: 3306 +``` + ### PlaintextOverrider The `PlaintextOverrider` is a simple overrider that overrides target fields according to path, operator and value, just like `kubectl patch`. diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/userguide/scheduling/override-policy.md b/i18n/zh/docusaurus-plugin-content-docs/current/userguide/scheduling/override-policy.md index 7946e938..513c6a15 100644 --- a/i18n/zh/docusaurus-plugin-content-docs/current/userguide/scheduling/override-policy.md +++ b/i18n/zh/docusaurus-plugin-content-docs/current/userguide/scheduling/override-policy.md @@ -180,6 +180,7 @@ Karmada offers various alternatives to declare the override rules: - `LabelsOverrider`: overrides labels for workloads. - `AnnotationsOverrider`: overrides annotations for workloads. - `PlaintextOverrider`: a general-purpose tool to override any kind of resources. +- `FieldOverrider`: partially override values inside JSON and YAML fields. ### ImageOverrider The `ImageOverrider` is a refined tool to override images with format `[registry/]repository[:tag|@digest]`(e.g.`/spec/template/spec/containers/0/image`) for workloads such as `Deployment`. @@ -426,6 +427,59 @@ spec: Note: `AnnotationsOverrider` functions the similar way as `LabelsOverrider`. You can refer to the `LabelsOverrider` examples. +### FieldOverrider +The `FieldOverrider` allows users to partially override values inside JSON and YAML fields. + +The allowed operations are as follows: + ++ `add`: appends new key-value pairs at the specified sub path. ++ `remove`: removes specific key-value pairs at the specified sub path. ++ `replace`: replaces existing values with new values at the specified sub path. + +Suppose we have a ConfigMap named myconfigmap that contains some nested YAML data: +```yaml +apiVersion: v1 +kind: ConfigMap +metadata: + name: myconfigmap +data: + config.yaml: | + app: + database: + port: 5432 +``` + +Example 1: Replace the database port within the ConfigMap using YAML Patch operations. + +```yaml +apiVersion: policy.karmada.io/v1alpha1 +kind: OverridePolicy +metadata: + name: example +spec: + #... + overrideRules: + - overriders: + fieldOverrider: + - fieldPath: /data/config.yaml + yaml: + - subPath: /app/database/port + operator: replace + value: "3306" +``` +After applying this OverridePolicy, the ConfigMap will be updated as follows: +```yaml +apiVersion: v1 +kind: ConfigMap +metadata: + name: myconfigmap +data: + config.yaml: | + app: + database: + port: 3306 +``` + ### PlaintextOverrider The `PlaintextOverrider` is a simple overrider that overrides target fields according to path, operator and value, just like `kubectl patch`.