Skip to content

Commit

Permalink
PB-6904:Functions to delete pv pvc with force option
Browse files Browse the repository at this point in the history
  • Loading branch information
aks-px committed May 15, 2024
1 parent ff0ae32 commit dab7553
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions k8s/core/persistentvolumeclaims.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ type PersistentVolumeClaimOps interface {
UpdatePersistentVolumeClaim(*corev1.PersistentVolumeClaim) (*corev1.PersistentVolumeClaim, error)
// DeletePersistentVolumeClaim deletes the given persistent volume claim
DeletePersistentVolumeClaim(name, namespace string) error
// DeletePersistentVolumeClaimWithForce deletes the given persistent volume claim with force option
DeletePersistentVolumeClaimWithForce(name, namespace string) error
// ValidatePersistentVolumeClaim validates the given pvc
ValidatePersistentVolumeClaim(vv *corev1.PersistentVolumeClaim, timeout, retryInterval time.Duration) error
// ValidatePersistentVolumeClaimSize validates the given pvc size
Expand All @@ -36,6 +38,8 @@ type PersistentVolumeClaimOps interface {
GetPersistentVolume(pvName string) (*corev1.PersistentVolume, error)
// DeletePersistentVolume deletes the PV for given name
DeletePersistentVolume(pvName string) error
// DeletePersistentVolumeWithForce deletes the PV for given name with force option
DeletePersistentVolumeWithForce(pvName string) error
// GetPersistentVolumes returns all PVs in cluster
GetPersistentVolumes() (*corev1.PersistentVolumeList, error)
//UpdatePersistentVolume updates PV
Expand Down Expand Up @@ -91,6 +95,18 @@ func (c *Client) DeletePersistentVolumeClaim(name, namespace string) error {
return c.kubernetes.CoreV1().PersistentVolumeClaims(namespace).Delete(context.TODO(), name, metav1.DeleteOptions{})
}

// DeletePersistentVolumeClaimWithForce deletes the given persistentvolumeclaim with force option
func (c *Client) DeletePersistentVolumeClaimWithForce(name, namespace string) error {
if err := c.initClient(); err != nil {
return err
}
gracePeriodSec := int64(0)
deleteOptions := metav1.DeleteOptions{
GracePeriodSeconds: &gracePeriodSec,
}
return c.kubernetes.CoreV1().PersistentVolumeClaims(namespace).Delete(context.TODO(), name, deleteOptions)
}

// ValidatePersistentVolumeClaim validates the given pvc
func (c *Client) ValidatePersistentVolumeClaim(pvc *corev1.PersistentVolumeClaim, timeout, retryInterval time.Duration) error {
t := func() (interface{}, bool, error) {
Expand Down Expand Up @@ -211,6 +227,18 @@ func (c *Client) DeletePersistentVolume(pvName string) error {
})
}

// DeletePersistentVolumeWithForce deletes the PV for given name with force option
func (c *Client) DeletePersistentVolumeWithForce(pvName string) error {
if err := c.initClient(); err != nil {
return err
}
gracePeriodSec := int64(0)
deleteOptions := metav1.DeleteOptions{
GracePeriodSeconds: &gracePeriodSec,
}
return c.kubernetes.CoreV1().PersistentVolumes().Delete(context.TODO(), pvName, deleteOptions)
}

// GetPersistentVolumes returns all PVs in cluster
func (c *Client) GetPersistentVolumes() (*corev1.PersistentVolumeList, error) {
if err := c.initClient(); err != nil {
Expand Down

0 comments on commit dab7553

Please sign in to comment.