Skip to content

Commit 1502ede

Browse files
authored
Merge pull request #2785 from camilamacedo86/gov4
✨ (go/v4-alpha) new alpha plugin using kustomize v4 (add support for Apple Silicon)
2 parents cddf6b4 + c04f181 commit 1502ede

File tree

498 files changed

+15581
-728
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

498 files changed

+15581
-728
lines changed

cmd/main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
cfgv2 "sigs.k8s.io/kubebuilder/v3/pkg/config/v2"
2626
cfgv3 "sigs.k8s.io/kubebuilder/v3/pkg/config/v3"
2727
"sigs.k8s.io/kubebuilder/v3/pkg/machinery"
28+
"sigs.k8s.io/kubebuilder/v3/pkg/model/stage"
2829
"sigs.k8s.io/kubebuilder/v3/pkg/plugin"
2930
kustomizecommonv1 "sigs.k8s.io/kubebuilder/v3/pkg/plugins/common/kustomize/v1"
3031
kustomizecommonv2alpha "sigs.k8s.io/kubebuilder/v3/pkg/plugins/common/kustomize/v2-alpha"
@@ -43,6 +44,11 @@ func main() {
4344
kustomizecommonv1.Plugin{},
4445
golangv3.Plugin{},
4546
)
47+
// Bundle plugin which built the golang projects scaffold by Kubebuilder go/v3 with kustomize alpha-v2
48+
gov4Bundle, _ := plugin.NewBundle(golang.DefaultNameQualifier, plugin.Version{Number: 4, Stage: stage.Alpha},
49+
kustomizecommonv2alpha.Plugin{},
50+
golangv3.Plugin{},
51+
)
4652

4753
fs := machinery.Filesystem{
4854
FS: afero.NewOsFs(),
@@ -59,6 +65,7 @@ func main() {
5965
golangv2.Plugin{},
6066
golangv3.Plugin{},
6167
gov3Bundle,
68+
gov4Bundle,
6269
&kustomizecommonv1.Plugin{},
6370
&kustomizecommonv2alpha.Plugin{},
6471
&declarativev1.Plugin{},

docs/book/src/SUMMARY.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,12 @@
111111
- [Available Plugins](./plugins/available-plugins.md)
112112
- [go/v2 plugin (Deprecated)](./plugins/go-v2-plugin.md)
113113
- [go/v3 plugin](./plugins/go-v3-plugin.md)
114-
- [Declarative V1](./plugins/declarative-v1.md)
115-
- [grafana/v1-alpha](./plugins/grafana-v1-alpha.md)
114+
- [go/v4-alpha plugin](./plugins/go-v4-plugin.md)
116115
- [Kustomize V1](./plugins/kustomize-v1.md)
116+
- [Kustomize v2 Alpha](./plugins/kustomize-v2-alpha.md)
117+
- [Declarative V1 (Optional Feature)](./plugins/declarative-v1.md)
118+
- [Grafana V1 Alpha (Optional Feature)](./plugins/grafana-v1-alpha.md)
119+
- [Deploy Image V1 Alpha (Optional Feature)](./plugins/deploy-image-plugin-v1-alpha.md)
117120
- [Plugins Versioning](./plugins/plugins-versioning.md)
118121

119122
---

docs/book/src/migration/migration_guide_v2tov3.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,6 @@ not needed inside `GOPATH`, it is still recommended.
3636
```bash
3737
go mod init tutorial.kubebuilder.io/migration-project
3838
```
39-
<aside class="note warning">
40-
<h1> Migrating to Kubebuilder v3 while staying on the go/v2 plugin </h1>
41-
42-
You can use `--plugins=go/v2` if you wish to continue using "`Kubebuilder 2.x`" layout.
43-
However, with the legacy layout you are unable to produce projects supported
44-
on Kubernetes versions >= `1.22`. Therefore, it is not recommended.
45-
46-
</aside>
4739

4840
<aside class="note">
4941
<h1>The module of your project can found in the in the `go.mod` file at the root of your project:</h1>

docs/book/src/migration/v2vsv3.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,21 @@ For example, you should refrain from moving the scaffolded files, doing so will
6060

6161
So you want to upgrade your scaffolding to use the latest and greatest features then, follow up the following guide which will cover the steps in the most straightforward way to allow you to upgrade your project to get all latest changes and improvements.
6262

63+
<aside class="note warning">
64+
<h1> Apple Silicon (M1) </h1>
65+
66+
The current scaffold done by the CLI (`go/v3`) uses [kubernetes-sigs/kustomize][kustomize] v3 which does not provide
67+
a valid binary for Apple Silicon (`darwin/arm64`). Therefore, you can use the `go/v4-alpha` plugin
68+
instead which provides support for this platform:
69+
70+
```bash
71+
kubebuilder init --domain my.domain --repo my.domain/guestbook --plugins=go/v4-alpha
72+
```
73+
74+
**Note**: The `go/v4-alpha` plugin is an unstable version and can have breaking changes in future releases.
75+
The steps to migrate your project from v2 to v3 using the `alpha` scaffold are the same.
76+
</aside>
77+
6378
- [Migration Guide v2 to V3][migration-guide-v2-to-v3] **(Recommended)**
6479

6580
### By updating the files manually
@@ -87,4 +102,5 @@ You will check that you can still using the previous layout by using the `go/v2`
87102
[cert-manager-docs]: https://cert-manager.io/docs/installation/upgrading/
88103
[kb-releases]: https://github.com/kubernetes-sigs/kubebuilder/releases
89104
[kube-rbac-proxy]: https://github.com/brancz/kube-rbac-proxy/releases
90-
[basic-project-doc]: ../cronjob-tutorial/basic-project.md
105+
[basic-project-doc]: ../cronjob-tutorial/basic-project.md
106+
[kustomize]: https://github.com/kubernetes-sigs/kustomize

docs/book/src/plugins/go-v4-plugin.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# go/v4-alpha (go.kubebuilder.io/v4-alpha)
2+
3+
Kubebuilder will scaffold using the go/v4-alpha plugin only if specified when initializing the project.
4+
This plugin is a composition of the plugins ` kustomize.common.kubebuilder.io/v2-alpha` and `base.go.kubebuilder.io/v3`.
5+
It scaffolds a project template that helps in constructing sets of [controllers][controller-runtime].
6+
7+
It scaffolds boilerplate code to create and design controllers.
8+
Note that by following the [quickstart][quickstart] you will be using this plugin.
9+
<aside class="note">
10+
11+
<h1>Examples</h1>
12+
13+
You can check samples using this plugin by looking at the `project-v4-<options>` projects
14+
under the [testdata][testdata] directory on the root directory of the Kubebuilder project.
15+
16+
</aside>
17+
18+
## When to use it ?
19+
20+
- If you are looking to scaffold Golang projects to develop projects using [controllers][controller-runtime]
21+
- If you are looking to experiment with the future default scaffold that will be provided by Kubebuilder CLI
22+
- If your local environment is Apple Silicon (`darwin/arm64`)
23+
- If you are looking to use [kubernetes-sigs/kustomize][kustomize] v4
24+
25+
## How to use it ?
26+
27+
To create a new project with the `go/v4-alpha` plugin the following command can be used:
28+
29+
```sh
30+
kubebuilder init --domain tutorial.kubebuilder.io --repo tutorial.kubebuilder.io/project --plugins=go/v4-alpha
31+
```
32+
33+
## Subcommands supported by the plugin
34+
35+
- Init - `kubebuilder init [OPTIONS]`
36+
- Edit - `kubebuilder edit [OPTIONS]`
37+
- Create API - `kubebuilder create api [OPTIONS]`
38+
- Create Webhook - `kubebuilder create webhook [OPTIONS]`
39+
40+
## Further resources
41+
42+
- To see the composition of plugins, you can check the source code for the Kubebuilder [main.go][plugins-main].
43+
- Check the code implementation of the [base Golang plugin `base.go.kubebuilder.io/v3`][v3-plugin].
44+
- Check the code implementation of the [Kustomize/v2-alpha plugin][kustomize-plugin].
45+
- Check [controller-runtime][controller-runtime] to know more about controllers.
46+
47+
[controller-runtime]: https://github.com/kubernetes-sigs/controller-runtime
48+
[quickstart]: ../quick-start.md
49+
[testdata]: https://github.com/kubernetes-sigs/kubebuilder/tree/master/testdata
50+
[plugins-main]: https://github.com/kubernetes-sigs/kubebuilder/blob/master/cmd/main.go
51+
[kustomize-plugin]: ../plugins/kustomize-v2-alpha.md
52+
[kustomize]: https://github.com/kubernetes-sigs/kustomize

docs/book/src/quick-start.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,20 @@ Kubebuilder provides autocompletion support for Bash and Zsh via the command `ku
5353

5454
Create a directory, and then run the init command inside of it to initialize a new project. Follows an example.
5555

56+
<aside class="note warning">
57+
<h1> Apple Silicon (M1) </h1>
58+
59+
The current scaffold done by the CLI (`go/v3`) uses [kubernetes-sigs/kustomize][kustomize] v3 which does not provide
60+
a valid binary for Apple Silicon (`darwin/arm64`). Therefore, you can use the `go/v4-alpha` plugin
61+
instead which provides support for this platform:
62+
63+
```bash
64+
kubebuilder init --domain my.domain --repo my.domain/guestbook --plugins=go/v4-alpha
65+
```
66+
67+
**Note**: The `go/v4-alpha` plugin is an unstable version and can have breaking changes in future releases.
68+
</aside>
69+
5670
```bash
5771
mkdir -p ~/projects/guestbook
5872
cd ~/projects/guestbook
@@ -236,3 +250,4 @@ Now, see the [architecture concept diagram][architecture-concept-diagram] for a
236250
[go-modules-blogpost]: https://blog.golang.org/using-go-modules
237251
[envtest]: https://book.kubebuilder.io/reference/testing/envtest.html
238252
[architecture-concept-diagram]: architecture.md
253+
[kustomize]: https://github.com/kubernetes-sigs/kustomize

pkg/plugins/golang/v3/scaffolds/init.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,11 @@ func (s *initScaffolder) Scaffold() error {
106106
// in order to support it
107107
kustomizeVersion = kustomizecommonv1.KustomizeVersion
108108
kustomizev2 := kustomizecommonv2alpha.Plugin{}
109+
gov4alpha := "go.kubebuilder.io/v4-alpha"
109110
pluginKeyForKustomizeV2 := plugin.KeyFor(kustomizev2)
110111

111112
for _, pluginKey := range s.config.GetPluginChain() {
112-
if pluginKey == pluginKeyForKustomizeV2 {
113+
if pluginKey == pluginKeyForKustomizeV2 || pluginKey == gov4alpha {
113114
kustomizeVersion = kustomizecommonv2alpha.KustomizeVersion
114115
break
115116
}

test/e2e/setup.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function test_cluster {
6262
docker pull busybox:1.28
6363
kind load docker-image --name $KIND_CLUSTER busybox:1.28
6464

65-
go test $(dirname "$0")/deployimage $flags
66-
go test $(dirname "$0")/v2 $flags
65+
go test $(dirname "$0")/deployimage $flags -timeout 30m
6766
go test $(dirname "$0")/v3 $flags -timeout 30m
67+
go test $(dirname "$0")/v4 $flags -timeout 30m
6868
}

0 commit comments

Comments
 (0)