diff --git a/pkg/utils/apply/apply.go b/pkg/utils/apply/apply.go index 4dee4a8c6..0bc111912 100644 --- a/pkg/utils/apply/apply.go +++ b/pkg/utils/apply/apply.go @@ -299,7 +299,10 @@ func MustBeControlledByApp(app *v1beta1.Application) ApplyOption { return nil } appKey, controlledBy := GetAppKey(app), GetControlledBy(existing) - if controlledBy == "" && !utilfeature.DefaultMutableFeatureGate.Enabled(features.LegacyResourceOwnerValidation) { + // if the existing object has no resource version, it means this resource is an API response not directly from + // an etcd object but from some external services, such as vela-prism. Then the response does not necessarily + // contain the owner + if controlledBy == "" && !utilfeature.DefaultMutableFeatureGate.Enabled(features.LegacyResourceOwnerValidation) && existing.GetResourceVersion() != "" { return fmt.Errorf("%s %s/%s exists but not managed by any application now", existing.GetObjectKind().GroupVersionKind().Kind, existing.GetNamespace(), existing.GetName()) } if controlledBy != "" && controlledBy != appKey { diff --git a/pkg/utils/apply/apply_test.go b/pkg/utils/apply/apply_test.go index a8176dcd9..91359fc57 100644 --- a/pkg/utils/apply/apply_test.go +++ b/pkg/utils/apply/apply_test.go @@ -380,18 +380,20 @@ func TestMustBeControlledByApp(t *testing.T) { hasError: false, }, "old app has no label": { - existing: &appsv1.Deployment{}, + existing: &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{ResourceVersion: "-"}}, hasError: true, }, "old app has no app label": { existing: &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{ - Labels: map[string]string{}, + Labels: map[string]string{}, + ResourceVersion: "-", }}, hasError: true, }, "old app has no app ns label": { existing: &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{ - Labels: map[string]string{oam.LabelAppName: "app"}, + Labels: map[string]string{oam.LabelAppName: "app"}, + ResourceVersion: "-", }}, hasError: true, }, @@ -413,6 +415,18 @@ func TestMustBeControlledByApp(t *testing.T) { }}, hasError: true, }, + "old app has no resource version but with bad app key": { + existing: &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{ + Labels: map[string]string{oam.LabelAppName: "app", oam.LabelAppNamespace: "ns"}, + }}, + hasError: true, + }, + "old app has no resource version": { + existing: &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{ + Labels: map[string]string{}, + }}, + hasError: false, + }, } for name, tc := range testCases { t.Run(name, func(t *testing.T) {