Skip to content

Commit

Permalink
proposal for overriding values inside structured data files
Browse files Browse the repository at this point in the history
Signed-off-by: sophie <[email protected]>
  • Loading branch information
whitewindmills authored and sophiefeifeifeiya committed Aug 28, 2024
1 parent 295dee8 commit a88c656
Show file tree
Hide file tree
Showing 103 changed files with 19,668 additions and 12,694 deletions.
219 changes: 219 additions & 0 deletions docs/proposals/override-values-inside-structured-data-files/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
---
title: Support Variable in OverridePolicy
authors:
- "@sophiefeifeifeiya"
reviewers:
- "@chaunceyjiang"
- TBD

approvers:
- "@chaunceyjiang"
- TBD

creation-date: 2024-08-12

---



# Overriding Values inside Structured Data Files

<!--
This is the title of your KEP. Keep it short, simple, and descriptive. A good
title can help communicate what the KEP is and should be considered as part of
any review.
-->

## Summary



<!--
This section is incredibly important for producing high-quality, user-focused
documentation such as release notes or a development roadmap.
A good summary is probably at least a paragraph in length.
-->

The proposal introduces a new feature, `PlaintextObjectOverrider` within the OverridePolicy in Karmada, allowing users to override values inside JSON or YAML plaintext objects. This feature expands the current capabilities of `PlaintextOverrider`, which only supports whole-field replacements, by enabling granular modifications within complex JSON or YAML structures.



## Motivation

<!--
This section is for explicitly listing the motivation, goals, and non-goals of
this KEP. Describe why the change is important and the benefits to users.
-->

### Goals

<!--
List the specific goals of the KEP. What is it trying to achieve? How will we
know that this has succeeded?
-->

+ Allow users to override specific fields within JSON or YAML structures in ConfigMaps or similar resources.

+ Enable operations, `replace`, `add`, and `remove` on nested fields within plaintext objects.



### Non-Goals

<!--
What is out of scope for this KEP? Listing non-goals helps to focus discussion
and make progress.
-->







## Proposal

<!--
This is where we get down to the specifics of what the proposal actually is.
This should have enough detail that reviewers can understand exactly what
you're proposing, but should not include things like API designs or
implementation. What is the desired outcome and how do we measure success?.
The "Design Details" section below is for the real
nitty-gritty.
-->

### User Stories (Optional)

<!--
Detail the things that people will be able to do if this KEP is implemented.
Include as much detail as possible so that people can understand the "how" of
the system. The goal here is to make this feel real for users without getting
bogged down.
-->

#### Story 1

As an administrator, I want to update specific fields within JSON or YAML files in ConfigMaps to customize application behavior without replacing the entire configuration, ensuring that my changes are minimal and targeted.

#### Story 2

As a developer, I want to override specific environment-related configurations stored in YAML within ConfigMaps, depending on the target deployment cluster, ensuring that my application behaves consistently across environments.



### Notes/Constraints/Caveats (Optional)

<!--
What are the caveats to the proposal?
What are some important details that didn't come across above?
Go in to as much detail as necessary here.
This might be a good place to talk about core concepts and how they relate.
-->

### Risks and Mitigations

<!--
What are the risks of this proposal, and how do we mitigate?
How will security be reviewed, and by whom?
How will UX be reviewed, and by whom?
Consider including folks who also work outside the SIG or subproject.
-->

+ Introducing PlaintextObjectOverrider increases the complexity of OverridePolicy. To mitigate this, thorough documentation and examples will be provided.



## Design Details

<!--
This section should contain enough information that the specifics of your
change are understandable. This may include API specs (though not always
required) or even code snippets. If there's any ambiguity about HOW your
proposal will be implemented, this is the place to discuss them.
-->

### API Change

```go
type Overriders struct {
...
// PlaintextObjectOverrider represents the rules dedicated to handling yaml or json object overrides
// +optional
PlaintextObjectOverrider []PlaintextObjectOverrider `json:"plaintextObjectOverrider,omitempty"`
}
```



### User usage example

For example, consider a ConfigMap with the following data:

```yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: myconfigmap
data:
test.json: |
{"key": {"test": "value"}, {"key1": "value"}}
```
Using PlaintextObjectOverrider, you can update the value of key.test from "value" to "value1" as follows:
```yaml
apiVersion: policy.karmada.io/v1alpha1
kind: OverridePolicy
metadata:
name: example
spec:
overrideRules:
- overriders:
plaintextObjectOverrider:
- path: /data/test.json
plaintext:
- path: /key/test
operator: replace
value: value1
```
After applying this policy, the myconfigmap resource will reflect the updated value within the JSON structure.
### Test Plan
#### UT
- Add unit tests to cover the new functions.
#### E2E
+ Write proposal in `coverage_docs/overridepolicy_test.md` : deployment PlaintextObjectOverrider testing;
+ Use ginkgo to complete the code `overridepolicy_test.go`.



## Alternatives

<!--
What other approaches did you consider, and why did you rule them out? These do
not need to be as detailed as the proposal, but should include enough
information to express the idea and why it was not acceptable.
-->

<!--
Note: This is a simplified version of kubernetes enhancement proposal template.
https://github.com/kubernetes/enhancements/tree/3317d4cb548c396a430d1c1ac6625226018adf6a/keps/NNNN-kep-template
-->







30 changes: 15 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ require (
github.com/kr/pretty v0.3.1
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f
github.com/olekukonko/tablewriter v0.0.5
github.com/onsi/ginkgo/v2 v2.17.1
github.com/onsi/gomega v1.32.0
github.com/onsi/ginkgo/v2 v2.17.2
github.com/onsi/gomega v1.33.1
github.com/opensearch-project/opensearch-go v1.1.0
github.com/prometheus/client_golang v1.18.0
github.com/spf13/cobra v1.8.0
Expand All @@ -26,11 +26,11 @@ require (
github.com/vektra/mockery/v2 v2.10.0
github.com/yuin/gopher-lua v0.0.0-20220504180219-658193537a64
go.uber.org/mock v0.4.0
golang.org/x/net v0.23.0
golang.org/x/term v0.18.0
golang.org/x/net v0.24.0
golang.org/x/term v0.19.0
golang.org/x/text v0.14.0
golang.org/x/time v0.5.0
golang.org/x/tools v0.18.0
golang.org/x/tools v0.20.0
gomodules.xyz/jsonpatch/v2 v2.4.0
google.golang.org/grpc v1.60.1
gopkg.in/yaml.v3 v3.0.1
Expand All @@ -47,14 +47,14 @@ require (
k8s.io/controller-manager v0.30.2
k8s.io/klog/v2 v2.120.1
k8s.io/kube-aggregator v0.30.2
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340
k8s.io/kube-openapi v0.0.0-20240430033511-f0e62f92d13f
k8s.io/kubectl v0.30.2
k8s.io/metrics v0.30.2
k8s.io/utils v0.0.0-20231127182322-b307cd553661
k8s.io/utils v0.0.0-20240423183400-0849a56e8f22
layeh.com/gopher-json v0.0.0-20201124131017-552bb3c4c3bf
sigs.k8s.io/cluster-api v1.7.1
sigs.k8s.io/controller-runtime v0.18.4
sigs.k8s.io/custom-metrics-apiserver v1.29.0
sigs.k8s.io/custom-metrics-apiserver v1.30.0
sigs.k8s.io/kind v0.22.0
sigs.k8s.io/mcs-api v0.1.0
sigs.k8s.io/metrics-server v0.7.1
Expand All @@ -79,7 +79,7 @@ require (
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/emicklei/go-restful/v3 v3.12.0 // indirect
github.com/evanphx/json-patch v5.7.0+incompatible // indirect
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d // indirect
github.com/fatih/camelcase v1.0.0 // indirect
Expand All @@ -93,14 +93,14 @@ require (
github.com/go-openapi/jsonpointer v0.20.2 // indirect
github.com/go-openapi/jsonreference v0.20.4 // indirect
github.com/go-openapi/swag v0.22.7 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/btree v1.0.1 // indirect
github.com/google/cel-go v0.17.8 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/pprof v0.0.0-20230926050212-f7f687d19a98 // indirect
github.com/google/pprof v0.0.0-20240424215950-a892ee059fd6 // indirect
github.com/google/safetext v0.0.0-20220905092116-b49f7bc46da2 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
Expand Down Expand Up @@ -170,12 +170,12 @@ require (
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.26.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/exp v0.0.0-20231226003508-02704c960a9b // indirect
golang.org/x/mod v0.15.0 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/oauth2 v0.18.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.19.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20231212172506-995d672761c0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231212172506-995d672761c0 // indirect
Expand Down
Loading

0 comments on commit a88c656

Please sign in to comment.