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

Generate alpha command do not respect API namespacing #3969

Closed
antonincms opened this issue Jun 4, 2024 · 2 comments · Fixed by #3970
Closed

Generate alpha command do not respect API namespacing #3969

antonincms opened this issue Jun 4, 2024 · 2 comments · Fixed by #3970
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/bug Categorizes issue or PR as related to a bug. priority/backlog Higher priority than priority/awaiting-more-evidence.

Comments

@antonincms
Copy link
Contributor

antonincms commented Jun 4, 2024

What broke? What's expected?

When running kubebuilder alpha generate with a project containing a non-namespaced cluster, the command does not set the argument --namespaced=false.

I think the issue is this part of the function getAPIResourceFlags :

func getAPIResourceFlags(resource resource.Resource) []string {
	var args []string
	if resource.API == nil || resource.API.IsEmpty() {
		// create API without creating resource
		args = append(args, "--resource=false")
	} else {
		args = append(args, "--resource")
		if resource.API.Namespaced {
			args = append(args, "--namespaced")
		}
	}

	// [...] snip
}

Which assumes namespaced=false is the default, which cause all the resources to be namespaced.
I would be happy to propose a fix !

Reproducing this issue

When running kubebuilder alpha generate with the following PROJETC :

domain: myoperator.io
layout:
- go.kubebuilder.io/v4
projectName: myoperator
repo: github.com/myoperator/myoperator
resources:
- api:
    crdVersion: v1
  controller: true
  domain: myoperator.io
  group: core
  kind: MyResource
  path: github.com/myoperator/myoperator/api/core/v1alpha1
  version: v1alpha1
  webhooks:
    validation: true
    webhookVersion: v1
version: "3"

The following command is logged kubebuilder create api --plural myresources --group core --version v1alpha1 --kind MyResource --resource --controller which generates the following PROJECT :

domain: myoperator.io
layout:
- go.kubebuilder.io/v4
projectName: output-dir
repo: github.com/myoperator/myoperator
resources:
- api:
    crdVersion: v1
    namespaced: true
  controller: true
  domain: myoperator.io
  group: core
  kind: MyResource
  path: github.com/myoperator/myoperator/api/v1alpha1
  version: v1alpha1
  webhooks:
    validation: true
    webhookVersion: v1
version: "3"

As you can see, api.namespaced which was absent (false) before is now true.

KubeBuilder (CLI) Version

4.0.0

PROJECT version

3

Plugin versions

go.kubebuilder.io/v4

Other versions

No response

Extra Labels

No response

@antonincms antonincms added the kind/bug Categorizes issue or PR as related to a bug. label Jun 4, 2024
@camilamacedo86
Copy link
Member

Hi @antonincms

Thank you for raise this one.
If you have the time please feel free to contribute with the fix by pushing a PR.
We just need the fix + improve the test to ensure that it is covered. (https://github.com/kubernetes-sigs/kubebuilder/blob/master/test/e2e/alphagenerate/generate_test.go)

See:

@camilamacedo86 camilamacedo86 added help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. priority/backlog Higher priority than priority/awaiting-more-evidence. labels Jun 6, 2024
antonincms added a commit to antonincms/kubebuilder that referenced this issue Jun 6, 2024
Change the getAPIResourceFlags function to return `--namespaced=false` if resource.API.Namespaced and add corresponding test.
This changes is needed since currently `kubebuilder alpha migrate` always create namespaced APIs due to the default of namespaced being true.

Fixes kubernetes-sigs#3969
antonincms added a commit to antonincms/kubebuilder that referenced this issue Jun 6, 2024
Change the getAPIResourceFlags function to return `--namespaced=false` if resource.API.Namespaced and add corresponding test.
This is needed since currently `kubebuilder alpha migrate` always create namespaced APIs due to the default of namespaced being true.

Fixes kubernetes-sigs#3969
@antonincms
Copy link
Contributor Author

antonincms commented Jun 6, 2024

Hi @camilamacedo86 , thanks for the help.

I opened a PR with the corresponding changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/bug Categorizes issue or PR as related to a bug. priority/backlog Higher priority than priority/awaiting-more-evidence.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants