From b7170fa35678798603a52e0fdcd2a51d07aaa90a Mon Sep 17 00:00:00 2001 From: z2665 Date: Mon, 6 Nov 2023 16:29:29 +0800 Subject: [PATCH] delete all pvc in tidbcluster ns (#5373) --- cmd/http-service/server/cluster.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/cmd/http-service/server/cluster.go b/cmd/http-service/server/cluster.go index ac83ccf098e..35f7b5baffc 100644 --- a/cmd/http-service/server/cluster.go +++ b/cmd/http-service/server/cluster.go @@ -1158,6 +1158,17 @@ func (s *ClusterServer) DeleteCluster(ctx context.Context, req *api.DeleteCluste } // we don't delete the ns for now, since some backup may still stored in it + // TODO(http-service): we delete all pvc in ns for now, but we may only delete tidbcluster pvc in future + if err := kubeCli.CoreV1().PersistentVolumeClaims(req.ClusterId).DeleteCollection(ctx, metav1.DeleteOptions{}, metav1.ListOptions{}); err != nil { + if apierrors.IsNotFound(err) { + logger.Warn("PersistentVolumeClaims not found", zap.Error(err)) + } else { + logger.Error("Delete PersistentVolumeClaims failed", zap.Error(err)) + setResponseStatusCodes(ctx, http.StatusInternalServerError) + message := fmt.Sprintf("delete PersistentVolumeClaims failed: %s", err.Error()) + return &api.DeleteClusterResp{Success: false, Message: &message}, nil + } + } return &api.DeleteClusterResp{Success: true}, nil }