-
Notifications
You must be signed in to change notification settings - Fork 49
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 k0scontrolplane controller #806
Add tests for k0scontrolplane controller #806
Conversation
a402a53
to
2201865
Compare
8da9d1f
to
6f6bee1
Compare
2ecdcb8
to
6a21e3f
Compare
51d1e3c
to
e845357
Compare
df4b917
to
a7e37a6
Compare
Signed-off-by: Adrian Pedriza <adripedriza@gmail.com>
a7e37a6
to
f9d3211
Compare
Ready for review, also I added some docs changes about testing |
|
||
3. Check documentation. |
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 all this should be in contribute workflow instead testing so I moved it there
|
||
// if it is necessary to reduce the number of replicas even counting the replicas to be eliminated | ||
// because they are outdated, we choose the oldest among the valid ones. | ||
if activeMachines.Len() > int(kcp.Spec.Replicas)+len(machineNamesToDelete) && len(desiredMachineNamesSlice) > 0 { |
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.
Could you elaborate a bit on why the logic was changed? The result looks more or less the same
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.
Yes, so basically I found a bug in the logic when running the proposed test TestReconcileMachinesSyncOldMachines
. Bug comes from two places: logic calculating machinesTodDelete
var + new machine name calculation.
Reproducible when:
- desired kcp replicas = 3
- current desired replicas:
<machine-name>-1
- outdated replicas:
<machine-name>-0
<machine-name>-2
👉 You can repro it by running new test TestReconcileMachinesSyncOldMachines
with the current reconcileMachines
func.
In this case, desired machine (<machine-name>-1
) is added to machineToDelete
variable even others machines which doesn't has same version should be delated first. In this case, <machine-name>-1
is added becauseactiveMachines.Len() > int(kcp.Spec.Replicas)+len(machineNamesToDelete)
is true
but others machines not updated should be removed first so condition activeMachines.Len() > int(kcp.Spec.Replicas)+len(machineNamesToDelete)
has been moved out of the loop to be sure a desired machine is not added until all others machine that could be added to machineToDelete
are checked.
In this case described above, machineName
func was calculating a bad machine name, facing an infinite loop an returning a machine name which was already created:
- machines to delete:
<machine-name>-1
,<machine-name>-2
- desired machines:
<machine-name>-4
,<machine-name>-5
- output:
<machine-name>-5
❌ (is already desired)
but I think all this comes from the error adding the wrong machine into machinesToDelete
so the fix is there and not in the naming logic.
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.
Great catch!
Changes
add unit and integration tests on the k0scontrolplane controller. They use envtest to spin-up to
kube-apiserver
+etcd
without using a cluster. In some of these tests it is enough to usefakeclient
for the creation of objects and subsequent state check but since for others it is necessary to use envtest (an apiserver is needed) and in order to reduce the different ways of creation of the environment I have chosen to use envtest for any test. For the test implementation I have taken inspiration from how upstream projects do this job.The idea is, after agreeing on how we want this type of testing for the project, to add the rest of the tests for the other controllers.
More detailed testing of the machine reconciliation logic can be added but since it is undergoing changes I have decided to add only basic testing for the time being.
updates docs about testing and moving some line to the proper place