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
+30 -5
View File
@@ -19,7 +19,6 @@ package apply
import (
"context"
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
"github.com/oam-dev/kubevela/pkg/oam"
"github.com/pkg/errors"
@@ -176,13 +175,39 @@ func MustBeControllableBy(u types.UID) ApplyOption {
if c == nil {
return nil
}
// if workload is a cross namespace resource, skip check UID
if c.Kind == v1beta1.ResourceTrackerKind {
return nil
}
if c.UID != u {
return errors.Errorf("existing object is not controlled by UID %q", u)
}
return nil
}
}
// MustBeControllableByAny requires that the new object is controllable by any of the object with
// the supplied UID.
func MustBeControllableByAny(ctrlUIDs []types.UID) ApplyOption {
return func(_ context.Context, existing, _ runtime.Object) error {
if existing == nil || len(ctrlUIDs) == 0 {
return nil
}
existingObjMeta, _ := existing.(metav1.Object)
c := metav1.GetControllerOf(existingObjMeta)
if c == nil {
return nil
}
// NOTE This is for backward compatibility after ApplicationContext is deprecated.
// In legacy clusters, existing resources are ctrl-owned by ApplicationContext or ResourceTracker (only for
// cx-namespace and cluster-scope resources). We use a particular annotation to identify legacy resources.
if len(existingObjMeta.GetAnnotations()[oam.AnnotationKubeVelaVersion]) == 0 {
// just skip checking UIDs, '3-way-merge' will remove the legacy ctrl-owner automatically
return nil
}
for _, u := range ctrlUIDs {
if c.UID == u {
return nil
}
}
return errors.Errorf("existing object is not controlled by any of UID %q", ctrlUIDs)
}
}
+64
View File
@@ -30,9 +30,11 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/pointer"
"sigs.k8s.io/controller-runtime/pkg/client"
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
"github.com/oam-dev/kubevela/pkg/oam"
)
var ctx = context.Background()
@@ -371,3 +373,65 @@ func TestMustBeControllableBy(t *testing.T) {
})
}
}
func TestMustBeControllableByAny(t *testing.T) {
ctrlByAny := []types.UID{"owner1", "owner2"}
cases := map[string]struct {
reason string
current runtime.Object
want error
}{
"NoExistingObject": {
reason: "No error should be returned if no existing object",
},
"Adoptable": {
reason: "A current object with no controller reference may be adopted and controlled",
current: &testObject{ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
oam.AnnotationKubeVelaVersion: "undefined",
}},
},
},
"ControlledBySuppliedUID": {
reason: "A current object that is already controlled by the supplied UID is controllable",
current: &testObject{ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
oam.AnnotationKubeVelaVersion: "undefined",
},
OwnerReferences: []metav1.OwnerReference{{
UID: types.UID("owner1"),
Controller: pointer.BoolPtr(true),
}}}},
},
"ControlledBySomeoneElse": {
reason: "A current object that is already controlled by a different UID is not controllable",
current: &testObject{ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
oam.AnnotationKubeVelaVersion: "undefined",
},
OwnerReferences: []metav1.OwnerReference{{
UID: types.UID("some-other-uid"),
Controller: pointer.BoolPtr(true),
}}}},
want: errors.Errorf("existing object is not controlled by any of UID %q", ctrlByAny),
},
"BackwardCompatability": {
reason: "A current object without annotation 'kubevelavesion' is legacy",
current: &testObject{ObjectMeta: metav1.ObjectMeta{
OwnerReferences: []metav1.OwnerReference{{
UID: types.UID("some-other-uid"),
Controller: pointer.BoolPtr(true),
}}}},
},
}
for name, tc := range cases {
t.Run(name, func(t *testing.T) {
ao := MustBeControllableByAny(ctrlByAny)
err := ao(context.TODO(), tc.current, nil)
if diff := cmp.Diff(tc.want, err, test.EquateErrors()); diff != "" {
t.Errorf("\n%s\nMustBeControllableByAny(...)(...): -want error, +got error\n%s\n", tc.reason, diff)
}
})
}
}