Skip to content

Commit dba75e5

Browse files
authored
Merge pull request #1182 from prafull01/no-apitype
🐛 add error check when no apiType is provided for reconciliation
2 parents 6af4e7c + 606344e commit dba75e5

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

pkg/builder/controller.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@ func (blder *Builder) Build(r reconcile.Reconciler) (controller.Controller, erro
167167
if blder.forInput.err != nil {
168168
return nil, blder.forInput.err
169169
}
170+
// Checking the reconcile type exist or not
171+
if blder.forInput.object == nil {
172+
return nil, fmt.Errorf("must provide an object for reconciliation")
173+
}
170174

171175
// Set the Config
172176
blder.loadRestConfig()

pkg/builder/controller_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,18 @@ var _ = Describe("application", func() {
104104
Expect(instance).To(BeNil())
105105
})
106106

107+
It("should return an error if For function is not called", func() {
108+
By("creating a controller manager")
109+
m, err := manager.New(cfg, manager.Options{})
110+
Expect(err).NotTo(HaveOccurred())
111+
112+
instance, err := ControllerManagedBy(m).
113+
Owns(&appsv1.ReplicaSet{}).
114+
Build(noop)
115+
Expect(err).To(MatchError(ContainSubstring("must provide an object for reconciliation")))
116+
Expect(instance).To(BeNil())
117+
})
118+
107119
It("should return an error if there is no GVK for an object, and thus we can't default the controller name", func() {
108120
By("creating a controller manager")
109121
m, err := manager.New(cfg, manager.Options{})

0 commit comments

Comments
 (0)