Feat: support per-application reconciliation interval override via annotation (#7089)

* Feat: support per-application reconciliation interval override via annotation

Add the app.oam.dev/reconcile-interval annotation that lets operators
override the global ApplicationReSyncPeriod on a per-application basis.
This is useful when different applications have different drift-detection
needs: a production app might need reconciliation every minute while a
dev/staging app can safely use a longer interval to reduce API server load.

When the annotation is present and contains a valid Go duration string
(e.g. "1m", "15m", "30s") at or above the 10s minimum floor, the
controller uses that value as RequeueAfter instead of the global default.
Invalid or below-minimum values are logged as warnings and silently fall
back to the global default, preserving full backward compatibility.

The implementation adds a forApp() chain method to reconcileResult so that
only the return paths where the default resync period matters (normal
completion and error recovery) need to be annotated, leaving all explicit
requeue() calls untouched.

Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>

* test: add e2e coverage for app reconcile interval

Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>

* chore: trigger ci rerun

Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>

* fix: address reconcile interval review feedback

Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>

* fix: satisfy reconcile interval lint

Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>

---------

Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
This commit is contained in:
Asish Kumar
2026-05-05 14:24:33 -07:00
committed by GitHub
parent c81b141302
commit 5664912a4c
4 changed files with 229 additions and 5 deletions
+33
View File
@@ -37,6 +37,7 @@ import (
common2 "github.com/oam-dev/kubevela/apis/core.oam.dev/common"
"github.com/oam-dev/kubevela/apis/core.oam.dev/condition"
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
"github.com/oam-dev/kubevela/pkg/oam"
"github.com/oam-dev/kubevela/pkg/utils/common"
)
@@ -109,6 +110,38 @@ var _ = Describe("Application Resource-Related Policy Tests", func() {
Expect(deploy.Spec.Replicas).Should(Equal(ptr.To(int32(0))))
})
It("Test per-application reconcile interval override", func() {
By("create app with custom reconcile interval")
app := &v1beta1.Application{}
Expect(common.ReadYamlToObject("testdata/app/app_apply_once.yaml", app)).Should(BeNil())
app.SetNamespace(namespace)
app.SetAnnotations(map[string]string{oam.AnnotationReconcileInterval: "10s"})
Expect(k8sClient.Create(ctx, app)).Should(Succeed())
appKey := client.ObjectKeyFromObject(app)
Eventually(func(g Gomega) {
g.Expect(k8sClient.Get(ctx, appKey, app)).Should(Succeed())
g.Expect(app.Status.Phase).Should(Equal(common2.ApplicationRunning))
}, 30*time.Second, time.Second*3).Should(Succeed())
// Let status-update reconciles from app creation drain before mutating
// the workload, so the repair depends on the scheduled interval.
time.Sleep(12 * time.Second)
By("mutate managed workload without forcing application reconciliation")
deploy := &v13.Deployment{}
deployKey := types.NamespacedName{Namespace: namespace, Name: "hello-world"}
Eventually(func(g Gomega) {
g.Expect(k8sClient.Get(ctx, deployKey, deploy)).Should(Succeed())
deploy.Spec.Replicas = ptr.To(int32(0))
g.Expect(k8sClient.Update(ctx, deploy)).Should(Succeed())
}, 10*time.Second, time.Second).Should(Succeed())
By("scheduled reconciliation restores the workload through state keep")
Eventually(func(g Gomega) {
g.Expect(k8sClient.Get(ctx, deployKey, deploy)).Should(Succeed())
g.Expect(deploy.Spec.Replicas).Should(Equal(ptr.To(int32(1))))
}, 45*time.Second, time.Second).Should(Succeed())
})
It("Test GarbageCollect Policy", func() {
By("create garbage-collect app")
app := &v1beta1.Application{}