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

Fix Service.OwnedResources() to return correct result #975

Conversation

pedjak
Copy link
Contributor

@pedjak pedjak commented Jun 9, 2021

We were bitten by https://github.com/golang/go/wiki/CommonMistakes#using-reference-to-loop-iterator-variable

Fixed the loop to use the new variable.

Fixes #966

@pedjak pedjak force-pushed the fix-wrong-detected-ownded-resources branch from 7e6bf7e to 7367583 Compare June 9, 2021 14:58
@pedjak
Copy link
Contributor Author

pedjak commented Jun 9, 2021

/retest

@pedjak pedjak force-pushed the fix-wrong-detected-ownded-resources branch from 7367583 to 57d00f2 Compare June 9, 2021 21:37
@pedjak
Copy link
Contributor Author

pedjak commented Jun 10, 2021

/retest

@codecov
Copy link

codecov bot commented Jun 10, 2021

Codecov Report

Merging #975 (615d956) into master (d4fd4b7) will increase coverage by 1.28%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #975      +/-   ##
==========================================
+ Coverage   54.27%   55.56%   +1.28%     
==========================================
  Files          23       23              
  Lines        1227     1240      +13     
==========================================
+ Hits          666      689      +23     
+ Misses        473      462      -11     
- Partials       88       89       +1     
Impacted Files Coverage Δ
pkg/reconcile/pipeline/context/service.go 38.98% <100.00%> (+18.29%) ⬆️
pkg/reconcile/pipeline/context/impl.go 70.67% <0.00%> (+2.90%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d4fd4b7...615d956. Read the comment docs.

@baijum
Copy link
Member

baijum commented Jun 10, 2021

If no plan to write an acceptance test as part of this PR, please create an issue to track it.

@@ -43,8 +47,55 @@ var _ = Describe("Service", func() {
Expect(res).To(BeNil())
})

It("should return owned resources", func() {
Copy link
Member

Choose a reason for hiding this comment

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

There is a scenario where the OwnedResources could return an error. A unit test would be nice.
Use this function to return error: https://pkg.go.dev/k8s.io/client-go/testing#Fake.PrependReactor
There is an example in PR #971

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added.

var children []interface{}

for _, gvr := range bindableResourceGVRs {
gvk := gvr.GroupVersion().WithKind(strings.Title(gvr.Resource)[:len(gvr.Resource)-1])
Copy link
Member

Choose a reason for hiding this comment

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

The title form Configmap is not equivalent to ConfigMap. But I think it's ok for testing. An acceptance test would be better to capture a real-world scenario.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch - I have modified the test to exclude configmaps and check additional path when List returns not found error.

@pedjak pedjak force-pushed the fix-wrong-detected-ownded-resources branch from 57d00f2 to 8ef84c0 Compare June 10, 2021 14:22
@pedjak
Copy link
Contributor Author

pedjak commented Jun 10, 2021

If no plan to write an acceptance test as part of this PR, please create an issue to track it.

@baijum IMHO, constructing a reliable, deterministic acceptance test for this bug is impossible, because the bug is triggered by the order of resources returned by cluster API, and we cannot control that in practice. Fortunately we can control the order in the unit tests.

I could agree that writing additional acceptance tests demonstrating detectBindingResource usage would beneficial, but IMHO it is out of the scope of this PR.

We were bitten by https://github.com/golang/go/wiki/CommonMistakes#using-reference-to-loop-iterator-variable

Fixed the loop to use the new variable.

Signed-off-by: Predrag Knezevic <pknezevi@redhat.com>
@pedjak pedjak force-pushed the fix-wrong-detected-ownded-resources branch from 8ef84c0 to 615d956 Compare June 10, 2021 14:30
@baijum
Copy link
Member

baijum commented Jun 10, 2021

/lgtm

Not adding "approve" now as @pratikjagrut is also looking into this.

@pratikjagrut
Copy link
Contributor

/lgtm
/approve

@baijum
Copy link
Member

baijum commented Jun 11, 2021

/approve

@pmacik
Copy link
Contributor

pmacik commented Jun 11, 2021

/lgtm
/approve

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jun 11, 2021

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: baijum, pmacik, pratikjagrut

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@baijum
Copy link
Member

baijum commented Jun 11, 2021

/retest

2 similar comments
@baijum
Copy link
Member

baijum commented Jun 11, 2021

/retest

@pmacik
Copy link
Contributor

pmacik commented Jun 11, 2021

/retest

@openshift-merge-robot openshift-merge-robot merged commit fea1679 into redhat-developer:master Jun 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

detectBindingResources is binding to a wrong Service
5 participants