Skip to content

Commit 6367514

Browse files
committed
Add some basic documentation for writing kcp-aware controllers
On-behalf-of: SAP <[email protected]> Signed-off-by: Marvin Beckers <[email protected]>
1 parent 384a53c commit 6367514

File tree

8 files changed

+47
-25
lines changed

8 files changed

+47
-25
lines changed

docs/content/developers/.pages

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
nav:
22
- index.md
3+
- controllers
34
- ...
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
nav:
2+
- writing-kcp-aware-controllers.md
3+
- client-go.md
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# client-go
2+
3+
kcp maintains its own `client-go` implementation at [github.com/kcp-dev/client-go](https://github.com/kcp-dev/client-go) for multi-cluster-aware Kubernetes clients, listers and informers.

docs/content/developers/controllers/writing-kcp-aware-controllers.md

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,34 @@ description: >
77

88
# Writing kcp-aware Controllers
99

10-
## Keys for Objects in Listers/Indexers
10+
While kcp follows the Kubernetes Resource Model (KRM) closely, its multi-tenancy capabilities via workspaces / logical clusters
11+
make normal Kubernetes controllers somewhat limited in usefulness, since they generally expect a single Kubernetes API endpoint
12+
(which would correspond to a single logical cluster). While kcp exposes something called [virtual workspaces](../../concepts/workspaces/virtual-workspaces.md),
13+
their API semantics are also different from standard Kubernetes API endpoints and thus, controllers written for Kubernetes
14+
cannot be used against them.
1115

12-
When you need to get an object from a kcp-aware lister or an indexer, you can't just pass the object's name to the
13-
`Get()` function, like you do with a typical controller targeting Kubernetes. Projects using kcp's copy of client-go
14-
are using a modified key function.
16+
!!! info
17+
kcp has previously maintained a [controller-runtime](https://github.com/kubernetes-sigs/controller-runtime) fork under [kcp-dev/controller-runtime](https://github.com/kcp-dev/controller-runtime).
18+
While it likely still works, we recommend migration to multicluster-runtime (see below).
1519

16-
Here are what keys look like for an object `foo` for both cluster-scoped and namespace-scoped varieties:
20+
## multicluster-runtime
1721

18-
|Organization|Workspace|Logical Cluster|Namespace|Key|
19-
|-|-|-|-|-|
20-
|-|-|root|-|root|foo|
21-
|-|-|root|default|default/root|foo|
22-
|root|my-org|root:my-org|-|root:my-org|foo|
23-
|root|my-org|root:my-org|default|default/root:my-org|foo|
24-
|my-org|my-workspace|my-org:my-workspace|-|my-org:my-workspace|foo|
25-
|my-org|my-workspace|my-org:my-workspace|default|default/my-org:my-workspace|foo|
22+
[multicluster-runtime](https://github.com/kubernetes-sigs/multicluster-runtime) is an effort initiated by kcp developers in the upstream
23+
community to provide a framework for building multi-cluster controllers. multicluster-runtime is **not** a fork of controller-runtime,
24+
instead it is a sort of "addon" built on top of controller-runtime's excellent Go generic support. While the project is relatively young
25+
and deemed experimental, we are confident in its ability to provide a great controller development experience for kcp.
2626

27-
## Encoding/Decoding Keys
27+
The runtime itself is generic and needs a so-called provider that provides it with information about the fleet of clusters
28+
it is supposed to reconcile over. A small ecosystem of providers exists already. The relevant provider for writing kcp-aware
29+
controllers is described below.
2830

29-
Use the `github.com/kcp-dev/apimachinery/pkg/cache` package to encode and decode keys.
31+
For more information, also feel free to check out the [talk introducing multicluster-runtime at KubeCon + CloudNativeCon EU in London, 2025](https://www.youtube.com/watch?v=Tz8IcMSY7jw).
32+
33+
### Providers for kcp
34+
35+
kcp hosts a repository for kcp-specific provider implementations at [kcp-dev/multicluster-provider](https://github.com/kcp-dev/multicluster-provider).
36+
37+
Which provider to choose depends on the controller that is to be written, but there is a good chance you want to write a controller for resources
38+
distributed via an [APIExport](../../concepts/apis/exporting-apis.md). In that case, you should choose the `apiexport` provider from the repository.
39+
40+
The provider repository also includes examples, including [one for the `apiexport` provider](https://github.com/kcp-dev/multicluster-provider/tree/main/examples/apiexport).

docs/content/developers/investigations/logical-clusters.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: >
33
Investigation on logical clusters
44
---
55

6-
# Logical clusters
6+
# Logical Clusters
77

88
Kubernetes evolved from and was influenced by earlier systems that had weaker internal tenancy than a general-purpose compute platform requires. The namespace, quota, admission, and RBAC concepts were all envisioned quite early in the project, but evolved with Kubernetes and not all impacts to future evolution were completely anticipated. Tenancy within clusters is handled at the resource and namespace level, and within a namespace there are a limited number of boundaries. Most organizations use either namespace or cluster separation as their primary unit of self service, with variations leveraging a rich ecosystem of tools.
99

docs/content/developers/investigations/self-service-policy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: >
33
Improve consistency and reusability of self-service and policy enforcement across multiple Kubernetes clusters.
44
---
55

6-
# Self-service policy
6+
# Self-service Policy
77

88
## Goal
99

docs/content/developers/investigations/transparent-multi-cluster.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ description: >
33
Investigation of transparent multi-cluster
44
---
55

6-
# Transparent multi-cluster
6+
# Transparent Multi-Cluster
77

8-
## NOTE: This was a prototype that was not continued. The ideas here are still valid and could be picked up by a future project.
8+
9+
!!! warning
10+
This was a prototype that was not continued. The ideas here are still valid and could be picked up by a future project.
911

1012
A key tenet of Kubernetes is that workload placement is node-agnostic until the user needs it to be - Kube offers a homogeneous compute surface that admins or app devs can "break-glass" and set constraints all the way down to writing software that deeply integrates with nodes. But for the majority of workloads a cluster is no more important than a node - it's a detail determined by some human or automated process.
1113

docs/content/developers/storage-to-rest-patterns.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
### workspaces
1+
# Storage to REST Patterns
22

3-
kcp promises to support 1 mln of workspaces.
4-
A workspace is like a Kubernetes endpoint, i.e. an endpoint usual Kubernetes client tooling (client-go, controller-runtime and others)
3+
## Logical Clusters
4+
5+
kcp promises to support 1 million logical clusters.
6+
A logical cluster is like a Kubernetes endpoint, i.e. an endpoint usual Kubernetes client tooling (client-go, controller-runtime and others)
57
and user interfaces (kubectl, helm, web console, ...) can talk to, just like to a Kubernetes cluster.
6-
Thus creating a workspace must be efficient, both in terms of storage and compute.
8+
Thus creating a logical cluster must be efficient, both in terms of storage and compute.
79
It also must provide isolation, just like regular clusters.
810

9-
### etcd
11+
## etcd
1012

1113
etcd is the primary datastore used by kcp.
1214
It stores data in a key-value store.
@@ -52,7 +54,7 @@ Creating a workspace on the storage layer is very efficient because it boils dow
5254
It also provides isolation on the lowest possible level.
5355
Data is filtered by the database engine.
5456

55-
### the generic registry
57+
## Generic Registry
5658

5759
kcp is based on the generic apiserver library provided by Kubernetes.
5860
The central type provided by the library that interacts with a storage layer is called the generic registry.

0 commit comments

Comments
 (0)