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: CONTRIBUTING.md
+5-44Lines changed: 5 additions & 44 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -380,50 +380,11 @@ licenses dependencies and other artifacts use. For go dependencies only dependen
380
380
381
381
## API conventions
382
382
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.
384
-
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
-
typeMachinestruct {
410
-
metav1.TypeMeta`json:",inline"`
411
-
metav1.ObjectMeta`json:"metadata,omitempty"`
412
-
413
-
SpecMachineSpec`json:"spec,omitempty"`
414
-
StatusMachineStatus`json:"status,omitempty"`
415
-
}
416
-
typeMachineListstruct {
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`
383
+
This project follows the [Kubernetes API conventions](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md).
384
+
We enforce the API conventions via [kube-api-linter](https://github.com/kubernetes-sigs/kube-api-linter).
385
+
The corresponding configuration field can be found [here](https://github.com/kubernetes-sigs/cluster-api/blob/main/.golangci-kal.yml).
386
+
387
+
Minor additions to the conventions are listed below.
0 commit comments