-
Notifications
You must be signed in to change notification settings - Fork 261
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
Envtest mocks #1236
Envtest mocks #1236
Conversation
✅ Deploy Preview for kubernetes-sigs-cluster-api-openstack ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
[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 |
@mdbooth: The
The following commands are available to trigger optional jobs:
Use
In response to this:
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. |
/test all |
967e5f9
to
ae843d6
Compare
/retest |
/retest |
Looks good to me! (adding lgtm after a rebase) We discussed removing the |
f78fe2e
to
807df96
Compare
@@ -111,18 +111,11 @@ func (r *OpenStackClusterReconciler) Reconcile(ctx context.Context, req ctrl.Req | |||
} | |||
}() | |||
|
|||
osProviderClient, clientOpts, projectID, err := provider.NewClientFromCluster(ctx, r.Client, openStackCluster) | |||
scope, err := r.ScopeFactory.NewClientScopeFromCluster(ctx, r.Client, openStackCluster, log) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we pass the logger as part of the context?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made this comment a long time ago but didn't submit the review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just implemented this to play with it, but I don't think so.
My thinking is that in the controllers we retrieve a logger from controller runtime from the context, then we add context to it with a succession of log = log.WithValues(...)
. The contract of this call is:
// WithValues returns a new Logger instance with additional key/value pairs.
I don't think we can assume that retrieving the logger again from the context would retrieve the logger customised for the current reconcile.
I'm prepared to be wrong on this, though. Either way, could we come back to it in a separate PR? It should be a fairly easy mechanical change if we decide to do this later.
807df96
to
e01fbe2
Compare
Thank you! It was quite nice to review per commit! 🙂 |
Move 'provider' from the 'cloud/services.provider' package to 'scope'. This is in preparation for adding ProviderScope.
Scope is going to return clients and therefore has to import it. clients therefore can't import scope as this would be a circular dependency.
scope.Factory is a factory for generating Scopes. We provide two implementations: - ScopeFactory generates a Scope from the provider details contained in either a Machine or a Cluster object. It expects to be able to make API calls to a running OpenStack cloud. - MockScopeFactory generates a Scope which uses mock clients from pkg/clients/mock.
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
Move all provider-specific code into provider.go.
9a865b2
to
bd1aabe
Compare
Fixed merge conflict with #1451 |
/hold cancel |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
Let's get this merged!
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