mirror of
https://github.com/kubevirt/containerized-data-importer.git
synced 2025-06-03 06:30:22 +00:00
add annotation cdi.kubevirt.io/garbageCollected to PVCs when DVs are garbage collected (#3059)
Signed-off-by: Michael Henriksen <mhenriks@redhat.com>
This commit is contained in:
parent
9ff5671e53
commit
61368754b1
@ -245,6 +245,9 @@ const (
|
|||||||
// be dynamically provisioned. Its value is the name of the selected node.
|
// be dynamically provisioned. Its value is the name of the selected node.
|
||||||
AnnSelectedNode = "volume.kubernetes.io/selected-node"
|
AnnSelectedNode = "volume.kubernetes.io/selected-node"
|
||||||
|
|
||||||
|
// AnnGarbageCollected is a PVC annotation indicating that the PVC was garbage collected
|
||||||
|
AnnGarbageCollected = AnnAPIGroup + "/garbageCollected"
|
||||||
|
|
||||||
// CloneUniqueID is used as a special label to be used when we search for the pod
|
// CloneUniqueID is used as a special label to be used when we search for the pod
|
||||||
CloneUniqueID = "cdi.kubevirt.io/storage.clone.cloneUniqeId"
|
CloneUniqueID = "cdi.kubevirt.io/storage.clone.cloneUniqeId"
|
||||||
|
|
||||||
|
@ -104,6 +104,7 @@ func (r *ReconcilerBase) canUpdateFinalizers(ownerRef metav1.OwnerReference) (bo
|
|||||||
func (r *ReconcilerBase) detachPvcDeleteDv(syncState *dvSyncState) error {
|
func (r *ReconcilerBase) detachPvcDeleteDv(syncState *dvSyncState) error {
|
||||||
updatePvcOwnerRefs(syncState.pvc, syncState.dv)
|
updatePvcOwnerRefs(syncState.pvc, syncState.dv)
|
||||||
delete(syncState.pvc.Annotations, cc.AnnPopulatedFor)
|
delete(syncState.pvc.Annotations, cc.AnnPopulatedFor)
|
||||||
|
cc.AddAnnotation(syncState.pvc, cc.AnnGarbageCollected, "true")
|
||||||
if err := r.updatePVC(syncState.pvc); err != nil {
|
if err := r.updatePVC(syncState.pvc); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -1624,6 +1624,34 @@ var _ = Describe("All DataVolume Tests", func() {
|
|||||||
Expect(pvc.OwnerReferences).To(HaveLen(4))
|
Expect(pvc.OwnerReferences).To(HaveLen(4))
|
||||||
Expect(pvc.OwnerReferences).To(Equal([]metav1.OwnerReference{ref("1"), ref("2"), ref("3"), vmOwnerRef}))
|
Expect(pvc.OwnerReferences).To(Equal([]metav1.OwnerReference{ref("1"), ref("2"), ref("3"), vmOwnerRef}))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("should update PVC when garbage collecting", func() {
|
||||||
|
dv := NewImportDataVolume("test-dv")
|
||||||
|
AddAnnotation(dv, AnnDeleteAfterCompletion, "true")
|
||||||
|
dv.Status.Phase = cdiv1.Succeeded
|
||||||
|
vmOwnerRef := metav1.OwnerReference{Kind: "VirtualMachine", Name: "test-vm", UID: "test-vm-uid", Controller: ptr.To(true)}
|
||||||
|
dv.OwnerReferences = append(dv.OwnerReferences, vmOwnerRef)
|
||||||
|
|
||||||
|
pvc := CreatePvc("test-dv", metav1.NamespaceDefault, nil, nil)
|
||||||
|
dvOwnerRef := metav1.OwnerReference{Kind: "DataVolume", Name: "test-dv", UID: dv.UID, Controller: ptr.To(true)}
|
||||||
|
pvc.OwnerReferences = append(pvc.OwnerReferences, dvOwnerRef)
|
||||||
|
|
||||||
|
cdiConfig := MakeEmptyCDIConfigSpec(common.ConfigName)
|
||||||
|
cdiConfig.Status = cdiv1.CDIConfigStatus{
|
||||||
|
ScratchSpaceStorageClass: testStorageClass,
|
||||||
|
}
|
||||||
|
cdiConfig.Spec.FeatureGates = []string{featuregates.HonorWaitForFirstConsumer}
|
||||||
|
cdiConfig.Spec.DataVolumeTTLSeconds = ptr.To(int32(0))
|
||||||
|
|
||||||
|
reconciler = createImportReconcilerWithoutConfig(dv, pvc, cdiConfig)
|
||||||
|
_, err := reconciler.Reconcile(context.TODO(), reconcile.Request{NamespacedName: types.NamespacedName{Name: "test-dv", Namespace: metav1.NamespaceDefault}})
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
pvc = &corev1.PersistentVolumeClaim{}
|
||||||
|
err = reconciler.client.Get(context.TODO(), types.NamespacedName{Name: "test-dv", Namespace: metav1.NamespaceDefault}, pvc)
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
Expect(pvc.OwnerReferences).To(Equal([]metav1.OwnerReference{vmOwnerRef}))
|
||||||
|
Expect(pvc.Annotations[AnnGarbageCollected]).To(Equal("true"))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
var _ = Describe("shouldUseCDIPopulator", func() {
|
var _ = Describe("shouldUseCDIPopulator", func() {
|
||||||
|
Loading…
Reference in New Issue
Block a user