Skip to content

Commit

Permalink
pvc_deletion_protection
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin1689-cloud committed Mar 19, 2023
1 parent 8204954 commit 2cb9866
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/webhook/util/deletionprotection/deletion_protection.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ func ValidateNamespaceDeletion(c client.Client, namespace *v1.Namespace) error {
if activeCount > 0 {
return fmt.Errorf("forbidden by ResourcesProtectionDeletion for %s=%s and active pods %d>0", policyv1alpha1.DeletionProtectionKey, val, activeCount)
}

pvc := v1.PersistentVolumeClaimList{}
if err := c.List(context.TODO(), &pvc, client.InNamespace(namespace.Name)); err != nil {
return fmt.Errorf("forbidden by ResourcesProtectionDeletion for list pvc error: %v", err)
}
var pvcCount int
for range pvc.Items {
pvcCount++
}
if pvcCount > 0 {
return fmt.Errorf("forbidden by ResourcesProtectionDeletion for %s=%s and existing pvc %d>0", policyv1alpha1.DeletionProtectionKey, val, pvcCount)
}
default:
}
return nil
Expand Down

0 comments on commit 2cb9866

Please sign in to comment.