cluster-api-provider-openstack icon indicating copy to clipboard operation
cluster-api-provider-openstack copied to clipboard

Envtest mocks

Open mdbooth opened this issue 2 years ago • 13 comments

What this PR does / why we need it:

The purpose of this PR is to be able to run envtests using mock clients instead of real ones. This PR achieves that by enhancing Scope to return service clients. We add a new scope Factory interface to generate Scopes. We provide 2 implementations of Factory:

ProviderScopeFactory generates 'real' Scopes which expect to be able to make API calls to a running OpenStack cloud. MockScopeFactory uses mock clients.

Because Scopes now return clients, the scope package must import those clients. However, clients are currently in their service packages. Services use scopes and must therefore import the scope package. This is a circular dependency. To avoid this we move clients into a separate package.

With the exception of the new factory interface, all other changes are mechanical. This PR does not intentionally introduce any functional changes.

Because of the large amount of code churn I have split the change into multiple commits. These commits each make a single refactor. I suggest that this PR will be simpler to review by commit, as the mechanical code churn in each individual commit is very similar.

/hold

mdbooth avatar May 06 '22 18:05 mdbooth

Deploy Preview for kubernetes-sigs-cluster-api-openstack ready!

Name Link
Latest commit bd1aabe56594e9a6679ced35aacbbfb585df7235
Latest deploy log https://app.netlify.com/sites/kubernetes-sigs-cluster-api-openstack/deploys/63d8e558a946bf0008ad0e5e
Deploy Preview https://deploy-preview-1236--kubernetes-sigs-cluster-api-openstack.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

netlify[bot] avatar May 06 '22 18:05 netlify[bot]

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mdbooth

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

k8s-ci-robot avatar May 06 '22 18:05 k8s-ci-robot

@mdbooth: The /test command needs one or more targets. The following commands are available to trigger required jobs:

  • /test pull-cluster-api-provider-openstack-build
  • /test pull-cluster-api-provider-openstack-e2e-test
  • /test pull-cluster-api-provider-openstack-test

The following commands are available to trigger optional jobs:

  • /test pull-cluster-api-provider-openstack-conformance-test

Use /test all to run the following jobs that were automatically triggered:

  • pull-cluster-api-provider-openstack-build
  • pull-cluster-api-provider-openstack-e2e-test
  • pull-cluster-api-provider-openstack-test

In response to this:

/test

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

k8s-ci-robot avatar May 06 '22 18:05 k8s-ci-robot

/test all

mdbooth avatar May 06 '22 18:05 mdbooth

/retest

mdbooth avatar May 06 '22 19:05 mdbooth

/retest

mdbooth avatar May 06 '22 19:05 mdbooth

Looks good to me! (adding lgtm after a rebase)

We discussed removing the clientOpts and passing the region through the Scope struct in #1178. At least now it is an implementation detail of the ProviderScopeFactory.

apricote avatar May 10 '22 12:05 apricote

/retest-required

mdbooth avatar Jul 06 '22 12:07 mdbooth

/test pull-cluster-api-provider-openstack-e2e-test

stephenfin avatar Aug 04 '22 11:08 stephenfin

/retest-required

stephenfin avatar Aug 04 '22 14:08 stephenfin

fwict, the CI failures are due to infra issues (quotas), not the change itself

stephenfin avatar Aug 04 '22 14:08 stephenfin

/retest-required

stephenfin avatar Aug 09 '22 10:08 stephenfin

This should be finally good to review again.

stephenfin avatar Oct 14 '22 14:10 stephenfin

Because of the large amount of code churn I have split the change into multiple commits. These commits each make a single refactor. I suggest that this PR will be simpler to review by commit, as the mechanical code churn in each individual commit is very similar.

Thank you! It was quite nice to review per commit! :slightly_smiling_face: This looks like a good improvement to me. /lgtm

lentzi90 avatar Jan 31 '23 08:01 lentzi90

Fixed merge conflict with #1451

mdbooth avatar Jan 31 '23 09:01 mdbooth

/hold cancel

mdbooth avatar Jan 31 '23 09:01 mdbooth