Skip to content

Commit 6f22ccb

Browse files
authored
Merge pull request #905 from DirectXMan12/docs/mv-tutorial-fixups
Multiversion Tutorial Refactor (Use CronJob)
2 parents c5e9e22 + eb8cd5a commit 6f22ccb

File tree

74 files changed

+7279
-1637
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+7279
-1637
lines changed

docs/book/src/SUMMARY.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,15 @@
2828
- [Deploying webhooks](./cronjob-tutorial/running-webhook.md)
2929

3030
- [Epilogue](./cronjob-tutorial/epilogue.md)
31-
- [Tutorial: Multi-version API](./multiversion-tutorial/tutorial.md)
32-
- [Concepts](./multiversion-tutorial/concepts.md)
33-
- [Implement APIs](./multiversion-tutorial/api-implementation.md)
31+
32+
- [Tutorial: Multi-Version API](./multiversion-tutorial/tutorial.md)
33+
34+
- [Changing things up](./multiversion-tutorial/api-changes.md)
35+
- [Hubs, spokes, and other wheel metaphors](./multiversion-tutorial/conversion-concepts.md)
36+
- [Implementing conversion](./multiversion-tutorial/conversion.md)
37+
38+
- [and setting up the webhooks](./multiversion-tutorial/webhooks.md)
39+
3440
- [Deployment and Testing](./multiversion-tutorial/deployment.md)
3541

3642
---
Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
# Epilogue
22

3-
Things left to do:
3+
By this point, we've got a pretty full-featured implementation of the
4+
CronJob controller, and have made use of most of the features of
5+
KubeBuilder.
46

5-
- Write custom printer columns
6-
- Use different watches
7+
If you want more, head over to the [Multi-Version
8+
Tutorial](/multiversion-tutorial/tutorial.md) to learn how to add new API
9+
versions to a project.
10+
11+
Additionally, you can try the following steps on your own -- we'll have
12+
a tutorial section on them Soon™:
13+
14+
- writing unit/integration tests (check out [envtest][envtest])
15+
- adding [additonal printer columns][printer-columns] `kubectl get`
16+
17+
[envtest]: https://godoc.org/sigs.k8s.io/controller-runtime/pkg/envtest
18+
19+
[printer-columns]: /reference/generating-crd.md#additional-printer-columns
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Changing things up
2+
3+
A fairly common change in a Kubernetes API is to take some data that used
4+
to be unstructured or stored in some special string format, and change it
5+
to structured data. Our `schedule` field fits the bill quite nicely for
6+
this -- right now, in `v1`, our schedules look like
7+
8+
```yaml
9+
schedule: "*/1 * * * *"
10+
```
11+
12+
That's a pretty textbook example of a special string format (it's also
13+
pretty unreadable unless you're a Unix sysadmin).
14+
15+
Let's make it a bit more structured. According to the our [CronJob
16+
code][cronjob-sched-code], we support "standard" Cron format.
17+
18+
In Kubernetes, **all versions must be safely round-tripable through each
19+
other**. This means that if we convert from version 1 to version 2, and
20+
then back to version 1, we must not lose information. Thus, any change we
21+
make to our API must be compatible with whatever we supported in v1, and
22+
also need to make sure anything we add in v2 is supported in v2. In some
23+
cases, this means we need to add new fields to v1, but in our case, we
24+
won't have to, since we're not adding new functionality.
25+
26+
Keeping all that in mind, let's figure convert our example above to be
27+
slightly more structured:
28+
29+
```yaml
30+
schedule:
31+
minute: */1
32+
```
33+
34+
Now, at least, we've got labels for each of our fields, but we can still
35+
easily support all the different syntax for each field.
36+
37+
We'll need a new API version for this change. Let's call it v2:
38+
39+
```shell
40+
kubebuilder create api --group batch --version v2 --kind CronJob
41+
```
42+
43+
Now, let's copy over our existing types, and make the change:
44+
45+
{{#literatego ./testdata/project/api/v2/cronjob_types.go}}
46+
47+
## Storage Versions
48+
49+
{{#literatego ./testdata/project/api/v1/cronjob_types.go}}
50+
51+
Now that we've got our types in place, we'll need to set up conversion...
52+
53+
[cronjob-sched-code]: /TODO.md

docs/book/src/multiversion-tutorial/api-implementation.md

Lines changed: 0 additions & 198 deletions
This file was deleted.
Lines changed: 15 additions & 0 deletions
Loading

docs/book/src/multiversion-tutorial/concepts.md

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)