Skip to content

Commit

Permalink
:sparkling: (go/v4-alpha) new alpha plugin using kustomize v4 (add su…
Browse files Browse the repository at this point in the history
…pport for Apple Silicon)
  • Loading branch information
NikhilSharmaWe authored and camilamacedo86 committed Jul 1, 2022
1 parent dda4b5f commit a5dcd3a
Show file tree
Hide file tree
Showing 458 changed files with 17,765 additions and 612 deletions.
7 changes: 7 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
cfgv2 "sigs.k8s.io/kubebuilder/v3/pkg/config/v2"
cfgv3 "sigs.k8s.io/kubebuilder/v3/pkg/config/v3"
"sigs.k8s.io/kubebuilder/v3/pkg/machinery"
"sigs.k8s.io/kubebuilder/v3/pkg/model/stage"
"sigs.k8s.io/kubebuilder/v3/pkg/plugin"
kustomizecommonv1 "sigs.k8s.io/kubebuilder/v3/pkg/plugins/common/kustomize/v1"
kustomizecommonv2alpha "sigs.k8s.io/kubebuilder/v3/pkg/plugins/common/kustomize/v2-alpha"
Expand All @@ -43,6 +44,11 @@ func main() {
kustomizecommonv1.Plugin{},
golangv3.Plugin{},
)
// Bundle plugin which built the golang projects scaffold by Kubebuilder go/v3 with kustomize alpha-v2
gov4Bundle, _ := plugin.NewBundle(golang.DefaultNameQualifier, plugin.Version{Number: 4, Stage: stage.Alpha},
kustomizecommonv2alpha.Plugin{},
golangv3.Plugin{},
)

fs := machinery.Filesystem{
FS: afero.NewOsFs(),
Expand All @@ -59,6 +65,7 @@ func main() {
golangv2.Plugin{},
golangv3.Plugin{},
gov3Bundle,
gov4Bundle,
&kustomizecommonv1.Plugin{},
&kustomizecommonv2alpha.Plugin{},
&declarativev1.Plugin{},
Expand Down
7 changes: 5 additions & 2 deletions docs/book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,12 @@
- [Available Plugins](./plugins/available-plugins.md)
- [go/v2 plugin (Deprecated)](./plugins/go-v2-plugin.md)
- [go/v3 plugin](./plugins/go-v3-plugin.md)
- [Declarative V1](./plugins/declarative-v1.md)
- [grafana/v1-alpha](./plugins/grafana-v1-alpha.md)
- [go/v4-alpha plugin](./plugins/go-v4-plugin.md)
- [Kustomize V1](./plugins/kustomize-v1.md)
- [Kustomize v2 Alpha](./plugins/kustomize-v2-alpha.md)
- [Declarative V1 (Optional Feature)](./plugins/declarative-v1.md)
- [Grafana V1 Alpha (Optional Feature)](./plugins/grafana-v1-alpha.md)
- [Deploy Image V1 Alpha (Optional Feature)](./plugins/deploy-image-plugin-v1-alpha.md)
- [Plugins Versioning](./plugins/plugins-versioning.md)

---
Expand Down
8 changes: 0 additions & 8 deletions docs/book/src/migration/migration_guide_v2tov3.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,6 @@ not needed inside `GOPATH`, it is still recommended.
```bash
go mod init tutorial.kubebuilder.io/migration-project
```
<aside class="note warning">
<h1> Migrating to Kubebuilder v3 while staying on the go/v2 plugin </h1>

You can use `--plugins=go/v2` if you wish to continue using "`Kubebuilder 2.x`" layout.
However, with the legacy layout you are unable to produce projects supported
on Kubernetes versions >= `1.22`. Therefore, it is not recommended.

</aside>

<aside class="note">
<h1>The module of your project can found in the in the `go.mod` file at the root of your project:</h1>
Expand Down
18 changes: 17 additions & 1 deletion docs/book/src/migration/v2vsv3.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,21 @@ For example, you should refrain from moving the scaffolded files, doing so will

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.

<aside class="note warning">
<h1> Apple Silicon (M1) </h1>

The current scaffold done by the CLI (`go/v3`) uses [kubernetes-sigs/kustomize][kustomize] v3 which does not provide
a binary valid for Apple Silicon (`darwin/arm64`). Therefore, you can use the `go/v4-apha` plugin
instead which provides support for this platform:

```bash
kubebuilder init --domain my.domain --repo my.domain/guestbook --plugins=go/v4-alpha
```

**Note**: The `go/v4-alpha` stable version and can have breaking changes in future releases.
The steps to migrate your project from v2 to v3 using the `alpha` scaffold are the same.
</aside>

- [Migration Guide v2 to V3][migration-guide-v2-to-v3] **(Recommended)**

### By updating the files manually
Expand Down Expand Up @@ -87,4 +102,5 @@ You will check that you can still using the previous layout by using the `go/v2`
[cert-manager-docs]: https://cert-manager.io/docs/installation/upgrading/
[kb-releases]: https://github.com/kubernetes-sigs/kubebuilder/releases
[kube-rbac-proxy]: https://github.com/brancz/kube-rbac-proxy/releases
[basic-project-doc]: ../cronjob-tutorial/basic-project.md
[basic-project-doc]: ../cronjob-tutorial/basic-project.md
[kustomize]: https://github.com/kubernetes-sigs/kustomize
52 changes: 52 additions & 0 deletions docs/book/src/plugins/go-v4-plugin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# go/v4-alpha (go.kubebuilder.io/v4-alpha)

Kubebuilder tool will scaffold the go/v4-alpha plugin only if ask for it when you create the project.
This plugin is a composition of the plugins ` kustomize.common.kubebuilder.io/v2-alpha` and `base.go.kubebuilder.io/v3`.
By using it you can scaffold a project which is a helper to construct sets of [controllers][controller-runtime].

It basically scaffolds all the boilerplate code required to create and design controllers.
Note that by following the [quickstart][quickstart] you will be using this plugin.
<aside class="note">

<h1>Examples</h1>

You can check samples using this plugin by looking at the `project-v4-<options>` projects
under the [testdata][testdata] directory on the root directory of the Kubebuilder project.

</aside>

## When to use it ?

- If you are looking to scaffold Golang projects to develop projects using [controllers][controller-runtime]
- If you are looking to experiment the future default scaffold that will be provided by Kubebuilder CLI
- If your local enviroment is Apple Silicon (`darwin/arm64`)
- If you are looking to use [kubernetes-sigs/kustomize][kustomize] v4

## How to use it ?

To create a new project with the `go/v4-alpha` plugin the following command can be used:

```sh
kubebuilder init --domain tutorial.kubebuilder.io --repo tutorial.kubebuilder.io/project --plugins=v4-alpha
```

## Subcommands supported by the plugin

- Init - `kubebuilder init [OPTIONS]`
- Edit - `kubebuilder edit [OPTIONS]`
- Create API - `kubebuilder create api [OPTIONS]`
- Create Webhook - `kubebuilder create webhook [OPTIONS]`

## Further resources

- To check how plugins are composited by looking at this definition in the [main.go][plugins-main].
- Check the code implementation of the [base Golang plugin `base.go.kubebuilder.io/v3`][v3-plugin].
- Check the code implementation of the [Kustomize/v2-alpha plugin][kustomize-plugin].
- Check [controller-runtime][controller-runtime] to know more about controllers.

[controller-runtime]: https://github.com/kubernetes-sigs/controller-runtime
[quickstart]: ../quick-start.md
[testdata]: https://github.com/kubernetes-sigs/kubebuilder/tree/master/testdata
[plugins-main]: https://github.com/kubernetes-sigs/kubebuilder/blob/master/cmd/main.go
[kustomize-plugin]: ../plugins/kustomize-v2-alpha.md
[kustomize]: https://github.com/kubernetes-sigs/kustomize
15 changes: 15 additions & 0 deletions docs/book/src/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ Kubebuilder provides autocompletion support for Bash and Zsh via the command `ku

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

<aside class="note warning">
<h1> Apple Silicon (M1) </h1>

The current scaffold done by the CLI (`go/v3`) uses [kubernetes-sigs/kustomize][kustomize] v3 which does not provide
a binary valid for Apple Silicon (`darwin/arm64`). Therefore, you can use the `go/v4-apha` plugin
instead which provides support for this platform:

```bash
kubebuilder init --domain my.domain --repo my.domain/guestbook --plugins=go/v4-alpha
```

**Note**: The `go/v4-alpha` stable version and can have breaking changes in future releases.
</aside>

```bash
mkdir -p ~/projects/guestbook
cd ~/projects/guestbook
Expand Down Expand Up @@ -236,3 +250,4 @@ Now, see the [architecture concept diagram][architecture-concept-diagram] for a
[go-modules-blogpost]: https://blog.golang.org/using-go-modules
[envtest]: https://book.kubebuilder.io/reference/testing/envtest.html
[architecture-concept-diagram]: architecture.md
[kustomize]: https://github.com/kubernetes-sigs/kustomize
4 changes: 2 additions & 2 deletions test/e2e/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function test_cluster {
docker pull busybox:1.28
kind load docker-image --name $KIND_CLUSTER busybox:1.28

go test $(dirname "$0")/deployimage $flags
go test $(dirname "$0")/v2 $flags
go test $(dirname "$0")/deployimage $flags -timeout 30m
go test $(dirname "$0")/v3 $flags -timeout 30m
go test $(dirname "$0")/v4 $flags -timeout 30m
}
Loading

0 comments on commit a5dcd3a

Please sign in to comment.