Skip to content

Commit 3cbd23a

Browse files
committed
docs: Schema contribution guide
1 parent 2bfc586 commit 3cbd23a

File tree

2 files changed

+154
-0
lines changed

2 files changed

+154
-0
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ repos:
1717
- id: trailing-whitespace
1818
exclude: ^helmfile\.d/upstream/|^tests/.*/resources/
1919

20+
# TODO: Migrate to same config as compliantkubernetes repo.
2021
- repo: https://github.com/igorshubovych/markdownlint-cli
2122
rev: v0.39.0
2223
hooks:
2324
- id: markdownlint
2425
name: lint markdown
2526
args:
2627
- --disable
28+
- MD007 # Unordered list indentation
2729
- MD013 # Line length
2830
- MD024 # Multiple headings with the same content
2931
- MD026 # Trailing punctuation in heading

config/schemas/README.md

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,155 @@ This can be enabled this in other repositories by editing the file `.vscode/sett
109109
}
110110
}
111111
```
112+
113+
## Guidelines
114+
115+
The uses for the schema is to provide structural and conditional validation here in this repository, and to provide reference documentation in the public documentation repository.
116+
To make it easier to read, write, and use the schema we have a set of guidelines to make the most out of it that will follow below.
117+
118+
> [!note]
119+
> The word "schema" here refers to any part of the schema, even subschemas, or schemas in definitions, etc.
120+
>
121+
> The example keys given are within the schema, shortened by stripping any `properties` and `items` components.
122+
123+
### Metadata
124+
125+
These guidelines aim to help in creating better quality reference documentation.
126+
127+
#### Titles
128+
129+
- Must be provided, else it becomes rendered as `Untitled`.
130+
- Should be capitalised, as it becomes part of rendered headers `<title> Schema`.
131+
- Should be short, as it becomes part of rendered names.
132+
- Should be based on the key of the schema, as it becomes more intuitive.
133+
- Should include the context of the schema for common keys, e.g. `Object Storage` and `Object Storage Network Policies`.
134+
- Should include the context type of the schema last, as it becomes part of rendered headers `<title> <type> Schema`.
135+
136+
#### Descriptions
137+
138+
- Must be [GitHub Flavoured Markdown (GFM)](https://github.github.com/gfm/), as it will be rendered down into markdown documentation.
139+
- Should be provided for all complex types, `array` and `object` with `items` or `properties` respectively, and other types of note.
140+
- Should be written with full sentences, including proper punctuation.
141+
- Should include a leading explanation of what the option does and affect.
142+
- For the root of larger schemas, e.g:
143+
- `.dex` - "Configure Dex, the federated OpenID connect identity provider."
144+
- For the root of smaller schemas, e.g.:
145+
- `.dex.expiry` - "Configure expiry when authenticating via Dex."
146+
- For the leaf of schemas, e.g.:
147+
- `.dex.expiry.idToken` - "Configure expiry of id tokens."
148+
- Should include a follow up explanation for more details when required, e.g:
149+
- `.grafana` - "Compliant Kubernetes hosts two instances of Grafana one for the Platform Administrator and one for the Application Developer"
150+
- Should include a follow up explanation for conditionals, e.g:
151+
- `.networkPolicies.ingressNginx.ingressOverride` - "When enabled a list of IPs must be set that should override the allowed ingress traffic."
152+
- Should include a follow up explanation for requirements, e.g:
153+
- `.velero` - "This requires that `.objectStorage` is configured, and will use the bucket or container set in `.objectStorage.buckets.velero`."
154+
- Should include a reference to upstream documentation, and applicable mapping rules, wrapped in a note GFM alert, e.g.:
155+
- `.fluentd.forwarder.buffer` - "See \[the upstream documentation for reference\]\(\<link\>\), set keys will converted from `camelCase` to `snake_case` as required."
156+
- Should include a note about which cluster it is applicable, either in schema roots as a general case or in schema leafs as an exception, wrapped in a note GFM alert:
157+
- For the root of larger schemas, e.g.:
158+
- `.dex` - "Dex is installed in the service cluster, therefore this configuration mainly applies there."
159+
- For the leaf of schemas, e.g.:
160+
- `.dex.subdomain` - "Must be set for both service and workload clusters."
161+
162+
#### Defaults and examples
163+
164+
- Must be provided for all simple types, all `array` types, all compositional, conditional, and reusable `object` types.
165+
- Must be valid input to the schema, with the exception of `set-me`.
166+
- Should degrade gracefully, e.g. disabling optional components rather than enabling.
167+
168+
### Structural
169+
170+
These guidelines aim to help in creating schemas that are easier to read and write.
171+
172+
- All schemas must define a type.
173+
- All schemas should define a single type to not cause type confusion.
174+
- All schemas should use `additionalProperties: false` when no additional properties should be defined to make it easier to find misspelled keys.
175+
176+
#### Defines
177+
178+
Defines here refer to the use of `$defs` to define schemas, and `$ref`:s to use schemas.
179+
This is usable in two situations:
180+
181+
1. To reuse common schemas
182+
2. To reduce and flatten nested schemas
183+
184+
- Must be grouped, so documentation can be generated for it, e.g.:
185+
- `.opensearch.$defs.roles` is not used on its own, but contains schemas that are reused.
186+
- Must be flattened, so documentation can be generated for it, e.g.:
187+
- `.opensearch.$defs.roles` contains schemas, but those schemas does not define subschemas instead they use `$refs` to other schemas under `.opensearch.$defs.roles`.
188+
- Should be used whenever possible to reuse common schemas, e.g. to have common definitions for similar things like `.grafana.ops` and `.grafana.user`.
189+
- Should be used whenever needed to reduce nested schemas, e.g. to reduce the generated names of a schema which is composed of the path to it within the schema.
190+
- Should be defined under `$defs` local to where they are used, e.g.:
191+
- `.opensearch.$defs.node` with subschemas reused by `.opensearch.master`, `.opensearch.data`, and `.opensearch.client` node.
192+
- `.opensearch.$defs.roles` with subschemas reduced and flattened for `.opensearch.extraRoles`.
193+
- Should **not** define titles, descriptions, defaults, or examples unless they are universally applicable.
194+
- Else it will not be possible to override this metadata when referenced.
195+
196+
#### Imports
197+
198+
Imports here refers to the use of `$defs` to define schemas fetched from upstream sources.
199+
The same guidelines for defines are applicable here as well.
200+
201+
- Must include a comment under the key `$comment` in the schema with the stanza "Schema imported from \[\<upstream-name\>\]\(\<upstream-link\>\).".
202+
- Must include a reference to upstream documentation.
203+
204+
#### Compositions and Conditions
205+
206+
Compositions and conditions here refers to the use of `allOf`, `anyOf`, and `oneOf`, etc. to define schema compositions and conditions.
207+
208+
- Schemas with compositions and conditions must set defaults because otherwise they cannot be fully resolved.
209+
- Schemas with compositions and conditions should set examples because otherwise they cannot be fully resolved.
210+
- Should not use `if`-`then`-`else` as it has less support in tooling, and has a semantic that is generally different from other schema constructs.
211+
212+
<details>
213+
<summary>Examples</summary>
214+
215+
Enabled component have standard properties:
216+
217+
```yaml
218+
anyOf:
219+
- properties:
220+
enabled:
221+
const: false
222+
- properties:
223+
enabled:
224+
const: true
225+
required:
226+
- resources
227+
- nodeSelector
228+
- tolerations
229+
- affinity
230+
```
231+
232+
Object storage have associated properties:
233+
234+
```yaml
235+
anyOf:
236+
- properties:
237+
type:
238+
const: azure
239+
required:
240+
- azure
241+
- properties:
242+
type:
243+
const: s3
244+
required:
245+
- s3
246+
- properties:
247+
type:
248+
const: swift
249+
required:
250+
- swift
251+
```
252+
253+
Combining multiple conditions:
254+
255+
```yaml
256+
allOf:
257+
- anyOf:
258+
<schema>
259+
- anyOf:
260+
<schema>
261+
```
262+
263+
</details>

0 commit comments

Comments
 (0)