From 0d8f656cdb074738124bdb8debd94cea39f1bab6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A9=E5=85=83?= Date: Mon, 29 Mar 2021 23:45:29 +0800 Subject: [PATCH] fix some tests --- .../applicationcontext_controller.go | 7 ++++ pkg/oam/util/helper.go | 42 ++++++++++++------- test/e2e-test/app_resourcetracker_test.go | 13 +++--- test/e2e-test/rollout_plan_test.go | 2 +- 4 files changed, 43 insertions(+), 21 deletions(-) diff --git a/pkg/controller/core.oam.dev/v1alpha2/applicationcontext/applicationcontext_controller.go b/pkg/controller/core.oam.dev/v1alpha2/applicationcontext/applicationcontext_controller.go index d36ccf55b..8b660b184 100644 --- a/pkg/controller/core.oam.dev/v1alpha2/applicationcontext/applicationcontext_controller.go +++ b/pkg/controller/core.oam.dev/v1alpha2/applicationcontext/applicationcontext_controller.go @@ -102,6 +102,13 @@ func (r *Reconciler) Reconcile(request reconcile.Request) (reconcile.Result, err // the name of the appConfig has to be the same as the appContext appConfig.Name = appContext.Name appConfig.UID = appContext.UID + for _, owner := range appContext.GetOwnerReferences() { + // if the appContext is created by Application, set the AppConfig UID to align with the application + if owner.Kind == v1beta1.ApplicationKind { + appConfig.UID = owner.UID + break + } + } appConfig.SetLabels(appContext.GetLabels()) appConfig.SetAnnotations(appContext.GetAnnotations()) // makes sure that the appConfig's owner is the same as the appContext diff --git a/pkg/oam/util/helper.go b/pkg/oam/util/helper.go index 421e8de11..f1f3b406a 100644 --- a/pkg/oam/util/helper.go +++ b/pkg/oam/util/helper.go @@ -27,6 +27,8 @@ import ( "strings" "time" + "github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1" + cpv1alpha1 "github.com/crossplane/crossplane-runtime/apis/core/v1alpha1" "github.com/davecgh/go-spew/spew" "github.com/go-logr/logr" @@ -132,25 +134,37 @@ type ConditionedObject interface { // LocateParentAppConfig locate the parent application configuration object func LocateParentAppConfig(ctx context.Context, client client.Client, oamObject oam.Object) (oam.Object, error) { - var acName string - var eventObj = &v1alpha2.ApplicationConfiguration{} + // locate the appConf name from the owner list for _, o := range oamObject.GetOwnerReferences() { - // TODO(wonderflow): this function maybe not work in the case AC was created by Application and the Application is the ownerRef here. if o.Kind == v1alpha2.ApplicationConfigurationKind { - acName = o.Name - break + var eventObj = &v1alpha2.ApplicationConfiguration{} + acName := o.Name + if len(acName) > 0 { + nn := types.NamespacedName{ + Name: acName, + Namespace: oamObject.GetNamespace(), + } + if err := client.Get(ctx, nn, eventObj); err != nil { + return nil, err + } + return eventObj, nil + } } - } - if len(acName) > 0 { - nn := types.NamespacedName{ - Name: acName, - Namespace: oamObject.GetNamespace(), + if o.Kind == v1beta1.ApplicationKind { + var eventObj = &v1beta1.Application{} + appName := o.Name + if len(appName) > 0 { + nn := types.NamespacedName{ + Name: appName, + Namespace: oamObject.GetNamespace(), + } + if err := client.Get(ctx, nn, eventObj); err != nil { + return nil, err + } + return eventObj, nil + } } - if err := client.Get(ctx, nn, eventObj); err != nil { - return nil, err - } - return eventObj, nil } return nil, errors.Errorf(ErrLocateAppConfig) } diff --git a/test/e2e-test/app_resourcetracker_test.go b/test/e2e-test/app_resourcetracker_test.go index ef7a4b73c..75677aa27 100644 --- a/test/e2e-test/app_resourcetracker_test.go +++ b/test/e2e-test/app_resourcetracker_test.go @@ -25,11 +25,6 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - "github.com/oam-dev/kubevela/apis/core.oam.dev/common" - "github.com/oam-dev/kubevela/apis/core.oam.dev/v1alpha2" - "github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1" - "github.com/oam-dev/kubevela/pkg/oam" - "github.com/oam-dev/kubevela/pkg/oam/util" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" @@ -38,6 +33,12 @@ import ( "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/yaml" + + "github.com/oam-dev/kubevela/apis/core.oam.dev/common" + "github.com/oam-dev/kubevela/apis/core.oam.dev/v1alpha2" + "github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1" + "github.com/oam-dev/kubevela/pkg/oam" + "github.com/oam-dev/kubevela/pkg/oam/util" ) var _ = Describe("Test application cross namespace resource", func() { @@ -240,7 +241,7 @@ var _ = Describe("Test application cross namespace resource", func() { return fmt.Errorf("error workload number %v", err) } workload := depolys.Items[0] - if len(workload.OwnerReferences) != 1 || workload.OwnerReferences[0].Kind != v1alpha2.ApplicationConfigurationKind { + if len(workload.OwnerReferences) != 1 || workload.OwnerReferences[0].Kind != v1beta1.ApplicationKind { return fmt.Errorf("workload owneRefernece err") } err = k8sClient.Get(ctx, generateResourceTrackerKey(app.Namespace, app.Name), resourceTracker) diff --git a/test/e2e-test/rollout_plan_test.go b/test/e2e-test/rollout_plan_test.go index aa72fb8a8..db8bfc59a 100644 --- a/test/e2e-test/rollout_plan_test.go +++ b/test/e2e-test/rollout_plan_test.go @@ -182,7 +182,7 @@ var _ = Describe("Cloneset based rollout tests", func() { } return "" }, - time.Second*30, time.Millisecond*500).Should(BeEquivalentTo(v1alpha2.ApplicationConfigurationKind)) + time.Second*30, time.Millisecond*500).Should(BeEquivalentTo(v1beta1.ApplicationKind)) Expect(clonesetOwner.Name).Should(BeEquivalentTo(targetAppName)) Expect(kc.Status.UpdatedReplicas).Should(BeEquivalentTo(*kc.Spec.Replicas)) Expect(kc.Status.UpdatedReadyReplicas).Should(BeEquivalentTo(*kc.Spec.Replicas))