Skip to content

Commit 024627e

Browse files
authored
Merge pull request #752 from ryanbrainard/external-type-testing-doc
Doc Clarification: Using an External Type
2 parents cdde9b2 + 021db9f commit 024627e

File tree

1 file changed

+34
-25
lines changed

1 file changed

+34
-25
lines changed

docs/using_an_external_type.md

+34-25
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Using an external Type
1+
# Using an External Type
22

33

44
# Introduction
@@ -19,13 +19,15 @@ you will need to have several items of information.
1919

2020
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.
2121

22-
Example API Aggregation directory structure
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.
23+
24+
Example external API Aggregation directory structure
2325
```
2426
github.com
25-
├── example
26-
├── myproject
27+
├── theiruser
28+
├── theirproject
2729
├── apis
28-
├── mygroup
30+
├── theirgroup
2931
├── doc.go
3032
├── install
3133
│   ├── install.go
@@ -36,7 +38,7 @@ github.com
3638
│   ├── zz_generated.deepcopy.go
3739
```
3840

39-
In the case above the import path would be `github.com/example/myproject/apis/mygroup/v1alpha1`
41+
In the case above the import path would be `github.com/theiruser/theirproject/apis/theirgroup/v1alpha1`
4042

4143
### Create a project
4244

@@ -48,60 +50,73 @@ kubebuilder init --domain $APIDOMAIN --owner "MyCompany"
4850

4951
be sure to answer no when it asks if you would like to create an api? [Y/n]
5052
```
51-
kubebuilder create api --group $APIGROUP --version $APIVERSION --kind MyKind
53+
kubebuilder create api --group mygroup --version $APIVERSION --kind MyKind
5254
5355
```
5456

55-
## Edit the Api files.
57+
## Edit the API files.
5658

5759
### Register your Types
5860

59-
Add the following file to the pkg/apis directory
61+
Edit the following file to the pkg/apis directory to append their `AddToScheme` to your `AddToSchemes`:
6062

6163
file: pkg/apis/mytype_addtoscheme.go
6264
```
6365
package apis
6466
6567
import (
66-
mygroupv1alpha1 "github.com/username/myapirepo/apis/mygroup/v1alpha1"
68+
mygroupv1alpha1 "github.com/myuser/myrepo/apis/mygroup/v1alpha1"
69+
theirgroupv1alpha1 "github.com/theiruser/theirproject/apis/theirgroup/v1alpha1"
6770
)
6871
6972
func init() {
7073
// Register the types with the Scheme so the components can map objects
7174
// to GroupVersionKinds and back
72-
AddToSchemes = append(AddToSchemes, mygroupv1alpha1.AddToScheme)
75+
AddToSchemes = append(
76+
AddToSchemes,
77+
mygroupv1alpha1.SchemeBuilder.AddToScheme,
78+
theirgroupv1alpha1.SchemeBuilder.AddToScheme,
79+
)
7380
}
7481
7582
```
7683

7784
## Edit the Controller files
7885

79-
### Use the correct import for your api
86+
### Use the correct imports for your API
8087

8188
file: pkg/controllers/mytype_controller.go
8289
```
83-
import mygroupv1alpha1 "github.com/example/myproject/apis/mygroup/v1alpha1"
90+
import (
91+
mygroupv1alpha1 "github.com/myuser/myrepo/apis/mygroup/v1alpha1"
92+
theirgroupv1alpha1 "github.com/theiruser/theirproject/apis/theirgroup/v1alpha1"
93+
)
94+
```
8495

96+
### Update dependencies
97+
98+
```
99+
dep ensure --add
85100
```
86101

87102
## Prepare for testing
88103

89104
#### Register your resource
90105

91-
Add the registration code to the test framework
106+
Edit the `CRDDirectoryPaths` in your test suite by appending the path to their CRDs:
92107

93-
file pkg/controller/my_agg_resource_controller_suite_test.go
108+
file pkg/controller/my_kind_controller_suite_test.go
94109
```
95-
import (
96-
97-
)
98110
var cfg *rest.Config
99111
100112
func TestMain(m *testing.M) {
101113
// Get a config to talk to the apiserver
102114
t := &envtest.Environment{
103115
Config: cfg,
104-
CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crds")},
116+
CRDDirectoryPaths: []string{
117+
filepath.Join("..", "..", "..", "config", "crds"),
118+
filepath.Join("..", "..", "..", "vendor", "github.com", "theiruser", "theirproject", "config", "crds"),
119+
},
105120
UseExistingCluster: true,
106121
}
107122
@@ -119,12 +134,6 @@ func TestMain(m *testing.M) {
119134
120135
```
121136

122-
### Update dependencies
123-
124-
```
125-
dep ensure --add
126-
```
127-
128137
## Helpful Tips
129138

130139
### Locate your domain and group variables

0 commit comments

Comments
 (0)