Skip to content

Commit

Permalink
Remove VolumeClaim ref from Volume when the VolumeClaim can not…
Browse files Browse the repository at this point in the history
… be found (#318)
  • Loading branch information
nikhilbarge authored Feb 24, 2022
1 parent 4df78c9 commit 73f001a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions controllers/storage/volume_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ func (r *VolumeReconciler) reconcile(ctx context.Context, log logr.Logger, volum
if err := r.updateVolumePhase(ctx, log, volume, storagev1alpha1.VolumeAvailable); err != nil {
return ctrl.Result{}, err
}
baseVolume := volume.DeepCopy()
volume.Spec.ClaimRef = storagev1alpha1.ClaimReference{}
if err := r.Patch(ctx, volume, client.MergeFrom(baseVolume)); err != nil {
return ctrl.Result{}, fmt.Errorf("could not remove claim to volume %s: %w", client.ObjectKeyFromObject(volume), err)
}
return ctrl.Result{}, nil
}
if claim.Spec.VolumeRef.Name == volume.Name && volume.Spec.ClaimRef.UID == claim.UID {
Expand Down
1 change: 1 addition & 0 deletions controllers/storage/volume_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ var _ = Describe("VolumeReconciler", func() {
Eventually(func(g Gomega) {
Expect(k8sClient.Get(ctx, volumeKey, volume)).To(Succeed(), "failed to get volume")
g.Expect(volume.Status.Phase).To(Equal(storagev1alpha1.VolumeAvailable))
g.Expect(volume.Spec.ClaimRef.Name).To(Equal(""))
}, timeout, interval).Should(Succeed())
})
})

0 comments on commit 73f001a

Please sign in to comment.