Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: prevent rerun app while upgrade due to old apprev lack app workflow #4852

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 22 additions & 1 deletion pkg/controller/core.oam.dev/v1alpha2/application/revision.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"sort"
"strings"

"github.com/hashicorp/go-version"
"github.com/kubevela/pkg/util/k8s"
"github.com/pkg/errors"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -535,6 +537,25 @@ func deepEqualWorkflow(old, new workflowv1alpha1.Workflow) bool {
return apiequality.Semantic.DeepEqual(old.Steps, new.Steps)
}

const velaVersionNumberToCompareWorkflow = "v1.5.7"

func deepEqualAppSpec(old, new *v1beta1.Application) bool {
oldSpec, newSpec := old.Spec.DeepCopy(), new.Spec.DeepCopy()
// legacy code: KubeVela version before v1.5.7 & v1.6.0-alpha.4 does not
// record workflow in application spec in application revision. The comparison
// need to bypass the equality check of workflow to prevent unintended rerun
curVerNum := k8s.GetAnnotation(old, oam.AnnotationKubeVelaVersion)
publishVersion := k8s.GetAnnotation(old, oam.AnnotationPublishVersion)
if publishVersion == "" && curVerNum != "" {
cmpVer, _ := version.NewVersion(velaVersionNumberToCompareWorkflow)
if curVer, err := version.NewVersion(curVerNum); err == nil && curVer.LessThan(cmpVer) {
oldSpec.Workflow = nil
newSpec.Workflow = nil
}
}
return apiequality.Semantic.DeepEqual(oldSpec, newSpec)
}

func deepEqualAppInRevision(old, new *v1beta1.ApplicationRevision) bool {
if len(old.Spec.Policies) != len(new.Spec.Policies) {
return false
Expand All @@ -552,7 +573,7 @@ func deepEqualAppInRevision(old, new *v1beta1.ApplicationRevision) bool {
return false
}
}
return apiequality.Semantic.DeepEqual(old.Spec.Application.Spec, new.Spec.Application.Spec)
return deepEqualAppSpec(&old.Spec.Application, &new.Spec.Application)
}

// HandleComponentsRevision manages Component revisions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ import (
"fmt"
"reflect"
"strconv"
"testing"
"time"

workflowv1alpha1 "github.com/kubevela/workflow/api/v1alpha1"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/stretchr/testify/require"

"github.com/google/go-cmp/cmp"
appsv1 "k8s.io/api/apps/v1"
Expand Down Expand Up @@ -1085,3 +1088,21 @@ status: {}
}()).Should(BeTrue())
})
})

func TestDeepEqualAppInRevision(t *testing.T) {
oldRev := &v1beta1.ApplicationRevision{}
newRev := &v1beta1.ApplicationRevision{}
newRev.Spec.Application.Spec.Workflow = &v1beta1.Workflow{
Steps: []workflowv1alpha1.WorkflowStep{{
WorkflowStepBase: workflowv1alpha1.WorkflowStepBase{
Type: "deploy",
Name: "deploy",
},
}},
}
require.False(t, deepEqualAppInRevision(oldRev, newRev))
metav1.SetMetaDataAnnotation(&oldRev.Spec.Application.ObjectMeta, oam.AnnotationKubeVelaVersion, "v1.6.0-alpha.5")
require.False(t, deepEqualAppInRevision(oldRev, newRev))
metav1.SetMetaDataAnnotation(&oldRev.Spec.Application.ObjectMeta, oam.AnnotationKubeVelaVersion, "v1.5.0")
require.True(t, deepEqualAppInRevision(oldRev, newRev))
}