Skip to content

Commit

Permalink
Delete all PVCs if guest cluster is deleted in Rancher
Browse files Browse the repository at this point in the history
If a cluster is deleted, the PVCs of the workloads are not deleted in Harvester. This is because the node driver does not know why the associated VM has to be deleted, e.g. because its parameters have changed or because the cluster is deleted.

To solve the problem, a finalizer on the Machine resource in Rancher will add an annotation to the VM which then is evaluated by the node driver when it running the Remove() handler.

Signed-off-by: Volker Theile <vtheile@suse.com>
  • Loading branch information
votdev committed Jan 15, 2025
1 parent 03e510a commit fc7d146
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion harvester/harvester.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const (
actionStart = "start"
actionStop = "stop"
actionRestart = "restart"

removeAllPVCsAnnotationKey = "harvesterhci.io/removeAllPersistentVolumeClaims"
)

// Driver is the driver used when no driver is selected. It is used to
Expand Down Expand Up @@ -180,9 +182,16 @@ func (d *Driver) Remove() error {
}
return err
}

removeAll := false
if value, ok := vm.Annotations[removeAllPVCsAnnotationKey]; ok && value == "true" {
log.Debugf("Force the removal of all persistent volume claims")
removeAll = true
}

removedPVCs := make([]string, 0, len(vm.Spec.Template.Spec.Volumes))
for _, volume := range vm.Spec.Template.Spec.Volumes {
if volume.PersistentVolumeClaim == nil || volume.PersistentVolumeClaim.Hotpluggable {
if volume.PersistentVolumeClaim == nil || (!removeAll && volume.PersistentVolumeClaim.Hotpluggable) {
continue
}
removedPVCs = append(removedPVCs, volume.PersistentVolumeClaim.ClaimName)
Expand Down

0 comments on commit fc7d146

Please sign in to comment.