Skip to content

🌱 Fix unit-tests on v1.1.x.#1958

Merged
guettli merged 13 commits intov1.1.xfrom
tg/fix-unit-tests
Apr 14, 2026
Merged

🌱 Fix unit-tests on v1.1.x.#1958
guettli merged 13 commits intov1.1.xfrom
tg/fix-unit-tests

Conversation

@guettli
Copy link
Copy Markdown
Collaborator

@guettli guettli commented Apr 13, 2026

Fix unit-tests on v1.1.x.

Failed before:

Summarizing 2 Failures:
[FAIL] HCloudMachineReconciler Basic hcloudmachine test wrong server [It] checks that ImageNotFound is visible in conditions if image does not exist
/home/guettli/syself/caph-fix-unit-tests/controllers/hcloudmachine_controller_test.go:518
[FAIL] HCloudMachineReconciler various specs without placement groups, but with placement group in hcloudMachine spec [It] should show the expected reason for server not created
/home/guettli/syself/caph-fix-unit-tests/controllers/hcloudmachine_controller_test.go:625

Ran 119 of 119 Specs in 60.768 seconds
FAIL! -- 117 Passed | 2 Failed | 0 Pending | 0 Skipped

  • Fixed the test, by not overwriting the condition.
  • Updated the test to provide a better err msg, when the test fails.
  • Provide better err msg, when running envtest fails. For example, when running like DEBUG=1 ginkgo run --focus "without placement groups" ./controllers/... | ./hack/filter-caph-controller-manager-logs.py -

@github-actions github-actions Bot added size/XS Denotes a PR that changes 0-20 lines, ignoring generated files. area/code Changes made in the code directory labels Apr 13, 2026
@guettli guettli requested a review from Dhairya-Arora01 April 13, 2026 14:50
@guettli guettli marked this pull request as ready for review April 13, 2026 14:50
@github-actions github-actions Bot added size/S Denotes a PR that changes 20-50 lines, ignoring generated files. area/test Changes made in the test directory and removed size/XS Denotes a PR that changes 0-20 lines, ignoring generated files. labels Apr 14, 2026
@github-actions github-actions Bot added size/M Denotes a PR that changes 50-200 lines, ignoring generated files. and removed size/S Denotes a PR that changes 20-50 lines, ignoring generated files. labels Apr 14, 2026
Comment thread test/helpers/envtest.go Outdated
@guettli guettli requested a review from Dhairya-Arora01 April 14, 2026 09:04
Comment thread pkg/services/hcloud/server/server.go Outdated
conditions.MarkFalse(hm, infrav1.ServerCreateSucceededCondition,
"ServerCreateNotPossible", clusterv1.ConditionSeverityWarning,
"%s", err.Error())
if !conditions.IsFalse(hm, infrav1.ServerCreateSucceededCondition) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this relevant? To me it sounds like we should stick to one version (in the utility function) or here, but not both

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@janiskemper what is the desired result?

Currently (pre PR):

reason="ServerCreateNotPossible" message="createServerFromImageNameOrURL failed: create server from imageName ("my-control-plane-2"): no image found with name my-control-plane-2: server create not possible - need action"

But test expected reason="ImageNotFound".


I slightly prefer ImageNotFound, but the more general reason is fine, too.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also do that. So we should not overwrite it. But my point is that we should find a better solution ideally, not this if statement. @Dhairya-Arora01 can also look into this if you want.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@janiskemper what about merging it like it is now, and make it nice in a second PR. The CI fails for other PRs now, and I would like to fix v1.1.x soon.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abdullah599 then plz look into that. If we have another issue, we can merge this

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

6d2a932

I did this (i'll revert it). I did not know we fixed it here

reason:
ServerCreateSucceededCondition are already set with the specific reason by the inner function that returned errServerCreateNotPossible. imo we must not overwrite them here.

The guard isn't needed imo. Every code path that returns errServerCreateNotPossible already sets ServerCreateSucceededCondition to False with a specific reason before returning:

  1. createServerInstanceHasNonExistingPlacementGroupReason
  2. getSSHKeysSSHKeyNotFoundReason
  3. getServerImageServerTypeNotFoundReason
  4. getServerImageImageAmbiguousReason
  5. getServerImageImageNotFoundReason

So conditions.IsFalse(hm, infrav1.ServerCreateSucceededCondition) is always true when this handler runs.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so we can just remove this right?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abdullah599 yes, maybe it works for now to remove that block completely. But who know if the future paths all set a condition. I recommend to leave it like this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@guettli I wouldn't leave it like this, because the problem shouldn't exist in the first place, if this code part is removed.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

Eventually(func() bool {
return isPresentAndFalseWithReason(key, hcloudMachine, infrav1.ServerCreateSucceededCondition, infrav1.ImageNotFoundReason)
}, timeout, interval).Should(BeTrue())
Eventually(func() error {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we do this? If the utility function has some issues, we oculd also solve it there probably no? I'm not able to judge on first glance what changed.

Copy link
Copy Markdown
Collaborator Author

@guettli guettli Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@janiskemper before we got an meaningless "false is not true" error. We get much better error now, when the test fails:

expected ServerCreateSucceeded to be False with reason "ImageNotFound",

got status="False" reason="ServerCreateNotPossible" message="createServerFromImageNameOrURL failed: create server from imageName ("my-control-plane-2"): no image found with name my-control-plane-2: server create not possible - need action"


For new code I prefer Eventually(func() error to Eventually(func() bool


But I can revert that, too. Or we write a helper which makes getting a good error message easier.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well this applies to all cases where we use this utility function. Do we have an idea how to improve that?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a reusable helper in test/helpers/conditions.go and switched only this Eventually to use it.

I reverted the broader rollout so this PR stays scoped to the original failing case. If we want to apply the same pattern to the other isPresentAndFalseWithReason usages, I can do that in a separate follow-up PR.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@guettli can you plz write down properly what your problem is with the isPresentAndFalseWithReason utility and then why you wanna change it and what you propose? I think that we either properly change the original utility function, we introduce a separate utility function, or we do it differently in this one case.

If no change is needed here for this PR, I would leave the topic, revert the changes, and create an issue for it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions github-actions Bot added size/S Denotes a PR that changes 20-50 lines, ignoring generated files. and removed size/M Denotes a PR that changes 50-200 lines, ignoring generated files. labels Apr 14, 2026
@guettli guettli requested a review from abdullah599 April 14, 2026 14:14
@github-actions github-actions Bot added size/M Denotes a PR that changes 50-200 lines, ignoring generated files. and removed size/S Denotes a PR that changes 20-50 lines, ignoring generated files. labels Apr 14, 2026
Copy link
Copy Markdown
Contributor

@janiskemper janiskemper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM from my side. @abdullah599 is that what you had in mind as well?

Copy link
Copy Markdown
Contributor

@abdullah599 abdullah599 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM from my side. @abdullah599 is that what you had in mind as well?

Yes :)

@guettli guettli merged commit aaf44ce into v1.1.x Apr 14, 2026
7 checks passed
@guettli guettli deleted the tg/fix-unit-tests branch April 14, 2026 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/code Changes made in the code directory area/test Changes made in the test directory size/M Denotes a PR that changes 50-200 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants