|
| 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) |
0 commit comments