You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -6,95 +6,157 @@ There are several different external types that may be referenced when writing a
6
6
* CRDs that are created and installed in another project.
7
7
* A custom API defined via the aggregation layer, served by an extension API server for which the primary API server acts as a proxy.
8
8
9
-
Currently Kubebuilder handles the first two—CRDs and Core Resources—seamlessly. You must scaffold the latter two—External CRDs and APIs created via aggregation—manually.
9
+
Currently, kubebuilder handles the first two, CRDs and Core Resources, seamlessly. You must scaffold the latter two, External CRDs and APIs created via aggregation, manually.
10
10
11
11
In order to use a Kubernetes Custom Resource that has been defined in another project
12
12
you will need to have several items of information.
13
13
* The Domain of the CR
14
14
* The Group under the Domain
15
-
* The Go import path of the CR Type definition.
15
+
* The Go import path of the CR Type definition
16
+
* The Custom Resource Type you want to depend on.
16
17
17
18
The Domain and Group variables have been discussed in other parts of the documentation. The import path would be located in the project that installs the CR.
18
-
19
+
The Custom Resource Type is usually a Go Type of the same name as the CustomResourceDefinition in kubernetes, e.g. for a `Pod` there will be a type `Pod` in the `v1` group.
20
+
For Kubernetes Core Types, the domain can be omitted.
21
+
``
19
22
This document uses `my` and `their` prefixes as a naming convention for repos, groups, and types to clearly distinguish between your own project and the external one you are referencing.
20
-
Note that by default, multigroup APIs are no longer included. To enable them again, see [the guide on multigroup API migration](https://book.kubebuilder.io/migration/multi-group.html).
21
23
22
-
Example external API Aggregation directory structure
23
-
```
24
-
github.com
25
-
├── theiruser
26
-
├── theirproject
27
-
├── apis
28
-
├── theirgroup
29
-
├── doc.go`
30
-
├── install
31
-
│ ├── install.go
32
-
├── v1alpha1
33
-
│ ├── doc.go
34
-
│ ├── register.go
35
-
│ ├── types.go
36
-
│ ├── zz_generated.deepcopy.go
37
-
```
24
+
In our example we will assume the following external API Type:
25
+
26
+
`github.com/theiruser/theirproject` is another kubebuilder project on whose CRD we want to depend and extend on.
27
+
Thus, it contains a `go.mod` in its repository root. The import path for the go types would be `github.com/theiruser/theirproject/api/theirgroup/v1alpha1`.
28
+
29
+
The Domain of the CR is `theirs.com`, the Group is `theirgroup` and the kind and go type would be `ExternalType`.
30
+
31
+
If there is an interest to have multiple Controllers running in different Groups (e.g. because one is an owned CRD and one is an external Type), please first
32
+
reconfigure the Project to use a multi-group layout as described in the [Multi-Group documentation](../migration/multi-group.md).
33
+
34
+
### Prerequisites
38
35
39
-
In the case above the import path would be `github.com/theiruser/theirproject/apis/theirgroup/v1alpha1`
36
+
The following guide assumes that you have already created a project using `kubebuilder init` in a directory in the GOPATH. Please reference the [Getting Started Guide](../getting-started.md) for more information.
40
37
38
+
Note that if you did not pass `--domain` to `kubebuilder init` you will need to modify it for the individual api types as the default is `my.domain`, not `theirs.com`.
39
+
Similarly, if you intend to use your own domain, please configure your own domain with `kubebuilder init` and do not use `theirs.com for the domain.
41
40
42
-
### Add a controller
41
+
### Add a controller for the external Type
42
+
43
+
Run the command `create api` to scaffold only the controller to manage the external type:
43
44
44
-
be sure to answer no when it asks if you would like to create an api? [Y/n]
45
45
```shell
46
-
kubebuilder create api --group mygroup --version $APIVERSION --kind MyKind
Note that the `resource` argument is set to false, as we are not attempting to create our own CustomResourceDefinition,
50
+
but instead rely on an external one.
51
+
52
+
This will result in a `PROJECT` entry with the default domain of the `PROJECT` (`my.domain` if not specified in `kubebuilder init`).
53
+
For use of other domains, such as `theirs.com`, one will have to manually adjust the `PROJECT` file with the correct domain for the entry:
54
+
55
+
<asideclass="note">
56
+
If you are looking to create Controllers to manage Kubernetes Core types (i.e. Deployments/Pods)y
57
+
you do not need to update the PROJECT file or register the Schema in the manager. All Core Types are registered by default. The Kubebuilder CLI will add the required values to the PROJECT file, but you still need to perform changes to the RBAC markers manually to ensure that the Rules will be generated accordingly.
58
+
</aside>
59
+
60
+
file: PROJECT
61
+
```
62
+
domain: my.domain
63
+
layout:
64
+
- go.kubebuilder.io/v4
65
+
projectName: testkube
66
+
repo: example.com
67
+
resources:
68
+
- controller: true
69
+
domain: my.domain ## <- Replace the domain with theirs.com domain
70
+
group: mygroup
71
+
kind: ExternalType
72
+
version: v1alpha1
73
+
version: "3"
47
74
```
48
75
49
-
## Edit the API files.
76
+
At the same time, the generated RBAC manifests need to be adjusted:
Note that core resources may simply be imported by depending on the API's from upstream Kubernetes:
143
+
Note that core resources may simply be imported by depending on the API's from upstream Kubernetes and do not need additional `AddToScheme` registrations:
0 commit comments