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: docs/content/concepts/workspaces/workspace-initialization.md
+43-29Lines changed: 43 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ Initializers are used to customize workspaces and bootstrap required resources u
8
8
9
9
### Defining Initializers in WorkspaceTypes
10
10
11
-
A `WorkspaceType` can specify an initializer using the `initializer` field. Here is an example of a `WorkspaceType` with an initializer.
11
+
A `WorkspaceType` can specify having an initializer using the `initializer` field. Here is an example of a `WorkspaceType` with an initializer.
12
12
13
13
```yaml
14
14
apiVersion: tenancy.kcp.io/v1alpha1
@@ -22,6 +22,25 @@ spec:
22
22
path: root
23
23
```
24
24
25
+
Each initializer has a unique name, which gets automatically generated using `<workspace-path-of-WorkspaceType>:<WorkspaceType-name>`. So for example, if you were to apply the aforementioned WorkspaceType on the root workspace, your initializer would be called `root:example`.
26
+
27
+
Since `WorkspaceType.spec.initializers` is a boolean field, each WorkspaceType comes with a single initializer by default. However each WorkspaceType inherits the initializers of its parent WorkspaceType. As a result, it is possible to have multiple initializers on a WorkspaceType using [WorkspaceType Extension](../../concepts/workspaces/workspace-types.md#workspace-type-extensions-and-constraints)
28
+
29
+
In the following example, `child` inherits the initializers of `parent`. As a result, child workspaces will have the `root:child` and `root:parent` initializers set.
30
+
31
+
```yaml
32
+
apiVersion: tenancy.kcp.io/v1alpha1
33
+
kind: WorkspaceType
34
+
metadata:
35
+
name: child
36
+
spec:
37
+
initializer: true
38
+
extend:
39
+
with:
40
+
- name: parent
41
+
path: root
42
+
```
43
+
25
44
### Enforcing Permissions for Initializers
26
45
27
46
The non-root user must have the `verb=initialize` on the `WorkspaceType` that the initializer is for. This ensures that only authorized users can perform initialization actions using virtual workspace endpoint. Here is an example of the `ClusterRole`.
@@ -37,6 +56,7 @@ rules:
37
56
resourceNames: ["example"]
38
57
verbs: ["initialize"]
39
58
```
59
+
40
60
You can then bind this role to a user or a group.
41
61
42
62
```yaml
@@ -54,46 +74,40 @@ roleRef:
54
74
apiGroup: rbac.authorization.k8s.io
55
75
```
56
76
57
-
## initializingworkspaces Virtual Workspace
58
-
59
-
As a service provider, you can use the `initializingworkspaces` virtual workspace to manage workspace resources in the initializing phase. This virtual workspace allows you to fetch `LogicalCluster` objects that are in the initializing phase and request initialization by a specific controller.
77
+
## Writing Custom Initialization Controllers
60
78
61
-
This Virtual Workspace can fetch `LogicalCluster` either by specific its name or using wildcard.
79
+
### Responsibilities Of Custom Initialization Controllers
62
80
63
-
### Endpoint URL path
81
+
Custom Initialization Controllers are responsible for handling initialization logic for custom WorkspaceTypes. They interact with kcp by:
64
82
65
-
`initializingworkspaces`Virtual Workspace provide a virtual api-server to access workspaces that are initializing with the specific initializer. These URLs are published in the status of WorkspaceType object.
83
+
1. Watching for the creation of new LogicalClusters (the backing object behind Workspaces) with the corresponding initializer on them
84
+
2. Running any custom initialization logic
85
+
3. Removing the corresponding initializer from the `.status.initializers` list of the LogicalCluster after initialization logic has successfully finished
66
86
87
+
In order to simplify these processes, kcp provides the `initializingworkspaces` virtual workspace.
### The `initializingworkspaces` Virtual Workspace
72
90
73
-
This is an example URL path for accessing logical cluster apis for a specific initializer in a `initializingworkspaces` virtual workspace.
91
+
As a service provider, you can use the `initializingworkspaces` virtual workspace to manage workspace resources in the initializing phase. This virtual workspace allows you to fetch `LogicalCluster` objects that are in the initializing phase and request initialization by a specific controller.
You can retrieve the url of a Virtual Workspace directly from the `.status.virtualWorkspaces` field of the corresponding WorkspaceType. Returning to our previous example using a custom WorkspaceType called "example", you will receive the following output:
78
94
79
-
You can also use `LogicalCluster` name for the direct view, allowing to manage all resources within that logical cluster.
* Add your custom WorkspaceType to the platform with an initializer.
104
+
You can use this url to construct a kubeconfig for your controller. To do so, use the url directly as the `cluster.server` in your kubeconfig and provide the subject with sufficient permissions (see [Enforcing Permissions for Initializers](#enforcing-permissions-for-initializers))
88
105
89
-
* Create a workspace with the necessary warrants and scopes. The workspace will stay in the initializing state as the initializer is present.
106
+
### Code Sample
90
107
91
-
* Use a controller to watch your initializing workspaces, you can interact with the workspace through the virtual workspace endpoint:
When writing a custom initializer, the following needs to be taken into account:
96
109
97
-
* Once you get the object, you need to initialize the workspace with its related resources, using the same endpoint
110
+
* We strongly recommend to use the kcp [initializingworkspace multicluster-provider](https://github.com/kcp-dev/multicluster-provider) to build your custom initializer
111
+
* You need to update LogicalClusters using patches; They cannot be updated using the update api
98
112
99
-
* Once the initialization is complete, use the same endpoint to remove the initializer from the workspace.
113
+
Keeping this in mind, you can use the [multicluster-provider initializingworkspaces example](https://github.com/kcp-dev/multicluster-provider/tree/main/examples/initializingworkspaces) as a starting point for your initialization controller
0 commit comments