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 aee538f
Show file tree
Hide file tree
Showing 458 changed files with 17,784 additions and 834 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
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
14 changes: 14 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
22 changes: 3 additions & 19 deletions test/e2e/deployimage/plugin_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ var _ = Describe("kubebuilder", func() {
"#- ../prometheus", "#")).To(Succeed())

By("uncomment kustomize files to ensure that pods are restricted")
uncommentPodStandards(kbc)
utils.UncommentPodStandards(kbc)

Run(kbc, "memcached:1.4.36-alpine")
})
Expand Down Expand Up @@ -160,7 +160,7 @@ var _ = Describe("kubebuilder", func() {
"#- ../prometheus", "#")).To(Succeed())

By("uncomment kustomize files to ensure that pods are restricted")
uncommentPodStandards(kbc)
utils.UncommentPodStandards(kbc)

Run(kbc, "busybox:1.28")
})
Expand Down Expand Up @@ -284,20 +284,4 @@ func Run(kbc *utils.TestContext, imageCR string) {
// Expect(pod).To(ContainSubstring(",Running"))
// }
// }
}

func uncommentPodStandards(kbc *utils.TestContext) {
configManager := filepath.Join(kbc.Dir, "config", "manager", "manager.yaml")

//nolint:lll
if err := util.ReplaceInFile(configManager, `# TODO(user): For common cases that do not require escalating privileges
# it is recommended to ensure that all your Pods/Containers are restrictive.
# More info: https://kubernetes.io/docs/concepts/security/pod-security-standards/#restricted
# Please uncomment the following code if your project does NOT have to work on old Kubernetes
# versions < 1.19 or on vendors versions which do NOT support this field by default (i.e. Openshift < 4.11 ).
# seccompProfile:
# type: RuntimeDefault`, `seccompProfile:
type: RuntimeDefault`); err == nil {
ExpectWithOffset(1, err).NotTo(HaveOccurred())
}
}
}
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 aee538f

Please sign in to comment.