Feat: ignore control check for resource without resource version (#4557)

Signed-off-by: Somefive <yd219913@alibaba-inc.com>
(cherry picked from commit 71554adbf1)

Co-authored-by: Somefive <yd219913@alibaba-inc.com>
This commit is contained in:
github-actions[bot]
2022-08-04 15:30:11 +08:00
committed by GitHub
co-authored by Somefive
parent e29b1af202
commit b0facbeaab
2 changed files with 21 additions and 4 deletions
+4 -1
View File
@@ -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 {
+17 -3
View File
@@ -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) {