Skip to content

Commit

Permalink
fix(RELEASE-1150): add checks to fieldselectors
Browse files Browse the repository at this point in the history
This commit fixes the issue of FieldSelectors retrurn everything
when argument is nill, added checks to each function using
fieldselecor.

Signed-off-by: Happy Bhati <[email protected]>
  • Loading branch information
happybhati committed Oct 15, 2024
1 parent e091a3b commit fc70fe4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ func (l *loader) GetMatchingReleasePlanAdmission(ctx context.Context, cli client
// are in the namespace specified by the ReleasePlanAdmission's origin. If the List operation fails, an
// error will be returned.
func (l *loader) GetMatchingReleasePlans(ctx context.Context, cli client.Client, releasePlanAdmission *v1alpha1.ReleasePlanAdmission) (*v1alpha1.ReleasePlanList, error) {

if releasePlanAdmission.Spec.Origin == "" {
return nil, fmt.Errorf("releasePlanAdmission has no origin, so no ReleasePlans can be found")
}

releasePlans := &v1alpha1.ReleasePlanList{}
err := cli.List(ctx, releasePlans,
client.InNamespace(releasePlanAdmission.Spec.Origin),
Expand Down
10 changes: 10 additions & 0 deletions loader/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,16 @@ var _ = Describe("Release Adapter", Ordered, func() {
return returnedObject != &v1alpha1.ReleasePlanList{} && err == nil && contains == false
})
})

It("fails to return release plans if origin is empty", func() {
modifiedReleasePlanAdmission := releasePlanAdmission.DeepCopy()
modifiedReleasePlanAdmission.Spec.Origin = ""

returnedObject, err := loader.GetMatchingReleasePlans(ctx, k8sClient, modifiedReleasePlanAdmission)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("releasePlanAdmission has no origin, so no ReleasePlans can be found"))
Expect(returnedObject).To(BeNil())
})
})

When("calling GetPreviousRelease", func() {
Expand Down

0 comments on commit fc70fe4

Please sign in to comment.