Skip to content

Commit b979c6f

Browse files
committed
Update API conventions
Signed-off-by: Stefan Büringer [email protected]
1 parent 4e37a51 commit b979c6f

File tree

1 file changed

+5
-44
lines changed

1 file changed

+5
-44
lines changed

CONTRIBUTING.md

Lines changed: 5 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -380,50 +380,11 @@ licenses dependencies and other artifacts use. For go dependencies only dependen
380380

381381
## API conventions
382382

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-
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`
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.
427388

428389
### CRD additionalPrinterColumns
429390

0 commit comments

Comments
 (0)