|
1 | 1 | # Kubebuilder v0 v.s. v1
|
2 | 2 |
|
3 |
| -## command difference |
| 3 | +Kubebuilder 1.0 adds a new flag `--project-version`, it accepts two different values, `v0` and `v1`. When `v0` is used, the kubebuilder behavior and workflow is the same as kubebuilder 0.*. When `v1` is specified, the generated v1 project layout is architecturally different from v0 project. v1 project uses [controller-runtime](https://github.com/kubernetes-sigs/controller-runtime) set of libraries for controller implementation and used tools under [controller-tools](https://github.com/kubernetes-sigs/controller-tools) for scaffolding and generation. |
| 4 | + |
| 5 | + |
| 6 | +## Command difference |
4 | 7 | - kubebuilder v0 has `init`, `create controller`, `create resouece`, `create config`, `generate` commands and the workflow is
|
5 | 8 |
|
6 | 9 | ```
|
|
25 | 28 | make run
|
26 | 29 | ```
|
27 | 30 | In v1 project, there is no generate command. When the resource or controller is updated, users don't need to regenerate the project.
|
28 |
| - |
29 |
| -## scaffolding difference |
30 |
| - Init a project with example.com and add a resource/api with group apps, version v1, kind Hello in both v0 and v1. The scaffolded projects are as follows. |
31 |
| - - v0 project |
32 |
| -``` |
33 |
| -. |
34 |
| -├── cmd |
35 |
| -│ └── controller-manager |
36 |
| -│ └── main.go |
37 |
| -├── Dockerfile.controller |
38 |
| -├── Gopkg.lock |
39 |
| -├── Gopkg.toml |
40 |
| -├── hack |
41 |
| -│ ├── boilerplate.go.txt |
42 |
| -│ ├── doc.go |
43 |
| -│ ├── imports.go |
44 |
| -│ └── sample |
45 |
| -│ └── hello.yaml |
46 |
| -├── pkg |
47 |
| -│ ├── apis |
48 |
| -│ │ ├── apps |
49 |
| -│ │ │ ├── doc.go |
50 |
| -│ │ │ └── v1 |
51 |
| -│ │ └── doc.go |
52 |
| -│ ├── client |
53 |
| -│ │ ├── clientset |
54 |
| -│ │ │ └── versioned |
55 |
| -│ │ ├── informers |
56 |
| -│ │ │ └── externalversions |
57 |
| -│ │ └── listers |
58 |
| -│ │ └── apps |
59 |
| -│ ├── controller |
60 |
| -│ │ ├── doc.go |
61 |
| -│ │ └── hello |
62 |
| -│ │ ├── controller.go |
63 |
| -│ │ ├── controller_test.go |
64 |
| -│ │ └── hello_suite_test.go |
65 |
| -│ ├── doc.go |
66 |
| -│ └── inject |
67 |
| -│ ├── args |
68 |
| -│ │ └── args.go |
69 |
| -│ ├── doc.go |
70 |
| -│ ├── inject.go |
71 |
| -│ └── zz_generated.kubebuilder.go |
72 |
| -└── vendor |
73 | 31 |
|
74 |
| -``` |
75 |
| - - v1 project |
76 |
| -``` |
77 |
| -├── cmd |
78 |
| -│ └── manager |
79 |
| -│ └── main.go |
80 |
| -├── config |
81 |
| -│ ├── crds |
82 |
| -│ │ └── apps_v1_hello.yaml |
83 |
| -│ └── manager |
84 |
| -│ ├── apps_rolebinding_rbac.yaml |
85 |
| -│ ├── apps_role_rbac.yaml |
86 |
| -│ └── manager.yaml |
87 |
| -├── Dockerfile |
88 |
| -├── Gopkg.toml |
89 |
| -├── hack |
90 |
| -│ └── boilerplate.go.txt |
91 |
| -├── Makefile |
92 |
| -├── pkg |
93 |
| -│ ├── apis |
94 |
| -│ │ ├── addtoscheme_apps_v1.go |
95 |
| -│ │ ├── apis.go |
96 |
| -│ │ └── apps |
97 |
| -│ │ ├── group.go |
98 |
| -│ │ └── v1 |
99 |
| -│ │ ├── doc.go |
100 |
| -│ │ ├── hello_types.go |
101 |
| -│ │ ├── hello_types_test.go |
102 |
| -│ │ ├── register.go |
103 |
| -│ │ └── v1_suite_test.go |
104 |
| -│ └── controller |
105 |
| -│ ├── add_hello.go |
106 |
| -│ ├── controller.go |
107 |
| -│ └── hello |
108 |
| -│ ├── hello_controller.go |
109 |
| -│ ├── hello_controller_suite_test.go |
110 |
| -│ └── hello_controller_test.go |
111 |
| -├── PROJECT |
112 |
| -└── vendor |
113 |
| -``` |
114 |
| -Compared with v0 project, there is no `client`, `inject` folders. |
| 32 | +## Scaffolding difference |
| 33 | + |
| 34 | +- v0 project contains a directory pkg/client while v1 project doesn't |
| 35 | +- v0 project contains a directory inject while v1 project doesn't |
| 36 | +- v0 project layout follows predefined directory layout `pkg/apis` and `pkg/controller` while v1 project accepts user specified path |
| 37 | +- In v1 project, there is a `init()` function for every api and controller. |
| 38 | + |
| 39 | + |
| 40 | +## Library difference |
| 41 | +### Controller libraries |
| 42 | + - v0 projects import the controller library from kubebuilder `kubebuilder/pkg/controller`. It provides a `GenericController` type with a list of functions. |
115 | 43 |
|
116 |
| -## library difference |
| 44 | + - v1 projects import the controller libraries from controller-runtime, such as `controller-runtime/pkg/controller`, `controller-runtime/pkg/reconcile`. |
117 | 45 |
|
118 |
| - - v0 projects import the libraries from kubebuilder, for example kubebuilder/pkg/controller. It provides a `GenericController` type with a list of functions. Note that for created resources, the corresponding client library is generated under the project folder `pkg/client` |
| 46 | +### Client libraries |
119 | 47 |
|
120 |
| - - v1 projects import the libraries from controller-runtime, for example controller-runtime/pkg/controller, controller-runtime/pkg/client, controller-runtime/pkg/reconcile. Note that for created resources or core types, the client library is provided by controller-runtime. |
| 48 | + - In v0 projects, the client libraries is generated by `kubebuilder generate` under directory `pkg/client` and imported wherever they are used in the project. |
121 | 49 |
|
122 |
| -## wiring difference |
| 50 | + - v1 projects imports the dynamic client library from controller-runtime `controller-runtime/pkg/client`. |
| 51 | + |
| 52 | +## Wiring difference |
| 53 | +Wiring refers to the machanics of integrating controllers to controller-manager and injecting the dependencies in them. |
123 | 54 | - v0 projects has a `inject` package and it provides functions for adding the controller to controller-manager as well as registering CRDs.
|
124 | 55 | - v1 projects doesn't have a `inject` package, the controller is added to controller-manager by a `init` function inside add_<type>.go file inside the controller directory. The types is registered by a `init` function inside <type>_types.go file inside the apis directory.
|
0 commit comments