Skip to content

Can't unit test own usage of InClusterFactory #103

Open
@phantomjinx

Description

@phantomjinx

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 readNamespace public
  • provide an interface to allow GetNamespacedName to 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    lifecycle/frozenIndicates that an issue or PR should not be auto-closed due to staleness.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions