test: Drain tool tests#1104
Conversation
ed8f6a2 to
584f822
Compare
370ea71 to
c3aa1d9
Compare
michaelawyu
left a comment
There was a problem hiding this comment.
Added some comments, PTAL
| } | ||
|
|
||
| // Build drain binary. | ||
| buildCmd := exec.Command("go", "build", "-o", drainBinaryPath, filepath.Join("../../", "tools", "draincluster")) |
There was a problem hiding this comment.
Hi Arvind! We have a setup.sh file; it might make a lot more sense to just call the build commands there rather than shell out in this Go source code.
There was a problem hiding this comment.
In fact these test specs might warrant an environment of its own -> but I guess we could make the move if our test specs continue to grow.
| const ( | ||
| uuidLength = 8 | ||
| drainEvictionNameFormat = "drain-eviction-%s-%s-%s" | ||
| drainEvictionNameFormat = "drain-eviction-%s" |
There was a problem hiding this comment.
Hi Arvind! Collision chances aside (which is minimal I assume), I do think that the prev. format might be more clear to the end users.
|
|
||
| It("drain cluster using binary, should succeed", func() { runDrainClusterBinary(hubClusterName, memberCluster1EastProdName, true) }) | ||
|
|
||
| It("should ensure no resources exist on drained clusters", func() { |
There was a problem hiding this comment.
Hi Arvind! I suppose we also need a check on the taints (here or as a separate test spec).
There was a problem hiding this comment.
And if we would like to check this a bit closer, an inspection on the Eviction object would also be nice.
| "--clusterName", memberClusterName) | ||
| output, err := cmd.CombinedOutput() | ||
| Expect(err).ToNot(HaveOccurred(), "Uncordon command failed with error: %v\nOutput: %s", err, string(output)) | ||
| Expect(strings.Contains(string(output), "uncordoned member cluster")).To(BeTrue(), "Expected uncordon to be successful") |
There was a problem hiding this comment.
Hi Arvind! IIRC the error check part already guarantees that the exit code must be 0; using the string match on logs to verify if it has run successfully is a bit error prone I am afraid.
| "--clusterName", memberClusterName) | ||
| output, err := cmd.CombinedOutput() | ||
| Expect(err).ToNot(HaveOccurred(), "Drain command failed with error: %v\nOutput: %s", err, string(output)) | ||
| if isSuccess { |
There was a problem hiding this comment.
Same issue here; I am wondering if there is a better way to validate this rather than relying on log string matches.
|
|
||
| AfterAll(func() { | ||
| // Uncordon member cluster 1 again to guarantee clean up of cordon taint on test failure. | ||
| runUncordonClusterBinary(hubClusterName, memberCluster1EastProdName) |
There was a problem hiding this comment.
Hi Arvind! Just a nit: since the cordon binary itself is a test target, it might be best not to rely it on the cleanup part, just in case.
There was a problem hiding this comment.
Same applies for a few other test specs I assume.
| Expect(hubClient.Create(ctx, &crpdb)).To(Succeed(), "Failed to create CRP Disruption Budget %s", crpName) | ||
| }) | ||
|
|
||
| It("drain cluster using binary, should fail due to CRPDB", func() { runDrainClusterBinary(hubClusterName, memberCluster1EastProdName, false) }) |
There was a problem hiding this comment.
Hi Arvind! Some of the issues mentioned earlier apply to this part as well.
There was a problem hiding this comment.
It probably would be better if we do a closer inspection (taints, eviction objects) to make sure that the tool is functioning normally rather than just check the logs.
|
|
||
| It("uncordon cluster using binary", func() { runUncordonClusterBinary(hubClusterName, memberCluster1EastProdName) }) | ||
|
|
||
| It("should update cluster resource placement status as expected", func() { |
There was a problem hiding this comment.
Hi Arvind! Is this step necessary? We really couldn't tell whether uncordoning works even with this step passing.
|
|
||
| It("should place resources on all available member clusters", checkIfPlacedWorkResourcesOnAllMemberClusters) | ||
| }) | ||
|
|
There was a problem hiding this comment.
Just my $0.02 but it would be interesting to see how this tool (and Fleet) can actually help DR in an actual workflow of migrating workloads between clusters. It's a good showcase too.
There was a problem hiding this comment.
But obviously we could always add more later.
| gotMap, gotErr := h.fetchClusterResourcePlacementNamesToEvict(context.Background()) | ||
| if tc.wantErr == nil { | ||
| if gotErr != nil { | ||
| t.Errorf("fetchClusterResourcePlacementNamesToEvict test %s failed, got error %v, want error %v", tc.name, gotErr, tc.wantErr) |
There was a problem hiding this comment.
Hi Arvind! Style concerns aside, there are a few branches that really do not need to continue once failure are found (even though they can proceed).
There was a problem hiding this comment.
Something like
if wantErred
if gotErr != nil -> Errorf and return
compareErrMessages -> Errorf if needed and return
if gotErr -> Errorf and return
cmpMap
would be clearer I assume.
There was a problem hiding this comment.
This would also apply to other cases I guess.
|
Hi Arvind! I am closing this PR as part of the CNCF repo migration process; please consider moving (re-creating) this PR in the new repo once the sync PR is merged. If there's any question/concern, please let me know. Thanks 🙏 |
Description of your changes
Fixes #
I have:
make reviewableto ensure this PR is ready for review.How has this code been tested
Special notes for your reviewer