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
Add tests for actuator events #107
Add tests for actuator events #107
Conversation
doneMgr := make(chan struct{}) | ||
|
||
go func() { | ||
g.Expect(mgr.Start(doneMgr)).To(Succeed()) |
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.
Does it mean that if the manager fails to start, the channel could potentially stay open? https://github.com/openshift/cluster-api-provider-gcp/pull/107/files#diff-1842c9950ada81a773ba54f690df1cefR58 defer
should belong here - https://github.com/openshift/cluster-api-provider-gcp/pull/107/files#diff-1842c9950ada81a773ba54f690df1cefR54
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.
The channel should be closed when the test exits, I don't think there's any issues with the manager not starting right here, apart from the fact we can't detect whether it has started/stopped. If you want to be thorough I would suggest the use of a waitgroup to ensure the goroutine finishes before the tests end
klog.Errorf("Failed to patch machine %q: %v", s.machine.GetName(), err) | ||
return err | ||
} | ||
|
||
s.machine.Status = statusCopy | ||
|
||
// patch status | ||
if err := s.coreClient.Status().Patch(context.Background(), s.machine, s.machineToBePatched); err != nil { |
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.
You could simply pass s
as a first argument.
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'd leave s.Context
for better readability.
@@ -45,6 +49,10 @@ type machineScope struct { | |||
// newMachineScope creates a new MachineScope from the supplied parameters. | |||
// This is meant to be called for each machine actuator operation. | |||
func newMachineScope(params machineScopeParams) (*machineScope, error) { | |||
if params.Context == nil { |
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 think we should default to context.Background
here, as I can't yet see real uses for other context values
eventsChannel := make(chan string, 1) | ||
recorder := &record.FakeRecorder{ | ||
Events: eventsChannel, | ||
func TestMachineEvents(t *testing.T) { |
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 think this method should be called TestActuatorScopeEvents
or just TestActuatorEvents
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.
👍
@@ -61,12 +62,14 @@ func (a *Actuator) Create(ctx context.Context, machine *machinev1.Machine) error | |||
machine: machine, | |||
}) | |||
if err != nil { | |||
return a.handleMachineError(machine, err, createEventAction) | |||
fmtErr := fmt.Errorf(scopeFailFmt, machine.GetName(), err) |
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.
wouldn't this shadow the error type breaking consumers?
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.
In Go 1.13 it shouldn't, https://blog.golang.org/go1.13-errors
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.
Consumers will need to make sure that they use errors.Is
or errors.As
from the errors
standard library if they want to check the type, I believe we are already doing this in MAO but worth checking if there's anywhere else expecting a particular error type
@@ -168,6 +168,10 @@ func (r *Reconciler) create() error { | |||
} | |||
|
|||
func (r *Reconciler) update() error { | |||
if err := validateMachine(*r.machine, *r.providerSpec); err != nil { |
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.
what's the rationale behind introducing this in the PR?
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.
We have this validation in other providers, and tests for actuator events cover this case. I'd like to keep these tests consistent among all providers.
@@ -61,12 +62,14 @@ func (a *Actuator) Create(ctx context.Context, machine *machinev1.Machine) error | |||
machine: machine, | |||
}) | |||
if err != nil { | |||
return a.handleMachineError(machine, err, createEventAction) | |||
fmtErr := fmt.Errorf(scopeFailFmt, machine.GetName(), err) |
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.
Consumers will need to make sure that they use errors.Is
or errors.As
from the errors
standard library if they want to check the type, I believe we are already doing this in MAO but worth checking if there's anywhere else expecting a particular error type
doneMgr := make(chan struct{}) | ||
|
||
go func() { | ||
g.Expect(mgr.Start(doneMgr)).To(Succeed()) |
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.
The channel should be closed when the test exits, I don't think there's any issues with the manager not starting right here, apart from the fact we can't detect whether it has started/stopped. If you want to be thorough I would suggest the use of a waitgroup to ensure the goroutine finishes before the tests end
@@ -18,12 +17,17 @@ import ( | |||
|
|||
// machineScopeParams defines the input parameters used to create a new MachineScope. | |||
type machineScopeParams struct { | |||
coreClient controllerclient.Client | |||
machine *machinev1.Machine | |||
context.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.
Out of interest, why embed the context rather than have it as an explicit field?
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 don't think there is any benefit in it, but we have the same in vsphere https://github.com/openshift/machine-api-operator/blob/master/pkg/controller/vsphere/machine_scope.go#L33 + I saw a similar thing in upstream https://github.com/kubernetes-sigs/cluster-api-provider-vsphere/blob/master/pkg/context/controller_manager_context.go#L35
} | ||
|
||
// machineScope defines a scope defined around a machine and its cluster. | ||
type machineScope struct { | ||
context.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.
Same as above, is there a benefit to embedding?
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: JoelSpeed 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 |
/lgtm |
/retest Please review the full test history for this PR and help us cut down flakes. |
10 similar comments
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
20 similar comments
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
This PR adds tests for actuator events, but this required couple of other changes.
https://github.com/openshift/machine-api-operator/blob/master/pkg/controller/vsphere/actuator_test.go
https://github.com/openshift/cluster-api-provider-aws/blob/master/pkg/actuators/machine/actuator_test.go