Fix: remove checks of the exists of release when delete app and repo
Signed-off-by: LiHui <andrewli@yunify.com>
This commit is contained in:
@@ -20,6 +20,7 @@ import (
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"io/ioutil"
|
||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/klog"
|
||||
"kubesphere.io/kubesphere/pkg/api"
|
||||
@@ -595,7 +596,11 @@ func (h *openpitrixHandler) GetAppVersionFiles(req *restful.Request, resp *restf
|
||||
|
||||
if err != nil {
|
||||
klog.Errorln(err)
|
||||
handleOpenpitrixError(resp, err)
|
||||
if apierrors.IsNotFound(err) {
|
||||
api.HandleNotFound(resp, nil, err)
|
||||
} else {
|
||||
api.HandleBadRequest(resp, nil, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -324,25 +324,16 @@ func (c *applicationOperator) DeleteApp(id string) error {
|
||||
app, err := c.appLister.Get(id)
|
||||
if err != nil {
|
||||
if apierrors.IsNotFound(err) {
|
||||
klog.V(4).Infof("app %s has been deleted", id)
|
||||
return nil
|
||||
} else {
|
||||
klog.Error(err)
|
||||
return nil
|
||||
klog.Errorf("get app %s failed, error: %s", id, err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
ls := map[string]string{
|
||||
constants.ChartApplicationIdLabelKey: app.GetHelmApplicationId(),
|
||||
}
|
||||
releases, err := c.rlsLister.List(labels.SelectorFromSet(ls))
|
||||
|
||||
if err != nil && !apierrors.IsNotFound(err) {
|
||||
klog.Error(err)
|
||||
return err
|
||||
} else if len(releases) > 0 {
|
||||
return fmt.Errorf("app %s has releases not deleted", id)
|
||||
}
|
||||
|
||||
list, err := c.versionLister.List(labels.SelectorFromSet(ls))
|
||||
if err != nil {
|
||||
|
||||
@@ -114,28 +114,6 @@ func (c *applicationOperator) DeleteAppVersion(id string) error {
|
||||
return actionNotPermitted
|
||||
}
|
||||
|
||||
// check release
|
||||
rls, err := c.rlsLister.List(labels.SelectorFromSet(map[string]string{constants.ChartApplicationVersionIdLabelKey: id}))
|
||||
if err != nil && !apierrors.IsNotFound(err) {
|
||||
return err
|
||||
}
|
||||
if len(rls) > 0 {
|
||||
klog.V(4).Infof("There are releases use data from app version %s", id)
|
||||
infoMap := make(map[string]string)
|
||||
allString := &bytes.Buffer{}
|
||||
for _, r := range rls {
|
||||
info := fmt.Sprintf("%s/%s", r.GetWorkspace(), r.GetRlsNamespace())
|
||||
if _, exists := infoMap[info]; !exists {
|
||||
infoMap[info] = ""
|
||||
allString.WriteString(info)
|
||||
if len(infoMap) > 1 {
|
||||
allString.WriteString(",")
|
||||
}
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("release exists: %s", allString.String())
|
||||
}
|
||||
|
||||
// Delete data in storage
|
||||
err = c.backingStoreClient.Delete(dataKeyInStorage(appVersion.GetWorkspace(), id))
|
||||
if err != nil {
|
||||
|
||||
@@ -267,6 +267,11 @@ func (c *releaseOperator) ListApplications(workspace, clusterName, namespace str
|
||||
ls[constants.ChartApplicationVersionIdLabelKey] = versionId
|
||||
}
|
||||
|
||||
repoId := conditions.Match[RepoId]
|
||||
if repoId != "" {
|
||||
ls[constants.ChartRepoIdLabelKey] = repoId
|
||||
}
|
||||
|
||||
if workspace != "" {
|
||||
ls[constants.WorkspaceLabelKey] = workspace
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ package openpitrix
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/go-openapi/strfmt"
|
||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
@@ -126,7 +125,7 @@ func (c *repoOperator) CreateRepo(repo *v1alpha1.HelmRepo) (*CreateRepoResponse,
|
||||
repo.Spec.Description = stringutils.ShortenString(repo.Spec.Description, DescriptionLen)
|
||||
_, err = c.repoClient.HelmRepos().Create(context.TODO(), repo, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
klog.Errorf("create helm repo failed, repod_id: %s, error: %s", repo.GetHelmRepoId(), err)
|
||||
klog.Errorf("create helm repo failed, repo_id: %s, error: %s", repo.GetHelmRepoId(), err)
|
||||
return nil, err
|
||||
} else {
|
||||
klog.V(4).Infof("create helm repo success, repo_id: %s", repo.GetHelmRepoId())
|
||||
@@ -136,20 +135,10 @@ func (c *repoOperator) CreateRepo(repo *v1alpha1.HelmRepo) (*CreateRepoResponse,
|
||||
}
|
||||
|
||||
func (c *repoOperator) DeleteRepo(id string) error {
|
||||
ls := map[string]string{
|
||||
constants.ChartRepoIdLabelKey: id,
|
||||
}
|
||||
releases, err := c.rlsLister.List(labels.SelectorFromSet(ls))
|
||||
|
||||
if err != nil && apierrors.IsNotFound(err) {
|
||||
return err
|
||||
} else if len(releases) > 0 {
|
||||
return fmt.Errorf("repo %s has releases not deleted", id)
|
||||
}
|
||||
|
||||
var err error
|
||||
err = c.repoClient.HelmRepos().Delete(context.TODO(), id, metav1.DeleteOptions{})
|
||||
if err != nil && apierrors.IsNotFound(err) {
|
||||
klog.Error(err)
|
||||
if err != nil && !apierrors.IsNotFound(err) {
|
||||
klog.Errorf("delete repo %s failed, error: %s", id, err)
|
||||
return err
|
||||
}
|
||||
klog.V(4).Infof("repo %s deleted", id)
|
||||
|
||||
Reference in New Issue
Block a user