Skip to content

Commit 9d950e6

Browse files
Refactor core developer guide
1 parent c1c8833 commit 9d950e6

33 files changed

+225
-194
lines changed

Diff for: docs/book/src/SUMMARY.md

+28-27
Original file line numberDiff line numberDiff line change
@@ -67,35 +67,36 @@
6767
- [clusterctl Provider Contract](clusterctl/provider-contract.md)
6868
- [clusterctl for Developers](clusterctl/developers.md)
6969
- [clusterctl Extensions with Plugins](clusterctl/plugins.md)
70-
- [Developer Guide](./developer/guide.md)
71-
- [Repository Layout](./developer/repository-layout.md)
72-
- [Rapid iterative development with Tilt](./developer/tilt.md)
73-
- [Logging](./developer/logging.md)
74-
- [Testing](./developer/testing.md)
75-
- [Developing E2E tests](./developer/e2e.md)
76-
- [Controllers](./developer/architecture/controllers.md)
77-
- [Bootstrap](./developer/architecture/controllers/bootstrap.md)
78-
- [Cluster](./developer/architecture/controllers/cluster.md)
79-
- [Machine](./developer/architecture/controllers/machine.md)
80-
- [MachineSet](./developer/architecture/controllers/machine-set.md)
81-
- [MachineDeployment](./developer/architecture/controllers/machine-deployment.md)
82-
- [MachineHealthCheck](./developer/architecture/controllers/machine-health-check.md)
83-
- [Control Plane](./developer/architecture/controllers/control-plane.md)
84-
- [MachinePool](./developer/architecture/controllers/machine-pool.md)
85-
- [ClusterTopology](./developer/architecture/controllers/cluster-topology.md)
86-
- [ClusterResourceSet](./developer/architecture/controllers/cluster-resource-set.md)
87-
- [Multi-tenancy](./developer/architecture/controllers/multi-tenancy.md)
88-
- [Support multiple instances](./developer/architecture/controllers/support-multiple-instances.md)
89-
- [Tuning controllers](./developer/architecture/controllers/tuning.md)
70+
- [Developer Guide](./developer/getting-started.md)
71+
- [Developing "core" Cluster API](developer/core/overview.md)
72+
- [Rapid iterative development with Tilt](developer/core/tilt.md)
73+
- [Repository Layout](developer/core/repository-layout.md)
74+
- [Controllers](./developer/core/controllers/overview.md)
75+
- [Cluster](./developer/core/controllers/cluster.md)
76+
- [ClusterTopology](./developer/core/controllers/cluster-topology.md)
77+
- [ClusterResourceSet](./developer/core/controllers/cluster-resource-set.md)
78+
- [MachineDeployment](./developer/core/controllers/machine-deployment.md)
79+
- [MachineSet](./developer/core/controllers/machine-set.md)
80+
- [Machine](./developer/core/controllers/machine.md)
81+
- [MachinePool](./developer/core/controllers/machine-pool.md)
82+
- [MachineHealthCheck](./developer/core/controllers/machine-health-check.md)
83+
- [Bootstrap](./developer/core/controllers/bootstrap.md)
84+
- [Control Plane](./developer/core/controllers/control-plane.md)
85+
- [Logging](developer/core/logging.md)
86+
- [Testing](developer/core/testing.md)
87+
- [Developing E2E tests](developer/core/e2e.md)
88+
- [Tuning controllers](./developer/core/tuning.md)
89+
- [Support multiple instances](./developer/core/support-multiple-instances.md)
90+
- [Multi-tenancy](./developer/core/multi-tenancy.md)
9091
- [Developing providers](./developer/providers/overview.md)
9192
- [Getting started](developer/providers/getting-started/overview.md)
92-
- [Naming](developer/providers/getting-started/naming.md)
93-
- [Initialize Repo and API types](developer/providers/getting-started/initialize-repo-and-api-types.md)
94-
- [Implement API types](developer/providers/getting-started/implement-api-types.md)
95-
- [Webhooks](developer/providers/getting-started/webhooks.md)
96-
- [Controllers and Reconciliation](developer/providers/getting-started/controllers-and-reconciliation.md)
97-
- [Configure the provider manifest](developer/providers/getting-started/configure-the-deployment.md)
98-
- [Building, Running, Testing](developer/providers/getting-started/building-running-and-testing.md)
93+
- [Naming](developer/providers/getting-started/naming.md)
94+
- [Initialize Repo and API types](developer/providers/getting-started/initialize-repo-and-api-types.md)
95+
- [Implement API types](developer/providers/getting-started/implement-api-types.md)
96+
- [Webhooks](developer/providers/getting-started/webhooks.md)
97+
- [Controllers and Reconciliation](developer/providers/getting-started/controllers-and-reconciliation.md)
98+
- [Configure the provider manifest](developer/providers/getting-started/configure-the-deployment.md)
99+
- [Building, Running, Testing](developer/providers/getting-started/building-running-and-testing.md)
99100
- [Provider contracts](./developer/providers/contracts.md)
100101
- [Cluster Infrastructure](./developer/providers/cluster-infrastructure.md)
101102
- [Control Plane](./developer/providers/control-plane.md)

Diff for: docs/book/src/clusterctl/provider-contract.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ While defining the Deployment Spec, the container that executes the controller/r
254254

255255
For controllers only, the manager MUST support a `--namespace` flag for specifying the namespace where the controller
256256
will look for objects to reconcile; however, clusterctl will always install providers watching for all namespaces
257-
(`--namespace=""`); for more details see [support for multiple instances](../developer/architecture/controllers/support-multiple-instances.md)
257+
(`--namespace=""`); for more details see [support for multiple instances](../developer/core/support-multiple-instances.md)
258258
for more context.
259259

260260
While defining Pods for Deployments, canonical names should be used for images.

Diff for: docs/book/src/developer/architecture/controllers.md

-20
This file was deleted.

Diff for: docs/book/src/developer/architecture/controllers/machine-deployment.md renamed to docs/book/src/developer/core/controllers/machine-deployment.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# MachineDeployment
22

3-
A MachineDeployment orchestrates deployments over a fleet of [MachineSets](./machine-set.md).
3+
A MachineDeployment orchestrates deployments over a fleet of MachineSets.
44

55
Its main responsibilities are:
66
* Adopting matching MachineSets not assigned to a MachineDeployment

Diff for: docs/book/src/developer/architecture/controllers/machine-health-check.md renamed to docs/book/src/developer/core/controllers/machine-health-check.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# MachineHealthCheck
22

3-
A MachineHealthCheck is responsible for remediating unhealthy [Machines](./machine.md).
3+
A MachineHealthCheck is responsible for remediating unhealthy Machines.
44

55
Its main responsibilities are:
66
* Checking the health of Nodes in the [workload clusters] against a list of unhealthy conditions

Diff for: docs/book/src/developer/architecture/controllers/machine-set.md renamed to docs/book/src/developer/core/controllers/machine-set.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# MachineSet
22

3-
A MachineSet is an abstraction over [Machines](./machine.md).
3+
A MachineSet is an abstraction over Machines.
44

55
Its main responsibilities are:
66
* Adopting unowned Machines that aren't assigned to a MachineSet

Diff for: docs/book/src/developer/core/controllers/overview.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Controllers
2+
3+
This section of the book provides an overview about "core" controllers in Cluster API.
4+
5+
<aside class="note warning">
6+
7+
<h1>The code is the source of truth!</h1>
8+
9+
While we put a great effort in ensuring a good documentation for Cluster API, we also recognize that some
10+
part of the documentation are more prone to miss details or become outdated.
11+
12+
Unfortunately, this section is one of those parts, because things in Cluster API change fast and the
13+
complexity of core controllers keeps growing.
14+
15+
Please feel free to open issues or even better send PRs with improvement that can make this documentation
16+
even more valuable for the readers that will follow you.
17+
18+
</aside>

Diff for: docs/book/src/developer/e2e.md renamed to docs/book/src/developer/core/e2e.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ Using the config file it is possible to:
5050

5151
- Define the list of providers to be installed in the management cluster. Most notably,
5252
for each provider it is possible to define:
53-
- One or more versions of the providers manifest (built from the sources, or pulled from a
54-
remote location).
55-
- A list of additional files to be added to the provider repository, to be used e.g.
56-
to provide `cluster-templates.yaml` files.
53+
- One or more versions of the providers manifest (built from the sources, or pulled from a
54+
remote location).
55+
- A list of additional files to be added to the provider repository, to be used e.g.
56+
to provide `cluster-templates.yaml` files.
5757
- Define the list of variables to be used when doing `clusterctl init` or
5858
`clusterctl generate cluster`.
5959
- Define a list of intervals to be used in the test specs for defining timeouts for the
@@ -135,7 +135,7 @@ defined in the [Cluster API test framework] to check if the operation completed
135135

136136
### Naming the test spec
137137

138-
You can categorize the test with a custom label that can be used to filter a category of E2E tests to be run. Currently, the cluster-api codebase has [these labels](./testing.md#running-specific-tests) which are used to run a focused subset of tests.
138+
You can categorize the test with a custom label that can be used to filter a category of E2E tests to be run. Currently, the cluster-api codebase has [these labels](testing.md#running-specific-tests) which are used to run a focused subset of tests.
139139

140140
## Tear down
141141

@@ -189,7 +189,7 @@ The [test E2E package] provides examples of how this can be achieved by implemen
189189
test specs for the most common Cluster API use cases.
190190

191191
<!-- links -->
192-
[Cluster API quick start]: ../user/quick-start.md
192+
[Cluster API quick start]: ../../user/quick-start.md
193193
[Cluster API test framework]: https://pkg.go.dev/sigs.k8s.io/cluster-api/test/framework?tab=doc
194194
[Apply method]: https://pkg.go.dev/sigs.k8s.io/cluster-api/test/framework?tab=doc#Applier
195195
[CAPA E2E tests]: https://github.com/kubernetes-sigs/cluster-api-provider-aws/blob/main/scripts/ci-e2e.sh

Diff for: docs/book/src/developer/logging.md renamed to docs/book/src/developer/core/logging.md

+14-15
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ In Cluster API we strive to follow three principles while implementing logging:
1616

1717
## Upstream Alignment
1818

19-
Kubernetes defines a set of [logging conventions](https://git.k8s.io/community/contributors/devel/sig-instrumentation/logging.md),
19+
Kubernetes defines a set of [logging conventions](https://git.k8s.io/community/contributors/devel/sig-instrumentation/logging.md),
2020
as well as tools and libraries for logging.
2121

2222
## Continuous improvement
@@ -28,16 +28,16 @@ The foundational items of Cluster API logging are:
2828
- Adding a minimal set of key/value pairs in the logger at the beginning of each reconcile loop, so all the subsequent
2929
log entries will inherit them (see [key value pairs](#keyvalue-pairs)).
3030

31-
Starting from the above foundations, then the long tail of small improvements will consist of following activities:
32-
31+
Starting from the above foundations, then the long tail of small improvements will consist of following activities:
32+
3333
- Improve consistency of additional key/value pairs added by single log entries (see [key value pairs](#keyvalue-pairs)).
3434
- Improve log messages (see [log messages](#log-messages)).
3535
- Improve consistency of log levels (see [log levels](#log-levels)).
3636

3737
## Log Format
3838

3939
Controllers MUST provide support for [structured logging](https://github.com/kubernetes/enhancements/tree/master/keps/sig-instrumentation/1602-structured-logging)
40-
and for the [JSON output format](https://github.com/kubernetes/enhancements/tree/master/keps/sig-instrumentation/1602-structured-logging#json-output-format);
40+
and for the [JSON output format](https://github.com/kubernetes/enhancements/tree/master/keps/sig-instrumentation/1602-structured-logging#json-output-format);
4141
quoting the Kubernetes documentation, these are the key elements of this approach:
4242

4343
- Separate a log message from its arguments.
@@ -61,7 +61,7 @@ beginning of the chain are then inherited by all the subsequent log entries crea
6161
Contextual logging is also embedded in controller runtime; In Cluster API we use contextual logging via controller runtime's
6262
`LoggerFrom(ctx)` and `LoggerInto(ctx, log)` primitives and this ensures that:
6363

64-
- The logger passed to each reconcile call has a unique `reconcileID`, so all the logs being written during a single
64+
- The logger passed to each reconcile call has a unique `reconcileID`, so all the logs being written during a single
6565
reconcile call can be easily identified (note: controller runtime also adds other useful key value pairs by default).
6666
- The logger has a key value pair identifying the objects being reconciled,e.g. a Machine Deployment, so all the logs
6767
impacting this object can be easily identified.
@@ -85,18 +85,18 @@ one of the above practices is really important for Cluster API developers
8585
- Developers MUST use `klog.KObj` or `klog.KRef` functions when logging key value pairs for Kubernetes objects, thus
8686
ensuring a key value pair representing a Kubernetes object is formatted consistently in all the logs.
8787
- Developers MUST use consistent log keys:
88-
- kinds should be written in upper camel case, e.g. `MachineDeployment`, `MachineSet`
89-
- Note: we cannot use lower camel case for kinds consistently because there is no way to
90-
automatically calculate the correct log key for provider CRDs like `AWSCluster`
91-
- all other keys should use lower camel case, e.g. `resourceVersion`, `oldReplicas` to align to Kubernetes log conventions
88+
- kinds should be written in upper camel case, e.g. `MachineDeployment`, `MachineSet`
89+
- Note: we cannot use lower camel case for kinds consistently because there is no way to
90+
automatically calculate the correct log key for provider CRDs like `AWSCluster`
91+
- all other keys should use lower camel case, e.g. `resourceVersion`, `oldReplicas` to align to Kubernetes log conventions
9292

9393
Please note that, in order to ensure logs can be easily searched it is important to ensure consistency for the following
9494
key value pairs (in order of importance):
9595

9696
- Key value pairs identifying the object being reconciled, e.g. a MachineDeployment.
9797
- Key value pairs identifying the hierarchy of objects being reconciled, e.g. the Cluster a MachineDeployment belongs
9898
to.
99-
- Key value pairs identifying side effects on other objects, e.g. while reconciling a MachineDeployment, the controller
99+
- Key value pairs identifying side effects on other objects, e.g. while reconciling a MachineDeployment, the controller
100100
creates a MachineSet.
101101
- Other Key value pairs.
102102

@@ -117,9 +117,9 @@ for log levels; as a small integration on the above guidelines we would like to
117117
- Logs at the lower levels of verbosity (<=3) are meant to document “what happened” by describing how an object status
118118
is being changed by controller/reconcilers across subsequent reconciliations; as a rule of thumb, it is reasonable
119119
to assume that a person reading those logs has a deep knowledge of how the system works, but it should not be required
120-
for those persons to have knowledge of the codebase.
120+
for those persons to have knowledge of the codebase.
121121
- Logs at higher levels of verbosity (>=4) are meant to document “how it happened”, providing insight on thorny parts of
122-
the code; a person reading those logs usually has deep knowledge of the codebase.
122+
the code; a person reading those logs usually has deep knowledge of the codebase.
123123
- Don’t use verbosity higher than 5.
124124

125125
We are using log level 2 as a default verbosity for all core Cluster API
@@ -140,7 +140,7 @@ Our [Tilt](tilt.md) setup offers a batteries-included log suite based on [Promta
140140
We are working to continuously improving this experience, allowing Cluster API developers to use logs and improve them as part of their development process.
141141

142142
For the best experience exploring the logs using Tilt:
143-
1. Set `--logging-format=json`.
143+
1. Set `--logging-format=json`.
144144
2. Set a high log verbosity, e.g. `v=5`.
145145
3. Enable Promtail, Loki, and Grafana under `deploy_observability`.
146146

@@ -168,7 +168,7 @@ extra_args:
168168
- "--v=5"
169169
- "--logging-format=json"
170170
```
171-
The above options can be combined with other settings from our [Tilt](tilt.md) setup. Once Tilt is up and running with these settings users will be able to browse logs using the Grafana Explore UI.
171+
The above options can be combined with other settings from our [Tilt](tilt.md) setup. Once Tilt is up and running with these settings users will be able to browse logs using the Grafana Explore UI.
172172
173173
This will normally be available on `localhost:3001`. To explore logs from Loki, open the Explore interface for the DataSource 'Loki'. [This link](http://localhost:3001/explore?datasource%22:%22Loki%22) should work as a shortcut with the default Tilt settings.
174174

@@ -220,4 +220,3 @@ we encourage providers to adopt and contribute to the guidelines defined in this
220220
221221
It is also worth noting that the foundational elements of the approach described in this document are easy to achieve
222222
by leveraging default Kubernetes tooling for logging.
223-

Diff for: docs/book/src/developer/core/overview.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Developing "core" Cluster API
2+
3+
This section of the book is about developing "core" Cluster API.
4+
5+
With "core" Cluster API we refer to the common set of API and controllers that are required to run
6+
any Cluster API provider.
7+
8+
Please note that in the Cluster API code base, side by side of "core" Cluster API components there
9+
is also a limited number of in-tree providers:
10+
11+
- Kubeadm bootstrap provider (CAPBK)
12+
- Kubeadm control plane provider (KCP)
13+
- Docker infrastructure provider (CAPD) - The Docker provider is not designed for production use and is intended for development & test only.
14+
- In Memory infrastructure provider (CAPIM) - The In Memory provider is not designed for production use and is intended for development & test only.
15+
16+
Please refer to [Developing providers](../providers/overview.md) for documentation about in-tree providers (and out of tree providers too).

0 commit comments

Comments
 (0)