Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PB-6904:Functions to delete pv pvc with force option #388

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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