-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
c00db6e
commit 965e005
Showing
34 changed files
with
805 additions
and
330 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
.idea/ | ||
.vscode/ | ||
WORKSPACE | ||
.DS_Store | ||
# don't check in the build output of the book | ||
docs/book/book/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# Using External Resources | ||
|
||
In some cases, your project may need to work with resources that aren't defined by your own APIs. | ||
These external resources fall into two main categories: | ||
|
||
- **Core Types**: API types defined by Kubernetes itself, such as `Pods`, `Services`, and `Deployments`. | ||
- **External Types**: API types defined in other projects, such as CRDs managed by another operator. | ||
|
||
## Managing External Types | ||
|
||
### Creating a Controller for External Types | ||
|
||
To create a controller for an external type without scaffolding a resource, you can use the `create api` command with | ||
the `--resource=false` option and specify the path to the external API type using the `--external-api-path` option. | ||
This allows you to generate a controller that operates on types defined outside of your project, such as CRDs managed | ||
by other operators. | ||
|
||
The command looks like this: | ||
|
||
```shell | ||
kubebuilder create api --group <theirgroup> --version v1alpha1 --kind <ExternalTypeKind> --controller --resource=false --external-api-path=<Golang Import Path> | ||
``` | ||
|
||
- `--external-api-path`: This is the import path for the external API type in your Go modules. | ||
You should provide the Go import path where the external types are defined. | ||
|
||
For example, if you're managing Certificates from Cert Manager: | ||
|
||
```shell | ||
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 | ||
``` | ||
|
||
This scaffolds a controller for the external type but skips creating new resource definitions since the type is defined in an external project. | ||
|
||
|
||
### Creating a Webhooks to manage an external type | ||
|
||
> Webhook support for external types is not currently available. (TODO) | ||
## Managing Core Types | ||
|
||
Core Kubernetes API types, such as `Pods`, `Services`, and `Deployments`, are predefined by Kubernetes. | ||
To create a controller for these core types without scaffolding the resource, use the appropriate group for the type. | ||
|
||
The following table lists the core groups and their corresponding API group paths. | ||
Use this information when defining controllers for core Kubernetes resources. | ||
|
||
| Group | API Group | | ||
|--------------------------|-------------------------| | ||
| admission | `k8s.io` | | ||
| admissionregistration | `k8s.io` | | ||
| apps | *(none)* | | ||
| auditregistration | `k8s.io` | | ||
| apiextensions | `k8s.io` | | ||
| authentication | `k8s.io` | | ||
| authorization | `k8s.io` | | ||
| autoscaling | *(none)* | | ||
| batch | *(none)* | | ||
| certificates | `k8s.io` | | ||
| coordination | `k8s.io` | | ||
| core | *(none)* | | ||
| events | `k8s.io` | | ||
| extensions | *(none)* | | ||
| imagepolicy | `k8s.io` | | ||
| networking | `k8s.io` | | ||
| node | `k8s.io` | | ||
| metrics | `k8s.io` | | ||
| policy | *(none)* | | ||
| rbac.authorization | `k8s.io` | | ||
| scheduling | `k8s.io` | | ||
| setting | `k8s.io` | | ||
| storage | `k8s.io` | | ||
|
||
Use the group and API version specific to the type you're | ||
managing when creating a controller for a core type. | ||
|
||
The command for managing a core type looks like this: | ||
|
||
```shell | ||
kubebuilder create api --group core --version v1 --kind Pod --controller=true --resource=false | ||
``` | ||
|
||
This scaffolds a controller for the Core type `corev1.Pod` but skips creating new resource | ||
definitions since the type is defined in the Kubernetes API. | ||
|
||
### Creating a Webhooks to manage a Core Type | ||
|
||
> Webhook support for Core Types is not currently available. (TODO) |
Oops, something went wrong.