Skip to content

Commit a7f8eaf

Browse files
edcdavidopenshift-merge-bot[bot]
authored andcommitted
Updating Docs
Signed-off-by: David Elie-Dit-Cosaque <[email protected]>
1 parent 7b2bf9c commit a7f8eaf

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

docs/policygenerator.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,50 @@ DIRECTORY TREE PACKAGE DESCRIPTION
7575
├── typohelper.go internal Helpers for identifying manifest typos
7676
├── utils.go internal Helper/utility functions
7777
```
78+
## Openapi schema support
79+
policy-genenerator-plugin supports openapi schemas as defined in https://kubectl.docs.kubernetes.io/references/kustomize/kustomization/openapi by Kustomize. The goal of this feature is to support patching non kubernetest CR objects that contain list of objects.
80+
The openapi object in this project has the same format of the openapi object in the kustomize project. The Path indicates the relative path of the schema json file relative to the kustomization.yaml file
81+
``` yaml
82+
openapi:
83+
path: schema.json
84+
```
85+
The openapi object is part of the manifest object in the plugin file:
86+
``` yaml
87+
apiVersion: policy.open-cluster-management.io/v1
88+
kind: PolicyGenerator
89+
...
90+
policies:
91+
- name: myapp
92+
manifests:
93+
- path: input-kustomize/
94+
patches:
95+
openapi:
96+
path: schema.json
97+
```
98+
### How to create a Kustomize schema manually
99+
Ideally the openapi schema should be provided by the developper of the Custom Resource (CR).
100+
To retrieve a schema from a running kubernetes cluster manually, do the following:
101+
102+
``` default
103+
kustomize openapi fetch
104+
```
105+
106+
Then cut and paste the subset containing the resources that need to be patched.
107+
108+
Next, identify the list objects in the schema and select a key from the fields
109+
of the object that would be use to index the list, for instance a name. After
110+
the definition of the list, add the following text:
111+
112+
``` default
113+
"x-kubernetes-patch-merge-key": "name",
114+
"x-kubernetes-patch-strategy": "merge"
115+
```
116+
117+
`x-kubernetes-patch-merge-key` indicates the field in the object that is used to
118+
uniquely identify it in the list in this case the `name` field
119+
`x-kubernetes-patch-strategy` indicates the patch strategy. Merge would merge
120+
fields, replace would replace the object identified by the key with patch
121+
content.
122+
`Note:` The "key" selected in this step is used in patches to uniquely identify a list object.
123+
124+
An example of schema for the ptp-operator PtpConfig CR is shown at [link](internal/testdata/OpenAPI/newptpconfig-schema.json)

examples/policyGenerator-kustomize.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,8 @@ policies:
1313
- name: myapp
1414
manifests:
1515
- path: input-kustomize/
16+
patches:
17+
- metadata:
18+
name: "myname"
19+
openapi:
20+
path: schema.json

0 commit comments

Comments
 (0)