Skip to content

Commit b8d5089

Browse files
committed
Add manual multi-group instructions to the book
This adds manual multi-group instructions to the book. We'll eventually get proper multi-group scaffolding.
1 parent 3c44f60 commit b8d5089

File tree

3 files changed

+84
-2
lines changed

3 files changed

+84
-2
lines changed

docs/book/src/SUMMARY.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,15 @@
4040
- [Deployment and Testing](./multiversion-tutorial/deployment.md)
4141

4242
---
43-
- [User Guides](./user-guide.md)
43+
44+
- [Migrations](./migrations.md)
4445

4546
- [Kubebuilder v1 vs v2](./migration/v1vsv2.md)
4647

4748
- [Migration Guide](./migration/guide.md)
4849

50+
- [Single Group to Multi-Group](./migration/multi-group.md)
51+
4952
---
5053

5154
- [Reference](./reference/reference.md)

docs/book/src/migration/guide.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ kubebuilder create api --group batch --version v1 --kind CronJob
8383
```
8484

8585
If you're using multiple groups, some manual work is required to migrate.
86-
Please follow [this](/TODO.md) for more details.
86+
Please follow [this](/migration/multi-group.md) for more details.
8787

8888
### Migrate the APIs
8989

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Single Group to Multi-Group
2+
3+
<aside class="note warning">
4+
5+
<h1>Work In Progress: Manual Work Incoming</h1>
6+
7+
Multi-group scaffolding support is not present in the initial version of
8+
the KubeBuilder v2 scaffolding (as of KubeBuilder v2.0.0).
9+
10+
Once you switch to a multi-group layout, additional manual work will be
11+
needed to create new API groups.
12+
13+
Support will eventually be added for scaffolding -- see
14+
[kubernetes-sigs/kubebuilder#923][multi-group-issue] for more information.
15+
16+
</aside>
17+
18+
While KubeBuilder v2 will not scaffold out a project structure compatible
19+
with multiple API groups in the same repository by default, it's possible
20+
to modify the default project structure to support it.
21+
22+
Let's migrate the [CronJob example][cronjob-tutorial].
23+
24+
Generally, we use the prefix for the API group as the directory name. We
25+
can check `api/v1/groupversion_info.go` to find that out:
26+
27+
```go
28+
// +groupName=batch.tutorial.kubebuilder.io
29+
package v1
30+
```
31+
32+
Then, we'll rename `api` to `apis` to be more clear, and we'll move our
33+
existing APIs into a new subdirectory, "batch":
34+
35+
```bash
36+
mv api apis
37+
mkdir apis/batch
38+
mv apis/v* batch/
39+
```
40+
41+
Next, we'll need to update all the references to the old package name. For
42+
CronJob, that'll be `main.go` and `controllers/cronjob_controller.go`. If
43+
you've added additional files to your project, you'll need to track down
44+
imports there as well.
45+
46+
Finally, we'll add a new line to `PROJECT` that marks this as
47+
a multi-group project:
48+
49+
```yaml
50+
version: "2"
51+
domain: tutorial.kubebuilder.io
52+
repo: tutorial.kubebuilder.io/project
53+
multigroup: true
54+
```
55+
56+
While this option doesn't do anything right now, it'll indicate to
57+
KubeBuilder in future versions that this is a multi-group project.
58+
59+
Now that we've migrated this to a multi-group project, normal KubeBuilder
60+
scaffolding won't work (as of KubeBuilder v2.0.0 -- see the warning at the
61+
top of this page). You'll need to copy the setup that KubeBuilder
62+
normally does to add new groups for the moment:
63+
64+
- Copy over `<kind>_types.go` and `groupversion_info.go` to
65+
`apis/<group>/<version>`
66+
67+
- Register the new group-version with the Scheme in `main.go`
68+
69+
- Add a new `<kind>_controller.go` file
70+
71+
- Add the controller to the manager in `main.go`
72+
73+
The [CronJob tutorial][cronjob-tutorial] explains each of these changes in
74+
more detail (in the context of how they're generated by KubeBuilder for
75+
single-group projects).
76+
77+
[multi-group-issue]: https://github.com/kubernetes-sigs/kubebuilder/issues/923 "KubeBuilder Issue #923"
78+
79+
[cronjob-tutorial]: /cronjob-tutorial/cronjob-tutorial.md "Tutorial: Building CronJob"

0 commit comments

Comments
 (0)