remove appContext from app/appRollout controller (#1774)

* refine  assemble and dispatch

Signed-off-by: roy wang <seiwy2010@gmail.com>

* remove app context in app controller

modify clean up app revision

remove old resource tracker related logic

fix unit tests

Signed-off-by: roy wang <seiwy2010@gmail.com>

* fix e2e-test

- get rid of appCtx in test cases
- fix test cases according other logic changes in app controller

remove whole appcontext_test.go file

disable rollout related e2e test provisionally

disable resource tracker related e2e test provisionally

Signed-off-by: roy wang <seiwy2010@gmail.com>

* add finalizer logic for app controller

Signed-off-by: roywang <seiwy2010@gmail.com>

* add new apply option MustBeControllableByAny

make dispatch idempotent

Signed-off-by: roywang <seiwy2010@gmail.com>

* refactor rollout

* fix rollout finalize succeed

Signed-off-by: roywang <seiwy2010@gmail.com>

* add update trait and gc test

fix lint

* fix flaky e2e test

Signed-off-by: roywang <seiwy2010@gmail.com>

* fix comment

* fix comments and add sourceRevision dispatch

delete useless

Signed-off-by: Yue Wang <seiwy2010@gmail.com>

* fix app finalizer backward compatible

Signed-off-by: roywang <seiwy2010@gmail.com>

* fix backward compatability for deprecation of appContext

add unit test for apply option

add e2e test

Signed-off-by: Yue Wang <seiwy2010@gmail.com>

* fix app controller unit test

Signed-off-by: Yue Wang <seiwy2010@gmail.com>

* refine app controller apply logic

Signed-off-by: Yue Wang <seiwy2010@gmail.com>

* fix e2e test of resource tracker

fix e2e test of rollout plan

fix flaky e2e tests

Signed-off-by: Yue Wang <seiwy2010@gmail.com>

* refine comments and remove useless codes

Signed-off-by: Yue Wang <seiwy2010@gmail.com>

* disable appCtx controller

add Component handler into app controller

Signed-off-by: Yue Wang <seiwy2010@gmail.com>

Co-authored-by: wangyike <wangyike.wyk@alibaba-inc.com>
This commit is contained in:
Yue Wang
2021-06-12 14:46:32 +08:00
committed by GitHub
co-authored by wangyike
parent 9de6aea5ab
commit 889e38e984
41 changed files with 1983 additions and 2098 deletions
@@ -17,12 +17,38 @@ limitations under the License.
package applicationrollout
import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1alpha2"
"github.com/oam-dev/kubevela/pkg/controller/utils"
)
// FindCommonComponent finds the common components in both the source and target application
// FindCommonComponentWithManifest finds the common components in both the source and target workloads
// the source can be nil
func FindCommonComponentWithManifest(target, source map[string]*unstructured.Unstructured) []string {
var commonComponents []string
if source == nil {
for compName := range target {
commonComponents = append(commonComponents, compName)
}
return commonComponents
}
// find the common components in both the source and target components
// write an O(N) algorithm just for fun, totally doesn't worth the extra space
targetComponents := make(map[string]bool)
for comp := range target {
targetComponents[comp] = true
}
for comp := range source {
if targetComponents[comp] {
commonComponents = append(commonComponents, comp)
}
}
return commonComponents
}
// FindCommonComponent finds the common components in both the source and target application
// only used for rollout webhook, will delete after refactor rollout webhook
func FindCommonComponent(targetApp, sourceApp *v1alpha2.ApplicationConfiguration) []string {
var commonComponents []string
if sourceApp == nil {
@@ -17,8 +17,11 @@ limitations under the License.
package applicationrollout
import (
"sort"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1alpha2"
"github.com/oam-dev/kubevela/pkg/controller/utils"
@@ -88,3 +91,53 @@ func fillApplication(app *v1alpha2.ApplicationConfigurationSpec, componentNames
})
}
}
var _ = Describe("Test find common component func", func() {
It("Test source app is nil", func() {
target := fillWorkloads([]string{"a", "b", "c"})
common := FindCommonComponentWithManifest(target, nil)
sort.Strings(common)
Expect(common).Should(BeEquivalentTo([]string{"a", "b", "c"}))
})
It("Test has one component", func() {
target := fillWorkloads([]string{"a", "b", "c"})
source := fillWorkloads([]string{"c"})
common := FindCommonComponentWithManifest(target, source)
sort.Strings(common)
Expect(common).Should(BeEquivalentTo([]string{"c"}))
})
It("Test has one common components", func() {
target := fillWorkloads([]string{"a", "b", "c"})
source := fillWorkloads([]string{"d", "c"})
common := FindCommonComponentWithManifest(target, source)
sort.Strings(common)
Expect(common).Should(BeEquivalentTo([]string{"c"}))
})
It("Test has more than 1 common component", func() {
target := fillWorkloads([]string{"b", "a", "c"})
source := fillWorkloads([]string{"c", "b"})
common := FindCommonComponentWithManifest(target, source)
sort.Strings(common)
Expect(common).Should(BeEquivalentTo([]string{"b", "c"}))
})
It("Test has more than 1 common component", func() {
target := fillWorkloads([]string{"a", "b", "c"})
source := fillWorkloads([]string{"d", "e", "c", "a"})
common := FindCommonComponentWithManifest(target, source)
sort.Strings(common)
Expect(common).Should(BeEquivalentTo([]string{"a", "c"}))
})
})
func fillWorkloads(componentNames []string) map[string]*unstructured.Unstructured {
w := make(map[string]*unstructured.Unstructured)
for _, s := range componentNames {
// we don't need real workload
w[s] = nil
}
return w
}