Skip to content

Add integration tests for auto machine preservation - #1124

Open
aaronfern wants to merge 12 commits into
gardener:masterfrom
aaronfern:int_tests
Open

Add integration tests for auto machine preservation#1124
aaronfern wants to merge 12 commits into
gardener:masterfrom
aaronfern:int_tests

Conversation

@aaronfern

@aaronfern aaronfern commented Jul 27, 2026

Copy link
Copy Markdown
Member

What this PR does / why we need it:
This PR adds integration tests for auto machine preservation.

The following cases have been covered:

  • Ensure failed machine is preserved and rejoins the cluster on recovery
  • Failed machines that cross the max threshold are not preserved
  • machinePreserveTimeout is honoured for failing machines
  • Machine should not be preserved when the preserve=false annotation is present
  • Preserved machine should stop being preserved when preserve=false annotation is added
  • When AutoPreserveFailedMachineMax is reduced, failed machines that exceed the new AutoPreserveFailedMachineMax count are moved to terminating

Which issue(s) this PR fixes:
Fixes partially #1123

Special notes for your reviewer:
To trigger machine failures, this PR takes the approach of applying a validating admission policy to block all kubelet updates. This causes kubelet not to be able to update it's node lease or it's node status and results in the node going into the Unknown state.
This is a k8s native way of achieving node failures and has no dependency on the provider or any other node/worker-pool setting

This might not work with the virtual provider of the virtual provider does not use kubelets, but imo this can be considered a special case and can be tackled in a separate PR

Release note:

Added integration tests for auto machine preservation

@aaronfern
aaronfern requested a review from a team as a code owner July 27, 2026 07:05
@gardener-prow gardener-prow Bot added do-not-merge/needs-kind Indicates a PR lacks a `kind/foo` label and requires one. cla: yes Indicates the PR's author has signed the cla-assistant.io CLA. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jul 27, 2026
@aaronfern aaronfern added the kind/test Test label Jul 27, 2026
@gardener-prow gardener-prow Bot removed the do-not-merge/needs-kind Indicates a PR lacks a `kind/foo` label and requires one. label Jul 27, 2026
@thiyyakat

Copy link
Copy Markdown
Member

/assign

@gagan16k gagan16k left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the PR!

}

// DeleteVAPToRestartKubeletUpdates deletes the ValidatingAdmissionPolicy and ValidatingAdmissionPolicyBinding that were created to block kubelet from updating node leases and node status.
func (c *Cluster) DeleteVAPToRestartKubeletUpdates(ctx context.Context) error {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I have some points/questions regarding this function

  • Should we use defer instead of gomega.Expect(c.TargetCluster.DeleteVAPToRestartKubeletUpdates(ctx)).To(gomega.BeNil()) for cleanup steps like these? In case of any test assertion failure above where this is called, the VAP and VAPB might not get cleared if Ginkgo aborts the test immediately.
  • I think we should also add this function in cleanTestResources(). If any matching resources get left behind, this way they get cleared after(and before) test runs.
  • In case the IT process crashes (with no chance to execute the cleanup), the resources can get left behind in the cluster. Currently(pre-PR) even the test machine deployment, and the machines themselves can persist if this happens. Would it be worthwhile to add a make target to clean this up?

@aaronfern aaronfern Aug 6, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I've added DeleteVAPToRestartKubeletUpdates to DeferCleanups within tests and have added vap/vapb cleanup to cleanTestResources() in fbfc7b5
PTAL

Comment thread pkg/test/integration/common/helpers/admission_policy.go
Comment thread pkg/test/integration/common/helpers/admission_policy.go Outdated
Comment thread go.mod Outdated
Comment thread pkg/test/integration/common/helpers/machine_resources.go
Comment thread pkg/test/integration/common/framework.go Outdated
Comment thread pkg/test/integration/common/framework.go Outdated
Comment thread pkg/test/integration/common/framework.go Outdated
Comment thread pkg/test/integration/common/framework.go Outdated
Comment thread pkg/test/integration/common/framework.go Outdated

@thiyyakat thiyyakat left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for adding these much-needed tests! 👍

Comment thread pkg/test/integration/common/helpers/admission_policy.go Outdated
Comment thread pkg/test/integration/common/helpers/admission_policy.go Outdated
Comment thread pkg/test/integration/common/helpers/admission_policy.go Outdated
Comment thread pkg/test/integration/common/helpers/machine_resources.go Outdated
Comment thread pkg/test/integration/common/helpers/machine_resources.go Outdated
Comment thread pkg/test/integration/common/framework.go Outdated
Comment thread pkg/test/integration/common/framework.go Outdated
Comment thread pkg/test/integration/common/framework.go Outdated
Comment thread pkg/test/integration/common/framework.go Outdated
Comment thread pkg/test/integration/common/framework.go
@thiyyakat

Copy link
Copy Markdown
Member

@aaronfern , should we have some IT to test reduction of AutoPreserveFailedMachineMax? If the number of preserved failed machines is equal to AutoPreserveFailedMachineMax already, and the value is reduced by 1, a machine should move to Terminating.

Co-authored-by: gagan16k
@gardener-prow

gardener-prow Bot commented Aug 5, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from thiyyakat. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@aaronfern

Copy link
Copy Markdown
Member Author

@aaronfern , should we have some IT to test reduction of AutoPreserveFailedMachineMax? If the number of preserved failed machines is equal to AutoPreserveFailedMachineMax already, and the value is reduced by 1, a machine should move to Terminating.

@thiyyakat Okay, sure, makes sense. I will add this test

aaronfern and others added 2 commits August 5, 2026 22:48
Co-authored-by: Meghana <meghana.thiyyakat@sap.com>

@thiyyakat thiyyakat left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for adding the test and addressing the comments. Just a few nits.

Comment thread pkg/test/integration/common/helpers/machine_resources.go Outdated
Comment thread pkg/test/integration/common/helpers/machine_resources.go Outdated
Comment thread pkg/test/integration/common/helpers/machine_resources.go Outdated
Comment thread pkg/test/integration/common/framework.go Outdated
Comment thread pkg/test/integration/common/framework.go Outdated
Comment thread pkg/test/integration/common/framework.go Outdated

@thiyyakat thiyyakat left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There are a few if-else if blocks that can be converted to if-else blocks. PTAL.

Comment thread pkg/test/integration/common/helpers/admission_policy.go Outdated
Comment thread pkg/test/integration/common/framework.go Outdated
Comment thread pkg/test/integration/common/framework.go Outdated
Comment thread pkg/test/integration/common/framework.go Outdated
Comment thread pkg/test/integration/common/framework.go Outdated

@gagan16k gagan16k left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Some more comments, PTAL

Comment thread pkg/test/integration/common/framework.go Outdated
Comment thread pkg/test/integration/common/framework.go Outdated
Comment thread pkg/test/integration/common/framework.go
Comment thread pkg/test/integration/common/helpers/machine_resources.go Outdated
Comment thread pkg/test/integration/common/framework.go Outdated
Comment thread pkg/test/integration/common/helpers/machine_resources.go
Comment thread pkg/test/integration/common/framework.go Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes Indicates the PR's author has signed the cla-assistant.io CLA. kind/test Test size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants