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 24, 2023
1 parent af4a310 commit 6fdf798
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 26 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
48 changes: 27 additions & 21 deletions test/e2e/yurt/iot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -37,51 +37,52 @@ 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{
Name: platformAdminName,
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,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 {
Expand All @@ -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() {
Expand Down

0 comments on commit 6fdf798

Please sign in to comment.