Skip to content

Commit 692f5e3

Browse files
authored
Merge pull request #1221 from alexymantha/fix/register-crd-markers
🐛 Applyconfiguration: register CRD markers
2 parents 9afcc17 + db11bcd commit 692f5e3

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

pkg/applyconfiguration/applyconfiguration_integration_test.go

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,9 @@ var _ = Describe("ApplyConfiguration generation from API types", func() {
106106
By("Initializing the runtime")
107107
optionsRegistry := &markers.Registry{}
108108
Expect(genall.RegisterOptionsMarkers(optionsRegistry)).To(Succeed())
109-
Expect(optionsRegistry.Register(markers.Must(markers.MakeDefinition("crd", markers.DescribesPackage, crd.Generator{})))).To(Succeed())
110109
Expect(optionsRegistry.Register(markers.Must(markers.MakeDefinition("applyconfiguration", markers.DescribesPackage, Generator{})))).To(Succeed())
111110

112111
rt, err := genall.FromOptions(optionsRegistry, []string{
113-
"crd:allowDangerousTypes=true,ignoreUnexportedFields=true", // Run another generator first to make sure they don't interfere; see also: the comment on cronjob_types.go:UntypedBlob
114112
"applyconfiguration",
115113
"paths=./api/v1",
116114
})
@@ -202,6 +200,41 @@ var _ = Describe("ApplyConfiguration generation from API types", func() {
202200
Entry("with the an alternative output package", "other"),
203201
Entry("with a package outside of the current directory", "../../clients"),
204202
)
203+
204+
DescribeTable("should be able to run another generator for the CronJob schema without interfering", func(outputPackage string) {
205+
Expect(replaceOutputPkgMarker("./api/v1", outputPackage)).To(Succeed())
206+
207+
// The output is used to capture the generated CRD file.
208+
// The output of the applyconfiguration cannot be generated to memory, gengo handles all of the writing to disk directly.
209+
output := make(outputToMap)
210+
211+
By("Initializing the runtime")
212+
optionsRegistry := &markers.Registry{}
213+
generator := Generator{}
214+
Expect(genall.RegisterOptionsMarkers(optionsRegistry)).To(Succeed())
215+
Expect(optionsRegistry.Register(markers.Must(markers.MakeDefinition("crd", markers.DescribesPackage, crd.Generator{})))).To(Succeed())
216+
Expect(optionsRegistry.Register(markers.Must(markers.MakeDefinition("applyconfiguration", markers.DescribesPackage, generator)))).To(Succeed())
217+
Expect(generator.RegisterMarkers(optionsRegistry)).To(Succeed())
218+
219+
rt, err := genall.FromOptions(optionsRegistry, []string{
220+
"crd:allowDangerousTypes=true,ignoreUnexportedFields=true", // Run another generator first to make sure they don't interfere; see also: the comment on cronjob_types.go:UntypedBlob
221+
"applyconfiguration",
222+
"paths=./api/v1",
223+
})
224+
Expect(err).NotTo(HaveOccurred())
225+
226+
rt.OutputRules = genall.OutputRules{Default: output}
227+
228+
By("Running the generator")
229+
hadErrs := rt.Run()
230+
231+
By("Checking for generation errors")
232+
Expect(hadErrs).To(BeFalse(), "Generator should run without errors")
233+
},
234+
Entry("with the default applyconfiguration output package", "applyconfiguration"),
235+
Entry("with the an alternative output package", "other"),
236+
Entry("with a package outside of the current directory", "../../clients"),
237+
)
205238
})
206239

207240
func replaceOutputPkgMarker(dir string, newOutputPackage string) error {

pkg/applyconfiguration/gen.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ func (Generator) RegisterMarkers(into *markers.Registry) error {
7272
return err
7373
}
7474

75+
if err := crdmarkers.Register(into); err != nil {
76+
return err
77+
}
78+
7579
into.AddHelp(isCRDMarker,
7680
markers.SimpleHelp("apply", "enables apply configuration generation for this type"))
7781
into.AddHelp(

0 commit comments

Comments
 (0)