Add support for hook to suspend VM deletion - #1158
CaptainIRS wants to merge 9 commits into
Conversation
Signed-off-by: Rinish Sam <rinish.sam@sap.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/kind enhancement |
takoverflow
left a comment
There was a problem hiding this comment.
Thanks for the PR, just took a cursory glance and had some initial comments PTAL
Signed-off-by: Rinish Sam <rinish.sam@sap.com>
3498b20 to
eace893
Compare
…ables Signed-off-by: Rinish Sam <rinish.sam@sap.com>
…ad of ShortRetry Signed-off-by: Rinish Sam <rinish.sam@sap.com>
Signed-off-by: Rinish Sam <rinish.sam@sap.com>
|
Can you add an intergration test for this annotation as well Which tests machine deletion for a machine with this annotation, waits for condition to be added, then the annotation is removed by the test to allow VM deletion to proceed. |
Signed-off-by: Rinish Sam <rinish.sam@sap.com>
|
I've added integration tests, I've also verified with simulated provider. PTAL, thanks. logs |
|
LGTM label has been added. DetailsGit tree hash: c39d6cece40af10e51cd05485a14f10b602dbcef |
Signed-off-by: Rinish Sam <rinish.sam@sap.com>
…exceeding the max length Signed-off-by: Rinish Sam <rinish.sam@sap.com>
| - Long term: Please set more appropriate PDBs which allow disruption of at least one pod. | ||
| - Expired cloud credentials can block the deletion of the machine from infrastructure. | ||
| - Cloud provider can't delete the machine due to internal errors. Such situations are best debugged by using cloud provider specific CLI or cloud console. | ||
| - A controller may intentionally suspend VM deletion by adding an annotation such as `suspend-instance-deletion.node.machine.sapcloud.io/my-reason: my-controller`. Check the `Machine`'s annotations and `.status.conditions` for `type: InstanceDeletionSuspended` with `status: "True"`; remove the suspension annotation once the controller's work is complete so MCM can continue deletion. |
There was a problem hiding this comment.
nit: just to make it clear that my-reason isn't actually part of the annotation
| - A controller may intentionally suspend VM deletion by adding an annotation such as `suspend-instance-deletion.node.machine.sapcloud.io/my-reason: my-controller`. Check the `Machine`'s annotations and `.status.conditions` for `type: InstanceDeletionSuspended` with `status: "True"`; remove the suspension annotation once the controller's work is complete so MCM can continue deletion. | |
| - A controller may intentionally suspend VM deletion by adding an annotation such as `suspend-instance-deletion.node.machine.sapcloud.io/<my-reason>: <my-controller>`. Check the `Machine`'s annotations and `.status.conditions` for `type: InstanceDeletionSuspended` with `status: "True"`; remove the suspension annotation once the controller's work is complete so MCM can continue deletion. |
Signed-off-by: Rinish Sam <rinish.sam@sap.com>
aaronfern
left a comment
There was a problem hiding this comment.
Thanks for the PR and for making the changes!
/lgtm
|
LGTM label has been added. DetailsGit tree hash: 4cacb8c13a5ff82b04bebce9559f684ff4e06adf |
| Expect(actualCondition).ToNot(BeNil()) | ||
| Expect(actualCondition.Type).To(Equal(v1alpha1.InstanceDeletionSuspended)) | ||
| Expect(actualCondition.Status).To(Equal(corev1.ConditionTrue)) | ||
| Expect(actualCondition.Message).To(Equal("Instance Deletion suspended by my-controller for etcd-member-removal.")) |
There was a problem hiding this comment.
Could we abstract my-controller and etcd-member-removal as consts, so that any future tests can use it instead of a string?
| } | ||
|
|
||
| var suspensions []instanceDeletionSuspension | ||
| if owner, exists := machine.Annotations[v1alpha1.AnnotationKeySuspendInstanceDeletionPrefix]; exists { |
There was a problem hiding this comment.
Could we have validation for owner to be a non empty string? Or else we can get malformed messages like "Instance Deletion suspended by for xxx-reason."
| func IsInstanceDeletionSuspended(machine *v1alpha1.Machine) (string, bool) { | ||
| suspensions := getInstanceDeletionSuspensions(machine) | ||
| if len(suspensions) == 0 { | ||
| return "", false |
There was a problem hiding this comment.
Since we return false only when the returned string is "", do we need the boolean return value?
| } | ||
| oldSuspensionMessage, oldSuspended := annotationsutils.IsInstanceDeletionSuspended(oldMachine) | ||
| newSuspensionMessage, newSuspended := annotationsutils.IsInstanceDeletionSuspended(newMachine) | ||
| if (oldSuspended != newSuspended || oldSuspensionMessage != newSuspensionMessage) && c.shouldMachineBeMovedToTerminatingQueue(newMachine) { |
There was a problem hiding this comment.
Can we gate annotation checks on c.shouldMachineBeMovedToTerminatingQueue(newMachine) so that we do not have to do all these things for every machine update?
Future pre delete hooks(if any) can also reuse this block to run their checks only in the case the machine is marked for termination.
What this PR does / why we need it:
Adds support for suspending VM deletion after node draining, allowing external controllers to perform pre-termination actions such as removing an etcd member before the VM is deleted.
When a terminating Machine reaches the VM deletion stage and has a suspension annotation, MCM:
InstanceDeletionSuspended=Truecondition;Once the annotation is removed by the external controller, MCM proceeds to start deleting the VM in the reconciliation triggered by the annotation removal.
The annotation format is:
For example:
Once the external controller removes the annotation, MCM clears the condition and resumes VM deletion.
Which issue(s) this PR fixes:
Fixes #1131
Special notes for your reviewer:
MachinePhaseis introduced; the existingTerminatingphase and deletion flow are preserved.node.machine.sapcloud.io/suspend-instance-deletion/<purpose>is not a valid Kubernetes annotation key because it contains two/separators. The implemented format usessuspend-instance-deletion.node.machine.sapcloud.ioas the DNS prefix.go test ./pkg/util/annotationsgo test ./pkg/util/provider/machinecontrollerTesting with g/g:
This patch can be utilized.
In local gardener setup:
(This uses MCM checked out to this branch. Make sure skaffold is not using the cached MCM local provider image)
Release note: