diff --git a/pkg/yurtmanager/controller/platformadmin/platformadmin_controller.go b/pkg/yurtmanager/controller/platformadmin/platformadmin_controller.go index 840d7a2509e..367cf1f6f3e 100644 --- a/pkg/yurtmanager/controller/platformadmin/platformadmin_controller.go +++ b/pkg/yurtmanager/controller/platformadmin/platformadmin_controller.go @@ -219,8 +219,20 @@ func (r *ReconcilePlatformAdmin) Reconcile(ctx context.Context, request reconcil // resource are patched back to the API server. defer func(isDeleted *bool) { if !*isDeleted { - platformAdmin.Status = *platformAdminStatus + // Finally check whether PlatformAdmin is Ready + platformAdminStatus.Ready = true + if cond := util.GetPlatformAdminCondition(*platformAdminStatus, iotv1alpha2.ConfigmapAvailableCondition); cond.Status == corev1.ConditionFalse { + platformAdminStatus.Ready = false + } + if cond := util.GetPlatformAdminCondition(*platformAdminStatus, iotv1alpha2.ComponentAvailableCondition); cond.Status == corev1.ConditionFalse { + platformAdminStatus.Ready = false + } + if platformAdminStatus.UnreadyComponentNum != 0 { + platformAdminStatus.Ready = false + } + // Finally update the status of PlatformAdmin + platformAdmin.Status = *platformAdminStatus if err := r.Status().Update(ctx, platformAdmin); err != nil { klog.Errorf(Format("Update the status of PlatformAdmin %s/%s failed", platformAdmin.Namespace, platformAdmin.Name)) reterr = kerrors.NewAggregate([]error{reterr, err}) @@ -257,8 +269,6 @@ func (r *ReconcilePlatformAdmin) reconcileDelete(ctx context.Context, platformAd } desiredComponents = append(desiredComponents, additionalComponents...) - //TODO: handle PlatformAdmin.Spec.Components - for _, dc := range desiredComponents { if err := r.Get( ctx, @@ -332,7 +342,6 @@ func (r *ReconcilePlatformAdmin) reconcileNormal(ctx context.Context, platformAd util.SetPlatformAdminCondition(platformAdminStatus, util.NewPlatformAdminCondition(iotv1alpha2.ComponentAvailableCondition, corev1.ConditionTrue, "", "")) // Update the metadata of PlatformAdmin - platformAdminStatus.Ready = true if err := r.Client.Update(ctx, platformAdmin); err != nil { klog.Errorf(Format("Update PlatformAdmin %s error %v", klog.KObj(platformAdmin), err)) return reconcile.Result{}, err diff --git a/test/e2e/util/nodepool.go b/test/e2e/util/nodepool.go index b63cfb0a124..3f310e59c26 100644 --- a/test/e2e/util/nodepool.go +++ b/test/e2e/util/nodepool.go @@ -142,7 +142,7 @@ func PrepareNodePoolWithNode(ctx context.Context, k8sClient client.Client, nodeN } patchObj := client.MergeFrom(node.DeepCopy()) - node.Labels[apps.NodePoolLabel] = NodePoolName + node.Labels[projectinfo.GetNodePoolLabel()] = NodePoolName if err := k8sClient.Patch(ctx, node, patchObj); err != nil { return err diff --git a/test/e2e/yurt/iot.go b/test/e2e/yurt/iot.go index 3a0b2b00230..d3dbde8735f 100644 --- a/test/e2e/yurt/iot.go +++ b/test/e2e/yurt/iot.go @@ -21,12 +21,12 @@ import ( "fmt" "time" + "github.com/google/uuid" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" - "sigs.k8s.io/controller-runtime/pkg/client" iotv1alpha2 "github.com/openyurtio/openyurt/pkg/apis/iot/v1alpha2" "github.com/openyurtio/openyurt/test/e2e/util" @@ -37,43 +37,44 @@ func generateTestVersions() []string { return []string{"levski", "jakarta", "kamakura", "ireland", "minnesota"} } -var _ = Describe("OpenYurt IoT Test", func() { - var platformAdminName string +var _ = Describe("OpenYurt IoT Test", Ordered, func() { + var ( + platformAdminName string + namespaceName string + ) ctx := context.Background() k8sClient := ycfg.YurtE2eCfg.RuntimeClient timeout := 60 * time.Second platformadminTimeout := 5 * time.Minute testVersions := generateTestVersions() - namespaceName := "iot-test-namespace" nodePoolName := util.NodePoolName createNamespace := func() { + By(fmt.Sprintf("create the Namespace named %s for iot e2e test", namespaceName)) + Eventually( + func() error { + return k8sClient.Delete(ctx, &corev1.Namespace{ + ObjectMeta: metav1.ObjectMeta{ + Name: namespaceName, + }, + }) + }, timeout, 500*time.Millisecond).Should(SatisfyAny(BeNil(), &util.NotFoundMatcher{})) + ns := corev1.Namespace{ ObjectMeta: metav1.ObjectMeta{ Name: namespaceName, }, } - Eventually( - func() error { - return k8sClient.Delete(ctx, &ns, client.PropagationPolicy(metav1.DeletePropagationForeground)) - }).WithTimeout(timeout).WithPolling(time.Millisecond * 500).Should(SatisfyAny(BeNil(), &util.NotFoundMatcher{})) - By("make sure the needed namespace are removed") - res := &corev1.Namespace{} - Eventually( - func() error { - return k8sClient.Get(ctx, client.ObjectKey{ - Name: namespaceName, - }, res) - }).WithTimeout(timeout).WithPolling(time.Millisecond * 500).Should(&util.NotFoundMatcher{}) Eventually( func() error { return k8sClient.Create(ctx, &ns) - }).WithTimeout(timeout).WithPolling(time.Millisecond * 300).Should(SatisfyAny(BeNil(), &util.AlreadyExistMatcher{})) + }, timeout, 500*time.Millisecond).Should(SatisfyAny(BeNil(), &util.AlreadyExistMatcher{})) } createPlatformAdmin := func(version string) { + By(fmt.Sprintf("create the PlatformAdmin named %s for iot e2e test", platformAdminName)) Eventually(func() error { return k8sClient.Delete(ctx, &iotv1alpha2.PlatformAdmin{ ObjectMeta: metav1.ObjectMeta{ @@ -81,7 +82,7 @@ var _ = Describe("OpenYurt IoT Test", func() { Namespace: namespaceName, }, }) - }).WithTimeout(timeout).WithPolling(500 * time.Millisecond).Should(SatisfyAny(BeNil(), &util.NotFoundMatcher{})) + }, timeout, 500*time.Millisecond).Should(SatisfyAny(BeNil(), &util.NotFoundMatcher{})) testPlatformAdmin := iotv1alpha2.PlatformAdmin{ ObjectMeta: metav1.ObjectMeta{ @@ -95,19 +96,24 @@ var _ = Describe("OpenYurt IoT Test", func() { } Eventually(func() error { return k8sClient.Create(ctx, &testPlatformAdmin) - }).WithTimeout(timeout).WithPolling(500 * time.Millisecond).Should(SatisfyAny(BeNil(), &util.AlreadyExistMatcher{})) + }, timeout, 500*time.Millisecond).Should(SatisfyAny(BeNil(), &util.AlreadyExistMatcher{})) } BeforeEach(func() { By("Start to run iot test, clean up previous resources") k8sClient = ycfg.YurtE2eCfg.RuntimeClient + + longUUID := uuid.New() + shortUUID := longUUID.String()[:8] + namespaceName = "iot-test-" + shortUUID + createNamespace() }) AfterEach(func() { By("Cleanup resources after test") By(fmt.Sprintf("Delete the entire namespaceName %s", namespaceName)) - Expect(k8sClient.Delete(ctx, &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: namespaceName}}, client.PropagationPolicy(metav1.DeletePropagationBackground))).Should(BeNil()) + Expect(k8sClient.Delete(ctx, &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: namespaceName}})).Should(SatisfyAny(BeNil(), &util.NotFoundMatcher{})) }) for _, testVersion := range testVersions { @@ -120,7 +126,7 @@ var _ = Describe("OpenYurt IoT Test", func() { AfterEach(func() { By(fmt.Sprintf("Delete the platformAdmin %s", platformAdminName)) - Expect(k8sClient.Delete(ctx, &iotv1alpha2.PlatformAdmin{ObjectMeta: metav1.ObjectMeta{Name: platformAdminName, Namespace: namespaceName}}, client.PropagationPolicy(metav1.DeletePropagationBackground))).Should(BeNil()) + Expect(k8sClient.Delete(ctx, &iotv1alpha2.PlatformAdmin{ObjectMeta: metav1.ObjectMeta{Name: platformAdminName, Namespace: namespaceName}})).Should(BeNil()) }) It(fmt.Sprintf("The %s version of PlatformAdmin should be stable in ready state after it is created", version), func() {