Fix: delete app won't be synced in UI (#3487)

* Fix: delete app won't be synced in UI

Signed-off-by: Jianbo Sun <jianbo.sjb@alibaba-inc.com>

* Fix: cache should be ignored in app meta not exist

Signed-off-by: Jianbo Sun <jianbo.sjb@alibaba-inc.com>
This commit is contained in:
Jianbo Sun
2022-03-22 10:04:10 +08:00
committed by GitHub
parent d9a676a688
commit 9a8ec5d797
5 changed files with 17 additions and 10 deletions
+2 -6
View File
@@ -185,12 +185,8 @@ func (s *addonWebService) enableAddon(req *restful.Request, res *restful.Respons
func (s *addonWebService) disableAddon(req *restful.Request, res *restful.Response) {
name := req.PathParameter("name")
forceParam := req.QueryParameter("force")
force, err := strconv.ParseBool(forceParam)
if err != nil {
bcode.ReturnError(req, res, err)
return
}
err = s.handler.DisableAddon(req.Request.Context(), name, force)
force, _ := strconv.ParseBool(forceParam)
err := s.handler.DisableAddon(req.Request.Context(), name, force)
if err != nil {
bcode.ReturnError(req, res, err)
return
+5 -4
View File
@@ -72,11 +72,12 @@ func (c *CR2UX) shouldSync(ctx context.Context, targetApp *v1beta1.Application,
cd := cachedData.(*cached)
// TODO(wonderflow): we should check targets if we sync that, it can avoid missing the status changed for targets updated in multi-cluster deploy, e.g. resumed suspend case.
if del {
// if app meta not exist, we should ignore the cache
_, _, err := c.getApp(ctx, targetApp.Name, targetApp.Namespace)
if del || err != nil {
c.cache.Delete(key)
return false
}
if cd.generation == targetApp.Generation && !del {
} else if cd.generation == targetApp.Generation {
logrus.Infof("app %s/%s with generation(%v) hasn't updated, ignore the sync event..", targetApp.Name, targetApp.Namespace, targetApp.Generation)
return false
}
+7
View File
@@ -84,8 +84,15 @@ var _ = Describe("Test Cache", func() {
Expect(cr2ux.shouldSync(ctx, app3, false)).Should(BeEquivalentTo(false))
Expect(ds.Put(ctx, &model.Application{Name: "app1", Labels: map[string]string{
model.LabelSyncGeneration: "1",
model.LabelSyncNamespace: "app1-ns",
}})).Should(BeNil())
cr2ux.syncCache(formatAppComposedName(app1.Name, app1.Namespace), 1, 0)
Expect(cr2ux.shouldSync(ctx, app1, false)).Should(BeEquivalentTo(false))
Expect(cr2ux.shouldSync(ctx, app1, true)).Should(BeEquivalentTo(true))
Expect(ds.Delete(ctx, &model.Application{Name: "app1"})).Should(BeNil())
Expect(cr2ux.shouldSync(ctx, app1, false)).Should(BeEquivalentTo(true))
})
+1
View File
@@ -155,6 +155,7 @@ var _ = Describe("Test CR convert to ux", func() {
Expect(cr2ux.DeleteApp(ctx, app1)).Should(BeNil())
Expect(ds.Get(context.Background(), &comp3)).Should(BeEquivalentTo(datastore.ErrRecordNotExist))
Expect(ds.Get(context.Background(), &model.Application{Name: apName1})).Should(BeEquivalentTo(datastore.ErrRecordNotExist))
})
})
+2
View File
@@ -19,6 +19,7 @@ package sync
import (
"context"
"errors"
"strings"
"github.com/oam-dev/kubevela/pkg/apiserver/datastore"
"github.com/oam-dev/kubevela/pkg/apiserver/log"
@@ -40,6 +41,7 @@ func StoreProject(ctx context.Context, name string, ds datastore.DataStore) erro
proj := &model.Project{
Name: name,
Description: model.AutoGenProj,
Alias: strings.Title(name),
}
return ds.Add(ctx, proj)
}