Merge pull request #3590 from xyz-li/app-fix1
Fix: remove checks when delete release
This commit is contained in:
@@ -126,3 +126,7 @@ func (in *HelmApplication) State() string {
|
||||
}
|
||||
return in.Status.State
|
||||
}
|
||||
|
||||
func (in *HelmApplication) GetCreator() string {
|
||||
return getValue(in.Annotations, constants.CreatorAnnotationKey)
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ func (r *ReconcileHelmApplication) Reconcile(request reconcile.Request) (reconci
|
||||
if !sliceutil.HasString(app.ObjectMeta.Finalizers, appFinalizer) {
|
||||
app.ObjectMeta.Finalizers = append(app.ObjectMeta.Finalizers, appFinalizer)
|
||||
if err := r.Update(rootCtx, app); err != nil {
|
||||
return ctrl.Result{}, err
|
||||
return reconcile.Result{}, err
|
||||
}
|
||||
// create app success
|
||||
appOperationTotal.WithLabelValues("creation", app.GetTrueName(), strconv.FormatBool(inAppStore(app))).Inc()
|
||||
@@ -78,7 +78,11 @@ func (r *ReconcileHelmApplication) Reconcile(request reconcile.Request) (reconci
|
||||
if !inAppStore(app) {
|
||||
if app.Status.State == v1alpha1.StateActive ||
|
||||
app.Status.State == v1alpha1.StateSuspended {
|
||||
return reconcile.Result{}, r.createAppCopyInAppStore(rootCtx, app)
|
||||
if err := r.createAppCopyInAppStore(rootCtx, app); err != nil {
|
||||
klog.Errorf("create app copy failed, error: %s", err)
|
||||
return reconcile.Result{}, err
|
||||
}
|
||||
return reconcile.Result{}, nil
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -120,9 +124,9 @@ func (r *ReconcileHelmApplication) deleteAppCopyInAppStore(ctx context.Context,
|
||||
return nil
|
||||
}
|
||||
|
||||
// create a application copy in app store
|
||||
func (r *ReconcileHelmApplication) createAppCopyInAppStore(ctx context.Context, from *v1alpha1.HelmApplication) error {
|
||||
name := fmt.Sprintf("%s%s", from.Name, v1alpha1.HelmApplicationAppStoreSuffix)
|
||||
// createAppCopyInAppStore create a application copy in app store
|
||||
func (r *ReconcileHelmApplication) createAppCopyInAppStore(ctx context.Context, originApp *v1alpha1.HelmApplication) error {
|
||||
name := fmt.Sprintf("%s%s", originApp.Name, v1alpha1.HelmApplicationAppStoreSuffix)
|
||||
|
||||
app := &v1alpha1.HelmApplication{}
|
||||
err := r.Get(ctx, types.NamespacedName{Name: name}, app)
|
||||
@@ -132,23 +136,25 @@ func (r *ReconcileHelmApplication) createAppCopyInAppStore(ctx context.Context,
|
||||
|
||||
if app.Name == "" {
|
||||
app.Name = name
|
||||
labels := from.Labels
|
||||
labels := originApp.Labels
|
||||
if len(labels) == 0 {
|
||||
labels = make(map[string]string, 3)
|
||||
}
|
||||
labels[constants.ChartRepoIdLabelKey] = v1alpha1.AppStoreRepoId
|
||||
|
||||
// assign a category to app
|
||||
// assign a default category to app
|
||||
if labels[constants.CategoryIdLabelKey] == "" {
|
||||
labels[constants.CategoryIdLabelKey] = v1alpha1.UncategorizedId
|
||||
}
|
||||
labels[v1alpha1.OriginWorkspaceLabelKey] = from.GetWorkspace()
|
||||
|
||||
// record the original workspace
|
||||
labels[v1alpha1.OriginWorkspaceLabelKey] = originApp.GetWorkspace()
|
||||
// apps in store are global resource.
|
||||
delete(labels, constants.WorkspaceLabelKey)
|
||||
|
||||
app.Annotations = originApp.Annotations
|
||||
app.Labels = labels
|
||||
|
||||
app.Spec = *from.Spec.DeepCopy()
|
||||
app.Spec = *originApp.Spec.DeepCopy()
|
||||
|
||||
err = r.Create(context.TODO(), app)
|
||||
if err != nil {
|
||||
@@ -158,7 +164,7 @@ func (r *ReconcileHelmApplication) createAppCopyInAppStore(ctx context.Context,
|
||||
|
||||
if app.Status.State == "" {
|
||||
// update status if needed
|
||||
return updateHelmApplicationStatus(r.Client, from.Name, true)
|
||||
return updateHelmApplicationStatus(r.Client, originApp.Name, true)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -171,6 +171,7 @@ func (c *releaseOperator) CreateApplication(workspace, clusterName, namespace st
|
||||
},
|
||||
Spec: v1alpha1.HelmReleaseSpec{
|
||||
Name: request.Name,
|
||||
Description: stringutils.ShortenString(request.Description, v1alpha1.MsgLen),
|
||||
Version: 1,
|
||||
Values: strfmt.Base64(request.Conf),
|
||||
ApplicationId: strings.TrimSuffix(request.AppId, v1alpha1.HelmApplicationAppStoreSuffix),
|
||||
@@ -267,6 +268,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)
|
||||
|
||||
@@ -738,6 +738,9 @@ type CreateClusterRequest struct {
|
||||
// release name
|
||||
Name string `json:"name"`
|
||||
|
||||
// release install description
|
||||
Description string `json:"description"`
|
||||
|
||||
// advanced param
|
||||
AdvancedParam []string `json:"advanced_param"`
|
||||
|
||||
|
||||
@@ -336,6 +336,7 @@ func convertApp(app *v1alpha1.HelmApplication, versions []*v1alpha1.HelmApplicat
|
||||
out.Isv = app.GetWorkspace()
|
||||
|
||||
out.ClusterTotal = &rlsCount
|
||||
out.Owner = app.GetCreator()
|
||||
|
||||
return out
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user