Skip to content

Generate alpha command do not respect API namespacing #3969

Closed
@antonincms

Description

@antonincms

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedDenotes an issue that needs help from a contributor. Must meet "help wanted" guidelines.kind/bugCategorizes issue or PR as related to a bug.priority/backlogHigher priority than priority/awaiting-more-evidence.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions