Skip to content

Commit

Permalink
Merge pull request #3970 from antonincms/fix-generate-api-namespacing
Browse files Browse the repository at this point in the history
🐛 fix generate command not respecting --namespaced=false of APIs
  • Loading branch information
k8s-ci-robot committed Jun 9, 2024
2 parents 351d9e8 + 09bf649 commit dc91124
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/rescaffold/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ func getAPIResourceFlags(resource resource.Resource) []string {
args = append(args, "--resource")
if resource.API.Namespaced {
args = append(args, "--namespaced")
} else {
args = append(args, "--namespaced=false")
}
}

Expand Down
23 changes: 23 additions & 0 deletions test/e2e/alphagenerate/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,17 @@ func ReGenerateProject(kbc *utils.TestContext) {
)
ExpectWithOffset(1, err).NotTo(HaveOccurred())

By("create APIs non namespaced with resource and controller")
err = kbc.CreateAPI(
"--group", "crew",
"--version", "v1",
"--kind", "Admiral",
"--namespaced=false",
"--resource",
"--controller",
)
ExpectWithOffset(1, err).NotTo(HaveOccurred())

By("create APIs with deploy-image plugin")
err = kbc.CreateAPI(
"--group", "crew",
Expand Down Expand Up @@ -210,6 +221,18 @@ func ReGenerateProject(kbc *utils.TestContext) {
ExpectWithOffset(1, err).NotTo(HaveOccurred())
ExpectWithOffset(1, fileContainsExpr).To(BeTrue())

By("checking if the project file was generated without namespace: true")
var nonNamespacedFields = fmt.Sprintf(`api:
crdVersion: v1
controller: true
domain: %s
group: crew
kind: Admiral`, kbc.Domain)
fileContainsExpr, err = pluginutil.HasFileContentWith(
filepath.Join(kbc.Dir, "testdir2", "PROJECT"), nonNamespacedFields)
ExpectWithOffset(1, err).NotTo(HaveOccurred())
Expect(fileContainsExpr).To(BeTrue())

By("checking if the project file was generated with the expected deploy-image plugin fields")
var deployImagePlugin = "deploy-image.go.kubebuilder.io/v1-alpha"
fileContainsExpr, err = pluginutil.HasFileContentWith(
Expand Down

0 comments on commit dc91124

Please sign in to comment.