You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/policygenerator.md
+47Lines changed: 47 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -75,3 +75,50 @@ DIRECTORY TREE PACKAGE DESCRIPTION
75
75
├── typohelper.go internal Helpers for identifying manifest typos
76
76
├── utils.go internal Helper/utility functions
77
77
```
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)
0 commit comments