Skip to content

Commit

Permalink
fix: modify the ready status judgment logic of PlatformAdmin
Browse files Browse the repository at this point in the history
Signed-off-by: LavenderQAQ <[email protected]>
  • Loading branch information
LavenderQAQ committed Nov 23, 2023
1 parent af4a310 commit a5bce7f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/util/nodepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 6 additions & 12 deletions test/e2e/yurt/iot.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,17 @@ var _ = Describe("OpenYurt IoT Test", func() {
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{}))
return k8sClient.Delete(ctx, &ns, client.PropagationPolicy(metav1.DeletePropagationBackground))
}, timeout, 500*time.Millisecond).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) {
Expand All @@ -81,7 +75,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{
Expand All @@ -95,7 +89,7 @@ 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() {
Expand Down

0 comments on commit a5bce7f

Please sign in to comment.