Skip to content

Commit

Permalink
Merge pull request #45 from wunderio/feature/remove-instance
Browse files Browse the repository at this point in the history
Remove pvc based on helm instance label
  • Loading branch information
Jancis authored Aug 10, 2023
2 parents 0150e83 + a98b28a commit 16f3a37
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions cmd/ciReleaseDelete.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,32 @@ var ciReleaseDeleteCmd = &cobra.Command{
}

//Delete PVCs
if deletePVCs == true {
if deletePVCs {

PVC_client := clientset.CoreV1().PersistentVolumeClaims(namespace)
list, err := PVC_client.List(context.TODO(), v1.ListOptions{
LabelSelector: "release=" + releaseName,
})
if err != nil {
log.Fatalf("Error getting the list of PVCs: %s", err)

selectorLabels := []string{
"app",
"release",
"app.kubernetes.io/instance",
}

for _, v := range list.Items {
PVC_client.Delete(context.TODO(), v.Name, v1.DeleteOptions{})
for _, l := range selectorLabels {
selector := l + "=" + releaseName
if l == "app" {
selector = l + "=" + releaseName + "-es"
}
list, err := PVC_client.List(context.TODO(), v1.ListOptions{
LabelSelector: selector,
})
if err != nil {
log.Fatalf("Error getting the list of PVCs: %s", err)
}

for _, v := range list.Items {
log.Printf("Deleting PVC: %s", v.Name)
PVC_client.Delete(context.TODO(), v.Name, v1.DeleteOptions{})
}
}
}

Expand Down

0 comments on commit 16f3a37

Please sign in to comment.