Fix: conflict while using gc policy and shared-resource policy concurrently

Signed-off-by: Somefive <yd219913@alibaba-inc.com>
This commit is contained in:
Somefive
2023-01-13 13:27:32 +08:00
parent 5ec3bd5ef7
commit f8239be21e
3 changed files with 48 additions and 0 deletions

View File

@@ -371,6 +371,7 @@ func DeleteManagedResourceInApplication(ctx context.Context, cli client.Client,
}
return nil
}
util.RemoveAnnotations(obj, []string{oam.AnnotationAppSharedBy})
}
if mr.SkipGC || hasOrphanFinalizer(app) {
if labels := obj.GetLabels(); labels != nil {

View File

@@ -912,5 +912,26 @@ var _ = Describe("Test multicluster scenario", func() {
g.Expect(cnt).Should(Equal(1))
}).WithTimeout(30 * time.Second).WithPolling(2 * time.Second).Should(Succeed())
})
It("Test application with gc policy and shared-resource policy", func() {
app := &v1beta1.Application{}
bs, err := os.ReadFile("./testdata/app/app-gc-shared.yaml")
Expect(err).Should(Succeed())
Expect(yaml.Unmarshal(bs, app)).Should(Succeed())
app.SetNamespace(namespace)
Expect(k8sClient.Create(hubCtx, app)).Should(Succeed())
appKey := client.ObjectKeyFromObject(app)
Eventually(func(g Gomega) {
g.Expect(k8sClient.Get(hubCtx, appKey, app)).Should(Succeed())
g.Expect(app.Status.Phase).Should(Equal(common.ApplicationRunning))
g.Expect(k8sClient.Get(hubCtx, appKey, &corev1.ConfigMap{})).Should(Succeed())
}).WithTimeout(10 * time.Second).Should(Succeed())
Expect(k8sClient.Get(hubCtx, appKey, app)).Should(Succeed())
Expect(k8sClient.Delete(hubCtx, app)).Should(Succeed())
Eventually(func(g Gomega) {
g.Expect(kerrors.IsNotFound(k8sClient.Get(hubCtx, appKey, app))).Should(BeTrue())
g.Expect(k8sClient.Get(hubCtx, appKey, &corev1.ConfigMap{})).Should(Succeed())
}).WithTimeout(10 * time.Second).Should(Succeed())
})
})
})

View File

@@ -0,0 +1,26 @@
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: app-gc-shared
spec:
components:
- type: k8s-objects
name: app-gc-shared
properties:
objects:
- apiVersion: v1
kind: ConfigMap
policies:
- name: gc-policy
type: garbage-collect
properties:
rules:
- selector:
resourceTypes: ["ConfigMap"]
strategy: never
- name: shared-policy
type: shared-resource
properties:
rules:
- selector:
resourceTypes: ["ConfigMap"]