Unverified Commit fbef61d0 authored by github-actions[bot]'s avatar github-actions[bot] Committed by GitHub
Browse files

[Backport release-1.2] Fix: disable cochange for apprev when def changes (#3221)


* Fix: disable cochange for apprev when def changes
Signed-off-by: default avatarSomefive <yd219913@alibaba-inc.com>
(cherry picked from commit f67d1c7e08418dd1c93d70ba45ff5a4363d63369)

* Fix: add test
Signed-off-by: default avatarSomefive <yd219913@alibaba-inc.com>
(cherry picked from commit e3f95763ae0d38d61dff8bc4b9e4c542a54e0854)
Co-authored-by: default avatarSomefive <yd219913@alibaba-inc.com>
Showing with 36 additions and 1 deletion
+36 -1
......@@ -374,11 +374,17 @@ func (h *AppHandler) currentAppRevIsNew(ctx context.Context) (bool, bool, error)
return true, true, nil
}
isLatestRev := deepEqualAppInRevision(h.latestAppRev, h.currentAppRev)
if metav1.HasAnnotation(h.app.ObjectMeta, oam.AnnotationAutoUpdate) {
isLatestRev = h.app.Status.LatestRevision.RevisionHash == h.currentRevHash && DeepEqualRevision(h.latestAppRev, h.currentAppRev)
}
// diff the latest revision first
if h.app.Status.LatestRevision.RevisionHash == h.currentRevHash && DeepEqualRevision(h.latestAppRev, h.currentAppRev) {
if isLatestRev {
appSpec := h.currentAppRev.Spec.Application.Spec
traitDef := h.currentAppRev.Spec.TraitDefinitions
h.currentAppRev = h.latestAppRev.DeepCopy()
h.currentRevHash = h.app.Status.LatestRevision.RevisionHash
h.currentAppRev.Spec.Application.Spec = appSpec
h.currentAppRev.Spec.TraitDefinitions = traitDef
return false, false, nil
......@@ -444,6 +450,10 @@ func DeepEqualRevision(old, new *v1beta1.ApplicationRevision) bool {
return false
}
}
return deepEqualAppInRevision(old, new)
}
func deepEqualAppInRevision(old, new *v1beta1.ApplicationRevision) bool {
return apiequality.Semantic.DeepEqual(filterSkipAffectAppRevTrait(old.Spec.Application.Spec, old.Spec.TraitDefinitions),
filterSkipAffectAppRevTrait(new.Spec.Application.Spec, new.Spec.TraitDefinitions))
}
......
......@@ -245,6 +245,28 @@ var _ = Describe("test generate revision ", func() {
verifyDeepEqualRevision()
})
It("Test application revision compare", func() {
By("Apply the application")
appParser := appfile.NewApplicationParser(reconciler.Client, reconciler.dm, reconciler.pd)
ctx = util.SetNamespaceInCtx(ctx, app.Namespace)
generatedAppfile, err := appParser.GenerateAppFile(ctx, &app)
Expect(err).Should(Succeed())
comps, err = generatedAppfile.GenerateComponentManifests()
Expect(err).Should(Succeed())
Expect(handler.PrepareCurrentAppRevision(ctx, generatedAppfile)).Should(Succeed())
Expect(handler.FinalizeAndApplyAppRevision(ctx)).Should(Succeed())
prevHash := generatedAppfile.AppRevisionHash
handler.app.Status.LatestRevision = &common.Revision{Name: generatedAppfile.AppRevisionName, Revision: 1, RevisionHash: generatedAppfile.AppRevisionHash}
generatedAppfile.Workloads[0].FullTemplate.ComponentDefinition = nil
Expect(handler.PrepareCurrentAppRevision(ctx, generatedAppfile)).Should(Succeed())
nonChangeHash := generatedAppfile.AppRevisionHash
handler.app.Annotations = map[string]string{oam.AnnotationAutoUpdate: "true"}
Expect(handler.PrepareCurrentAppRevision(ctx, generatedAppfile)).Should(Succeed())
changedHash := generatedAppfile.AppRevisionHash
Expect(nonChangeHash).Should(Equal(prevHash))
Expect(changedHash).ShouldNot(Equal(prevHash))
})
It("Test apply success for none rollout case", func() {
By("Apply the application")
appParser := appfile.NewApplicationParser(reconciler.Client, reconciler.dm, reconciler.pd)
......
......@@ -165,6 +165,9 @@ const (
// AnnotationPublishVersion is annotation that record the application workflow version.
AnnotationPublishVersion = "app.oam.dev/publishVersion"
// AnnotationAutoUpdate is annotation that let application auto update when it finds definition changes
AnnotationAutoUpdate = "app.oam.dev/autoUpdate"
// AnnotationWorkflowName specifies the workflow name for execution.
AnnotationWorkflowName = "app.oam.dev/workflowName"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment