mirror of
https://github.com/kubevela/kubevela.git
synced 2026-04-20 09:37:17 +00:00
Fix: the history applications are repeatedly synchronized
Signed-off-by: barnettZQG <barnett.zqg@gmail.com>
This commit is contained in:
@@ -77,6 +77,11 @@ func (c *CR2UX) shouldSync(ctx context.Context, targetApp *v1beta1.Application,
|
||||
}
|
||||
}
|
||||
|
||||
// if no LabelSourceOfTruth label, it means the app is existing ones, check the existing labels and annotations
|
||||
if _, appName := targetApp.Annotations[oam.AnnotationAppName]; appName {
|
||||
return false
|
||||
}
|
||||
|
||||
key := formatAppComposedName(targetApp.Name, targetApp.Namespace)
|
||||
cachedData, ok := c.cache.Load(key)
|
||||
if ok {
|
||||
|
||||
@@ -27,35 +27,8 @@ import (
|
||||
"github.com/oam-dev/kubevela/pkg/apiserver/domain/service"
|
||||
"github.com/oam-dev/kubevela/pkg/apiserver/infrastructure/datastore"
|
||||
"github.com/oam-dev/kubevela/pkg/apiserver/utils/log"
|
||||
"github.com/oam-dev/kubevela/pkg/oam"
|
||||
)
|
||||
|
||||
// CheckSoTFromCR will check the source of truth of the application
|
||||
func CheckSoTFromCR(targetApp *v1beta1.Application) string {
|
||||
if sot := targetApp.Annotations[model.LabelSourceOfTruth]; sot != "" {
|
||||
return sot
|
||||
}
|
||||
// if no LabelSourceOfTruth label, it means the app is existing ones, check the existing labels and annotations
|
||||
if _, appName := targetApp.Annotations[oam.AnnotationAppName]; appName {
|
||||
return model.FromUX
|
||||
}
|
||||
// no labels mean it's created by K8s resources.
|
||||
return model.FromCR
|
||||
}
|
||||
|
||||
// CheckSoTFromAppMeta will check the source of truth marked in datastore
|
||||
func (c *CR2UX) CheckSoTFromAppMeta(ctx context.Context, appName, namespace string, sotFromCR string) string {
|
||||
|
||||
app, _, err := c.getApp(ctx, appName, namespace)
|
||||
if err != nil {
|
||||
return sotFromCR
|
||||
}
|
||||
if app.Labels == nil || app.Labels[model.LabelSourceOfTruth] == "" {
|
||||
return sotFromCR
|
||||
}
|
||||
return app.Labels[model.LabelSourceOfTruth]
|
||||
}
|
||||
|
||||
// getApp will return the app and appname if exists
|
||||
func (c *CR2UX) getApp(ctx context.Context, name, namespace string) (*model.Application, string, error) {
|
||||
alreadyCreated := &model.Application{Name: formatAppComposedName(name, namespace)}
|
||||
|
||||
Reference in New Issue
Block a user