Skip to content

Commit

Permalink
http-serivce: add delete tidbcluster api
Browse files Browse the repository at this point in the history
  • Loading branch information
z2665 committed Nov 4, 2023
1 parent 073d54a commit c220456
Showing 1 changed file with 54 additions and 3 deletions.
57 changes: 54 additions & 3 deletions cmd/http-service/server/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -1015,11 +1015,62 @@ func (s *ClusterServer) DeleteCluster(ctx context.Context, req *api.DeleteCluste
return &api.DeleteClusterResp{Success: false, Message: &message}, nil
}
// delete tm
if err := opCli.PingcapV1alpha1().TidbMonitors(req.ClusterId).Delete(ctx, tidbMonitorName, metav1.DeleteOptions{}); err != nil {
if apierrors.IsNotFound(err) {
logger.Warn("TidbMonitor not found", zap.Error(err))
} else {
logger.Error("Delete TidbMonitor failed", zap.Error(err))
setResponseStatusCodes(ctx, http.StatusInternalServerError)
message := fmt.Sprintf("delete TidbMonitor failed: %s", err.Error())
return &api.DeleteClusterResp{Success: false, Message: &message}, nil
}

}
// delete init and secret
if err := opCli.PingcapV1alpha1().TidbInitializers(req.ClusterId).Delete(ctx, tidbInitializerName, metav1.DeleteOptions{}); err != nil {
if apierrors.IsNotFound(err) {
logger.Warn("TidbInitializer not found", zap.Error(err))
} else {
logger.Error("Delete TidbInitializer failed", zap.Error(err))
setResponseStatusCodes(ctx, http.StatusInternalServerError)
message := fmt.Sprintf("delete TidbInitializer failed: %s", err.Error())
return &api.DeleteClusterResp{Success: false, Message: &message}, nil
}
}
if err := kubeCli.CoreV1().Secrets(req.ClusterId).Delete(ctx, tidbInitializerPasswordSecret, metav1.DeleteOptions{}); err != nil {
if apierrors.IsNotFound(err) {
logger.Warn("TidbInitializer password secret not found", zap.Error(err))
} else {
logger.Error("Delete TidbInitializer password secret failed", zap.Error(err))
setResponseStatusCodes(ctx, http.StatusInternalServerError)
message := fmt.Sprintf("delete TidbInitializer password secret failed: %s", err.Error())
return &api.DeleteClusterResp{Success: false, Message: &message}, nil
}
}
// delete tc
if _, err = opCli.PingcapV1alpha1().TidbMonitors(req.ClusterId).Get(ctx,req.ClusterId); err != nil {
if apierrors.IsAlreadyExists(err) {}
return nil, errors.New("DeleteCluster not implemented")
if err := opCli.PingcapV1alpha1().TidbClusters(req.ClusterId).Delete(ctx, tidbClusterName, metav1.DeleteOptions{}); err != nil {
if apierrors.IsNotFound(err) {
logger.Warn("TidbCluster not found", zap.Error(err))
} else {
logger.Error("Delete TidbCluster failed", zap.Error(err))
setResponseStatusCodes(ctx, http.StatusInternalServerError)
message := fmt.Sprintf("delete TidbCluster failed: %s", err.Error())
return &api.DeleteClusterResp{Success: false, Message: &message}, nil
}

}
// delete ns
if err := kubeCli.CoreV1().Namespaces().Delete(ctx, req.ClusterId, metav1.DeleteOptions{}); err != nil {
if apierrors.IsNotFound(err) {
logger.Warn("Namespace not found", zap.Error(err))
} else {
logger.Error("Delete Namespace failed", zap.Error(err))
setResponseStatusCodes(ctx, http.StatusInternalServerError)
message := fmt.Sprintf("delete Namespace failed: %s", err.Error())
return &api.DeleteClusterResp{Success: false, Message: &message}, nil
}
}
return &api.DeleteClusterResp{Success: true}, nil
}

// RestartCluster
Expand Down

0 comments on commit c220456

Please sign in to comment.