Skip to content

Commit 7ea823d

Browse files
Add support to scaffold controllers for External Types
Introduces the option to allow users scaffold controllers for external types by running: kubebuilder create api --group certmanager --version v1 --kind Certificate --controller=true --resource=false --make=false --external-api-path=github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1
1 parent c00db6e commit 7ea823d

File tree

17 files changed

+386
-297
lines changed

17 files changed

+386
-297
lines changed

docs/book/src/SUMMARY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
- [Manager and CRDs Scope](./reference/scopes.md)
103103

104104
- [Sub-Module Layouts](./reference/submodule-layouts.md)
105-
- [Using an external Type / API](./reference/using_an_external_type.md)
105+
- [Using an external Resource / API](./reference/using_an_external_resource.md)
106106

107107
- [Configuring EnvTest](./reference/envtest.md)
108108

docs/book/src/reference/reference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
- [Platform Support](platform.md)
3636

3737
- [Sub-Module Layouts](submodule-layouts.md)
38-
- [Using an external Type / API](using_an_external_type.md)
38+
- [Using an external Resource / API](using_an_external_resource.md)
3939

4040
- [Metrics](metrics.md)
4141
- [Reference](metrics-reference.md)

docs/book/src/reference/submodule-layouts.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ This part describes how to modify a scaffolded project for use with multiple `go
55
Sub-Module Layouts (in a way you could call them a special form of [Monorepo's][monorepo]) are a special use case and can help in scenarios that involve reuse of APIs without introducing indirect dependencies that should not be available in the project consuming the API externally.
66

77
<aside class="note">
8-
<h1>Using external Types</h1>
8+
<h1>Using External Resources/APIs</h1>
99

10-
If you are looking to do operations and reconcile via a controller a Type(CRD) which are owned by another project then, please see [Using an external Type](/reference/using_an_external_type.md) for more info.
10+
If you are looking to do operations and reconcile via a controller a Type(CRD) which are owned by another project
11+
or By Kubernetes API then, please see [Using an external Resources/API](/reference/using_an_external_type.md)
12+
for more info.
1113

1214
</aside>
1315

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Using External Resources
2+
3+
In some cases, your project may need to work with resources that aren't defined by your own APIs.
4+
These external resources fall into two main categories:
5+
6+
- **Core Types**: API types defined by Kubernetes itself, such as `Pods`, `Services`, and `Deployments`.
7+
- **External Types**: API types defined in other projects, such as CRDs managed by another operator.
8+
9+
## Managing External Types
10+
11+
### Creating a Controller for External Types
12+
13+
To create a controller for an external type without scaffolding a resource, you can use the `create api` command with
14+
the `--resource=false` option and specify the path to the external API type using the `--external-api-path` option.
15+
This allows you to generate a controller that operates on types defined outside of your project, such as CRDs managed
16+
by other operators.
17+
18+
The command looks like this:
19+
20+
```shell
21+
kubebuilder create api --group <theirgroup> --version v1alpha1 --kind <ExternalTypeKind> --controller --resource=false --external-api-path=<Golang Import Path>
22+
```
23+
24+
- `--external-api-path`: This is the import path for the external API type in your Go modules.
25+
You should provide the Go import path where the external types are defined.
26+
27+
For example, if you're managing Certificates from Cert Manager:
28+
29+
```shell
30+
kubebuilder create api --group certmanager --version v1 --kind Certificate --controller=true --resource=false --make=false --external-api-path=github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1
31+
```
32+
33+
This scaffolds a controller for the external type but skips creating new resource definitions since the type is defined in an external project.
34+
35+
36+
### Creating a Webhooks to manage an external type
37+
38+
> Webhook support for external types is not currently available. (TODO)
39+
40+
## Managing Core Types
41+
42+
Core Kubernetes API types, such as `Pods`, `Services`, and `Deployments`, are predefined by Kubernetes.
43+
To create a controller for these core types without scaffolding the resource, use the appropriate group for the type.
44+
45+
The following table lists the core groups and their corresponding API group paths.
46+
Use this information when defining controllers for core Kubernetes resources.
47+
48+
| Group | API Group |
49+
|--------------------------|-------------------------|
50+
| admission | `k8s.io` |
51+
| admissionregistration | `k8s.io` |
52+
| apps | *(none)* |
53+
| auditregistration | `k8s.io` |
54+
| apiextensions | `k8s.io` |
55+
| authentication | `k8s.io` |
56+
| authorization | `k8s.io` |
57+
| autoscaling | *(none)* |
58+
| batch | *(none)* |
59+
| certificates | `k8s.io` |
60+
| coordination | `k8s.io` |
61+
| core | *(none)* |
62+
| events | `k8s.io` |
63+
| extensions | *(none)* |
64+
| imagepolicy | `k8s.io` |
65+
| networking | `k8s.io` |
66+
| node | `k8s.io` |
67+
| metrics | `k8s.io` |
68+
| policy | *(none)* |
69+
| rbac.authorization | `k8s.io` |
70+
| scheduling | `k8s.io` |
71+
| setting | `k8s.io` |
72+
| storage | `k8s.io` |
73+
74+
Use the group and API version specific to the type you're
75+
managing when creating a controller for a core type.
76+
77+
The command for managing a core type looks like this:
78+
79+
```shell
80+
kubebuilder create api --group core --version v1 --kind Pod --controller=true --resource=false
81+
```
82+
83+
This scaffolds a controller for the Core type `corev1.Pod` but skips creating new resource
84+
definitions since the type is defined in the Kubernetes API.
85+
86+
### Creating a Webhooks to manage a Core Type
87+
88+
> Webhook support for Core Types is not currently available. (TODO)

docs/book/src/reference/using_an_external_type.md

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

0 commit comments

Comments
 (0)