Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kubebuilder with multi-group and same Kind names doesn't generate proper crd/patch and rbac manifests #2495

Closed
rmb938 opened this issue Jan 25, 2022 · 4 comments · Fixed by #2500
Labels
kind/bug Categorizes issue or PR as related to a bug.

Comments

@rmb938
Copy link
Contributor

rmb938 commented Jan 25, 2022

What broke? What's expected?

In a multi-group project when 2 groups have the same CRD name for example

---
apiVersion: foo.rmb938.com/v1alpha1
kind: Bar
...
---
apiVersion: faz.rmb938.com/v1alpha1
kind: Bar

The crd patches generated in config/crd/patches and the rbac generated (for viewer and editor) in config/rbac are only for the first group and kind that gets generated. They should be generated for all groups.

Reproducing this issue

Run the following

kubebuilder create api --controller=false --group foo --version v1alpha1 --kind Bar
kubebuilder create api --controller=false --group faz --version v1alpha1 --kind Bar

KubeBuilder (CLI) Version

Version: main.version{KubeBuilderVersion:"3.3.0", KubernetesVendor:"1.23.1", GitCommit:"47859bf2ebf96a64db69a2f7074ffdec7f15c1ec", BuildDate:"2022-01-18T17:03:29Z", GoOs:"darwin", GoArch:"amd64"}

PROJECT version

3

Plugin versions

layout:
- go.kubebuilder.io/v3

Other versions

 %  go version
go version go1.17.3 darwin/amd64
sigs.k8s.io/controller-runtime v0.11.0
sigs.k8s.io/controller-tools/cmd/controller-gen@v0.8.0
%  kubectl version
Client Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.2", GitCommit:"f5743093fd1c663cb0cbc89748f730662345d44d", GitTreeState:"clean", BuildDate:"2020-09-16T21:51:21Z", GoVersion:"go1.15.2", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"21", GitVersion:"v1.21.5-gke.1302", GitCommit:"639f3a74abf258418493e9b75f2f98a08da29733", GitTreeState:"clean", BuildDate:"2021-10-21T21:35:48Z", GoVersion:"go1.16.7b7", Compiler:"gc", Platform:"linux/amd64"}
%  kustomize version
{Version:kustomize/v4.4.0 GitCommit:63ec6bdb3d737a7c66901828c5743656c49b60e1 BuildDate:2021-09-27T16:13:36Z GoOs:darwin GoArch:amd64}

Extra Labels

No response

@rmb938 rmb938 added the kind/bug Categorizes issue or PR as related to a bug. label Jan 25, 2022
@camilamacedo86
Copy link
Member

Hi @rmb938,

Could you please provide some additional info?

  1. Are the multi-group support enabled in your project? see: https://book.kubebuilder.io/migration/multi-group.html
  2. Could you please copy and paste here the PROJECT file content?

See that we have sample projects generated at testdata/ directory and I could not find the issue raised by you in the project which has multi-group support (see, kubebuilder/testdata/project-v3-multigroup).

The crd patches generated in config/crd/patches and the rbac generated (for viewer and editor) in config/rbac are only for the first group and kind that gets generated. They should be generated for all groups.

Note the config/crd/patches generated for all groups:

Also, see the rbac generated for all: https://github.com/kubernetes-sigs/kubebuilder/tree/master/testdata/project-v3-multigroup/config/rbac

If you want see how the sample/testdata project is generated see the script: https://github.com/kubernetes-sigs/kubebuilder/blob/master/test/testdata/generate.sh

@rmb938
Copy link
Contributor Author

rmb938 commented Jan 30, 2022

I created a kubebuilder project and push it to a repo for easy reference.

PROJECT file: https://github.com/rmb938/multi-group-test/blob/main/PROJECT as you can see there's 2 groups each with a kind that is named the same.

APIs https://github.com/rmb938/multi-group-test/tree/main/apis

Controllers https://github.com/rmb938/multi-group-test/tree/main/controllers

CRD Patches https://github.com/rmb938/multi-group-test/tree/main/config/crd/patches Notice they only exist for the single group foo, the one for group fiz does not exist.

RBAC https://github.com/rmb938/multi-group-test/tree/main/config/rbac notice that the editor and viewer roles only exist for foo not for fiz.

You can replicate this project by running the following commands:

kubebuilder init --domain rmb938.com --repo github.com/rmb938/multi-group-test
kubebuilder edit --multigroup=true
kubebuilder create api --group foo --version v1alpha1 --kind Bar
kubebuilder create api --group fiz --version v1alpha1 --kind Bar
make generate
make manifests

@camilamacedo86
Copy link
Member

camilamacedo86 commented Jan 30, 2022

Hi @rmb938,

Thank you for the clarifications

That shows that when the multi-group support is enabled we are not using the group in the name of the files and generating them. So we need to:

a) Ensure that we will consider the group to do the scaffolds

Such as, change the boilerplates to use the group, see: https://github.com/kubernetes-sigs/kubebuilder/tree/master/pkg/plugins/common/kustomize/v1/scaffolds/internal/templates/config/crd/patches. In the same way that we do here (https://github.com/kubernetes-sigs/kubebuilder/blob/master/pkg/plugins/golang/v2/scaffolds/internal/templates/api/group.go#L37-L43). ( The same implementation actually)

b) Update the sample/testdata to have the same kind for different groups to ensure the scenario
The change must be done in: https://github.com/kubernetes-sigs/kubebuilder/blob/master/test/testdata/generate.sh for the sample kubebuilder/testdata/project-v3-multigroup.

Could you help out with this fix? WDYT about a collab with a PR to fix this scenario?

@rmb938
Copy link
Contributor Author

rmb938 commented Jan 30, 2022

Yup I can get that done. I've been working on some internal kubebuilder scaffolds myself so I'm familiar with the modifications. I'll get the changes committed and a PR ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug.
Projects
None yet
2 participants