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
@@ -16,11 +16,17 @@ The recommended upgrade approach is to follow the [Migration Guide go/v3 to go/v
16
16
17
17
## Migration from project config version "go/v3" to "go/v4"
18
18
19
-
Update `PROJECT` file layout which stores the information about the resources are use to enable plugins to make useful decisions when scaffolding.
19
+
Update the `PROJECT` file layout which stores information about the resources that are used to enable plugins make
20
+
useful decisions while scaffolding. The `layout` field indicates the scaffolding and the primary plugin version in use.
20
21
21
-
Furthermore, the `PROJECT` file itself is now versioned. The `version` field corresponds to the version of the `PROJECT` file itself, while the `layout` field indicates the scaffolding and the primary plugin version in use.
22
+
### Steps to migrate
23
+
24
+
#### Migrate the layout version into the PROJECT file
25
+
26
+
The following steps describe the manual changes required to bring the project configuration file (`PROJECT`).
27
+
These change will add the information that Kubebuilder would add when generating the file. This file can be found in the root directory.
22
28
23
-
Update:
29
+
Update the PROJECT file by replacing:
24
30
25
31
```yaml
26
32
layout:
@@ -35,34 +41,150 @@ layout:
35
41
36
42
```
37
43
38
-
### Steps to migrate
44
+
#### Changes to the layout
39
45
40
-
- Update the `main.go` with the changes which can be found in the samples under testdata for the release tag used. (see for example `testdata/project-v4/main.go`).
41
-
- Update the Makefile with the changes which can be found in the samples under testdata for the release tag used. (see for example `testdata/project-v4/Makefile`)
42
-
- Update the `go.mod` with the changes which can be found in the samples under `testdata` for the release tag used. (see for example `testdata/project-v4/go.mod`). Then, run
43
-
`go mod tidy`to ensure that you get the latest dependencies and your Golang code has no breaking changes.
44
-
- Update the manifest under `config/` directory with all changes performed in the default scaffold done with `go/v4-alpha` plugin. (see for example `testdata/project-v4/config/`) to get all changes in the
45
-
default scaffolds to be applied on your project
46
-
- Create `config/samples/kustomization.yaml` with all CR samples specified. (see for example `testdata/project-v4/config/samples/kustomization.yaml`)
47
-
- Replace the import `admissionv1beta1 "k8s.io/api/admission/v1beta1"` with `admissionv1 "k8s.io/api/admission/v1"` in the webhook test files
46
+
##### New layout:
47
+
48
+
- The directory `apis` was renamed to `api` to follow the standard
49
+
- The `controller(s)` directory has been moved under a new directory called `internal` and renamed to singular as well `controller`
50
+
- The `main.go` previously scaffolded in the root directory has been moved under a new directory called `cmd`
51
+
52
+
Therefore, you can check the changes in the layout results into:
53
+
54
+
```sh
55
+
...
56
+
├── cmd
57
+
│ └── main.go
58
+
├── internal
59
+
│ └── controller
60
+
└── api
61
+
```
62
+
63
+
##### Migrating to the new layout:
64
+
65
+
- Create a new directory `cmd` and move the `main.go` under it.
66
+
- If your project support multi-group the APIs are scaffold under a directory called `apis`. Rename this directory to `api`
67
+
- Move the `controllers` directory under the `internal` and rename it for `controller`
68
+
- Now ensure that the imports will be updated accordingly by:
69
+
- Update the `main.go` imports to look for the new path of your controllers under the `pkg` directory
70
+
71
+
**Then, let's update the scaffolds paths**
72
+
73
+
- Update the Dockerfile to ensure that you will have:
74
+
75
+
```
76
+
COPY cmd/main.go cmd/main.go
77
+
COPY api/ api/
78
+
COPY internal/controller/ internal/controller/
79
+
```
80
+
81
+
Then, replace:
82
+
83
+
```
84
+
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager main.go
85
+
86
+
```
87
+
88
+
With:
89
+
90
+
```
91
+
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go
92
+
```
93
+
94
+
- Update the Makefile targets to build and run the manager by replacing:
95
+
96
+
```
97
+
.PHONY: build
98
+
build: manifests generate fmt vet ## Build manager binary.
99
+
go build -o bin/manager main.go
100
+
101
+
.PHONY: run
102
+
run: manifests generate fmt vet ## Run a controller from your host.
103
+
go run ./main.go
104
+
```
105
+
106
+
With:
107
+
108
+
```
109
+
.PHONY: build
110
+
build: manifests generate fmt vet ## Build manager binary.
111
+
go build -o bin/manager cmd/main.go
112
+
113
+
.PHONY: run
114
+
run: manifests generate fmt vet ## Run a controller from your host.
115
+
go run ./cmd/main.go
116
+
```
117
+
118
+
- Update the `internal/controller/suite_test.go` to set the path for the `CRDDirectoryPaths`:
### Update kustomize manifests with the changes made so far
153
+
154
+
- Update the manifest under `config/` directory with all changes performed in the default scaffold done with `go/v4-alpha` plugin. (see for example `testdata/project-v4/config/`) to get all changes in the
155
+
default scaffolds to be applied on your project
156
+
- Create `config/samples/kustomization.yaml` with all Custom Resources samples specified into `config/samples`. _(see for example `testdata/project-v4/config/samples/kustomization.yaml`)_
48
157
49
158
<aside class="warning">
50
159
<h1>`config/` directory with changes into the scaffold files</h1>
51
160
52
161
Note that under the `config/` directory you will find scaffolding changes since using
53
162
`go/v4-alpha`you will ensure that you are no longer using Kustomize v3x.
54
163
55
-
You can mainly compare the `config/` directory from the samples scaffolded under the `testdata`directory by
164
+
You can mainly compare the `config/` directory from the samples scaffolded under the `testdata`directory by
56
165
checking the differences between the `testdata/project-v3/config/` with `testdata/project-v4/config/` which
57
166
are samples created with the same commands with the only difference being versions.
58
167
59
168
However, note that if you create your project with Kubebuilder CLI 3.0.0, its scaffolds
60
-
might change to accommodate changes up to the latest releases using `go/v3` which are not considered
61
-
breaking for users and/or are forced by the changes introduced in the dependencies
62
-
used by the project such as [controller-runtime][controller-runtime] and [controller-tools][controller-tools].
169
+
might change to accommodate changes up to the latest releases using `go/v3` which are not considered
170
+
breaking for users and/or are forced by the changes introduced in the dependencies
171
+
used by the project such as [controller-runtime][controller-runtime] and [controller-tools][controller-tools].
63
172
64
173
</aside>
65
174
175
+
### If you have webhooks:
176
+
177
+
Replace the import `admissionv1beta1 "k8s.io/api/admission/v1beta1"` with `admissionv1 "k8s.io/api/admission/v1"` in the webhook test files
178
+
179
+
### Makefile updates
180
+
181
+
Update the Makefile with the changes which can be found in the samples under testdata for the release tag used. (see for example `testdata/project-v4/Makefile`)
182
+
183
+
### Update the dependencies
184
+
185
+
Update the `go.mod` with the changes which can be found in the samples under `testdata` for the release tag used. (see for example `testdata/project-v4/go.mod`). Then, run
186
+
`go mod tidy`to ensure that you get the latest dependencies and your Golang code has no breaking changes.
187
+
66
188
### Verification
67
189
68
190
In the steps above, you updated your project manually with the goal of ensuring that it follows
Copy file name to clipboardExpand all lines: docs/book/src/migration/v3vsv4.md
+3Lines changed: 3 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,6 +20,8 @@ The details of all changes (breaking or otherwise) can be found in:
20
20
- no longer scaffold webhook test files with `"k8s.io/api/admission/v1beta1"` the k8s API which is no longer served since k8s `1.25`. By default
21
21
webhooks test files are scaffolding using `"k8s.io/api/admission/v1"` which is support from k8s `1.20`
22
22
- no longer provide backwards compatible support with k8s versions < `1.16`
23
+
- change the layout to accommodate the community request to follow the [Standard Go Project Layout][standard-go-project]
24
+
by moving the api(s) under a new directory called `api`, controller(s) under a new directory called `internal` and the `main.go` under a new directory named `cmd`
23
25
24
26
<asideclass="note">
25
27
<H1> TL;DR of the New `go/v4-alpha` Plugin </H1>
@@ -86,3 +88,4 @@ This way is more complex, susceptible to errors, and success cannot be assured.
0 commit comments