|
24 | 24 | - [Breaking Changes](#breaking-changes)
|
25 | 25 | - [Dependency Licence Management](#dependency-licence-management)
|
26 | 26 | - [API conventions](#api-conventions)
|
27 |
| - - [Optional vs. Required](#optional-vs-required) |
28 |
| - - [Example](#example) |
29 |
| - - [Exceptions](#exceptions) |
30 | 27 | - [CRD additionalPrinterColumns](#crd-additionalprintercolumns)
|
31 | 28 | - [Google Doc Viewing Permissions](#google-doc-viewing-permissions)
|
32 | 29 | - [Issue and Pull Request Management](#issue-and-pull-request-management)
|
@@ -380,50 +377,11 @@ licenses dependencies and other artifacts use. For go dependencies only dependen
|
380 | 377 |
|
381 | 378 | ## API conventions
|
382 | 379 |
|
383 |
| -This project follows the [Kubernetes API conventions](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md). Minor modifications or additions to the conventions are listed below. |
| 380 | +This project follows the [Kubernetes API conventions](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md). |
| 381 | +We enforce the API conventions via [kube-api-linter](https://github.com/kubernetes-sigs/kube-api-linter). |
| 382 | +The corresponding configuration field can be found [here](https://github.com/kubernetes-sigs/cluster-api/blob/main/.golangci-kal.yml). |
384 | 383 |
|
385 |
| -### Optional vs. Required |
386 |
| - |
387 |
| -* Status fields MUST be optional. Our controllers are patching selected fields instead of updating the entire status in every reconciliation. |
388 |
| - |
389 |
| -* If a field is required (for our controllers to work) and has a default value specified via OpenAPI schema, but we don't want to force users to set the field, we have to mark the field as optional. Otherwise, the client-side kubectl OpenAPI schema validation will force the user to set it even though it would be defaulted on the server-side. |
390 |
| - |
391 |
| -Optional fields have the following properties: |
392 |
| -* An optional field MUST be marked with `+optional` and include an `omitempty` JSON tag. |
393 |
| -* Fields SHOULD be pointers if there is a good reason for it, for example: |
394 |
| - * the nil and the zero values (by Go standards) have semantic differences. |
395 |
| - * Note: This doesn't apply to map or slice types as they are assignable to `nil`. |
396 |
| - * the field is of a struct type, contains only fields with `omitempty` and you want |
397 |
| - to prevent that it shows up as an empty object after marshalling (e.g. `kubectl get`) |
398 |
| - |
399 |
| -#### Example |
400 |
| - |
401 |
| -When using ClusterClass, the semantic difference is important when you have a field in a template which will |
402 |
| -have instance-specific different values in derived objects. Because in this case it's possible to set the field to `nil` |
403 |
| -in the template and then the value can be set in derived objects without being overwritten by the cluster topology controller. |
404 |
| - |
405 |
| -#### Exceptions |
406 |
| - |
407 |
| -* Fields in root objects should be kept as scaffolded by kubebuilder, e.g.: |
408 |
| - ```golang |
409 |
| - type Machine struct { |
410 |
| - metav1.TypeMeta `json:",inline"` |
411 |
| - metav1.ObjectMeta `json:"metadata,omitempty"` |
412 |
| - |
413 |
| - Spec MachineSpec `json:"spec,omitempty"` |
414 |
| - Status MachineStatus `json:"status,omitempty"` |
415 |
| - } |
416 |
| - type MachineList struct { |
417 |
| - metav1.TypeMeta `json:",inline"` |
418 |
| - metav1.ListMeta `json:"metadata,omitempty"` |
419 |
| - Items []Machine `json:"items"` |
420 |
| - } |
421 |
| - ``` |
422 |
| - |
423 |
| -* Top-level fields in `status` must always have the `+optional` annotation. If we want the field to be always visible even if it |
424 |
| - has the zero value, it must **not** have the `omitempty` JSON tag, e.g.: |
425 |
| - * Replica counters like `availableReplicas` in the `MachineDeployment` |
426 |
| - * Flags expressing progress in the object lifecycle like `infrastructureReady` in `Machine` |
| 384 | +Minor additions to the conventions are listed below. |
427 | 385 |
|
428 | 386 | ### CRD additionalPrinterColumns
|
429 | 387 |
|
|
0 commit comments