Skip to content

Commit dc91124

Browse files
authored
Merge pull request #3970 from antonincms/fix-generate-api-namespacing
🐛 fix generate command not respecting --namespaced=false of APIs
2 parents 351d9e8 + 09bf649 commit dc91124

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

pkg/rescaffold/migrate.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,8 @@ func getAPIResourceFlags(resource resource.Resource) []string {
287287
args = append(args, "--resource")
288288
if resource.API.Namespaced {
289289
args = append(args, "--namespaced")
290+
} else {
291+
args = append(args, "--namespaced=false")
290292
}
291293
}
292294

test/e2e/alphagenerate/generate_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,17 @@ func ReGenerateProject(kbc *utils.TestContext) {
123123
)
124124
ExpectWithOffset(1, err).NotTo(HaveOccurred())
125125

126+
By("create APIs non namespaced with resource and controller")
127+
err = kbc.CreateAPI(
128+
"--group", "crew",
129+
"--version", "v1",
130+
"--kind", "Admiral",
131+
"--namespaced=false",
132+
"--resource",
133+
"--controller",
134+
)
135+
ExpectWithOffset(1, err).NotTo(HaveOccurred())
136+
126137
By("create APIs with deploy-image plugin")
127138
err = kbc.CreateAPI(
128139
"--group", "crew",
@@ -210,6 +221,18 @@ func ReGenerateProject(kbc *utils.TestContext) {
210221
ExpectWithOffset(1, err).NotTo(HaveOccurred())
211222
ExpectWithOffset(1, fileContainsExpr).To(BeTrue())
212223

224+
By("checking if the project file was generated without namespace: true")
225+
var nonNamespacedFields = fmt.Sprintf(`api:
226+
crdVersion: v1
227+
controller: true
228+
domain: %s
229+
group: crew
230+
kind: Admiral`, kbc.Domain)
231+
fileContainsExpr, err = pluginutil.HasFileContentWith(
232+
filepath.Join(kbc.Dir, "testdir2", "PROJECT"), nonNamespacedFields)
233+
ExpectWithOffset(1, err).NotTo(HaveOccurred())
234+
Expect(fileContainsExpr).To(BeTrue())
235+
213236
By("checking if the project file was generated with the expected deploy-image plugin fields")
214237
var deployImagePlugin = "deploy-image.go.kubebuilder.io/v1-alpha"
215238
fileContainsExpr, err = pluginutil.HasFileContentWith(

0 commit comments

Comments
 (0)