operator-framework / operator-framework/operator-lib
Can't unit test own usage of InClusterFactory
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 41
- Forks
- 42
- Avg merge
- 8d 8h
- Merged PRs (30d)
- 4
Description
Bug Report
What did you do?
Created a wrapper function in our operator code that finds the name of the associated OLM OperatorCondition and then uses the InClusterFactory API to set the upgradeable condition. Then we started writing tests to test this function.
What did you expect to see?
Tests to pass or fail depending on the correct writing of the wrapper function and calling the correct InClusterFactory and Condition code.
What did you see instead? Under which circumstances?
The error: get operator condition namespace: namespace not found for current environment.
Since the unit tests are using a fake runtime client and running locally, this was to be expected since InClusterFactory.GetNamespacedName() calls utils.GetOperatorNamespace(). However, what was unexpected was in our tests there is no way to override this since:
- utils package is internal so private
- readNamespace is private
- the library's own tests can override since they share the same package as
readNamespace.
Environment
- operator-lib version: 0.9.x
- github.com/operator-framework/operator-lib v0.9.0
Possible Solutions
- make
readNamespacepublic - provide an interface to allow
GetNamespacedNameto be overridden - allow the namespace to be injected into InClusterFactory (since the operator provides the namespace through
request.namespace, it might be a nice alternative?)
Additional context
Add any other context about the problem here.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with conditions/factory.go at readNamespace, then trace InClusterFactory.GetNamespacedName through internal/utils/utils.go and review the override used in conditions/conditions_test.go. Determine an externally usable way to supply or override the namespace for unit tests, with tests that exercise wrapper code using a fake runtime client without requiring the current environment namespace.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- backend-api-design, testing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100