Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 add error check when no apiType is provided for reconciliation #1182

Merged
merged 1 commit into from
Sep 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/builder/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ func (blder *Builder) Build(r reconcile.Reconciler) (controller.Controller, erro
if blder.forInput.err != nil {
return nil, blder.forInput.err
}
// Checking the reconcile type exist or not
if blder.forInput.object == nil {
return nil, fmt.Errorf("must provide an object for reconciliation")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use errors.New for error messages without a format string

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alvaroaleman In the same func, fmt.Errorf is used for other errors which do not have a format string. IMHO this needs to be fixed horizontally for all such error messages.

}

// Set the Config
blder.loadRestConfig()
Expand Down
12 changes: 12 additions & 0 deletions pkg/builder/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ var _ = Describe("application", func() {
Expect(instance).To(BeNil())
})

It("should return an error if For function is not called", func() {
By("creating a controller manager")
m, err := manager.New(cfg, manager.Options{})
Expect(err).NotTo(HaveOccurred())

instance, err := ControllerManagedBy(m).
Owns(&appsv1.ReplicaSet{}).
Build(noop)
Expect(err).To(MatchError(ContainSubstring("must provide an object for reconciliation")))
Expect(instance).To(BeNil())
})

It("should return an error if there is no GVK for an object, and thus we can't default the controller name", func() {
By("creating a controller manager")
m, err := manager.New(cfg, manager.Options{})
Expand Down