Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Charlie17Li committed Oct 29, 2023
1 parent f46a48e commit 928a00b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ func (r *ModuleDeploymentReconciler) Reconcile(ctx context.Context, req ctrl.Req
}

if moduleDeployment.DeletionTimestamp != nil {
// delete moduleDeployment
event.PublishModuleDeploymentDeleteEvent(r.Client, ctx, moduleDeployment)
if !utils.HasFinalizer(&moduleDeployment.ObjectMeta, finalizer.ModuleReplicaSetExistedFinalizer) &&
!utils.HasFinalizer(&moduleDeployment.ObjectMeta, finalizer.ModuleExistedFinalizer) {
Expand Down Expand Up @@ -245,6 +244,7 @@ func (r *ModuleDeploymentReconciler) handleDeletingModuleDeployment(ctx context.
return ctrl.Result{}, utils.Error(err, "Failed to delete moduleReplicaSet", "moduleReplicaSetName", replicaSetList.Items[i].Name)
}
}
log.Log.Info("replicaset删除完毕")
requeueAfter := utils.GetNextReconcileTime(moduleDeployment.DeletionTimestamp.Time)
return ctrl.Result{RequeueAfter: requeueAfter}, nil
} else {
Expand Down Expand Up @@ -341,6 +341,9 @@ func (r *ModuleDeploymentReconciler) createOrGetModuleReplicas(ctx context.Conte
log.Log.Info("module has changed, need create a new replicaset")
}

if moduleDeployment.DeletionTimestamp != nil {
return nil, nil, false, nil
}
// create a new moduleReplicaset
moduleReplicaSet, err := r.createNewReplicaSet(ctx, moduleDeployment, maxVersion+1)
if err != nil {
Expand Down Expand Up @@ -414,6 +417,7 @@ func (r *ModuleDeploymentReconciler) updateModuleReplicaSet(ctx context.Context,
}

err := r.updateModuleReplicas(ctx, replicas, moduleDeployment, newRS)

if err != nil {
return ctrl.Result{}, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/sofastack/sofa-serverless/internal/utils"
)

var _ = FDescribe("ModuleDeployment Controller", func() {
var _ = Describe("ModuleDeployment Controller", func() {
const timeout = time.Second * 30
const interval = time.Second * 5

Expand Down Expand Up @@ -174,17 +174,26 @@ var _ = FDescribe("ModuleDeployment Controller", func() {
moduleDeployment.Spec.OperationStrategy.BatchCount = 2

It("0. prepare 2 pods", func() {

Eventually(func() bool {
pod := preparePod(namespace, "fake-pod-3")
pod.Labels[label.ModuleLabelPrefix+"dynamic-provider"] = "true"
if err := k8sClient.Create(context.TODO(), &pod); err != nil {
return false
}
// when install module, the podIP is necessary
pod.Status.PodIP = "127.0.0.1"
return k8sClient.Status().Update(context.TODO(), &pod) == nil
}, timeout, interval).Should(BeTrue())
if k8sClient.Status().Update(context.TODO(), &pod) != nil {
return false
}

pod2 := preparePod(namespace, "fake-pod-4")
if err := k8sClient.Create(context.TODO(), &pod2); err != nil {
return false
}
// when install module, the podIP is necessary
pod.Status.PodIP = "127.0.0.1"
return k8sClient.Status().Update(context.TODO(), &pod2) == nil
}, timeout, interval).Should(BeTrue())
})

It("1. create a new moduleDeployment", func() {
Expand Down Expand Up @@ -268,7 +277,7 @@ var _ = FDescribe("ModuleDeployment Controller", func() {
}, timeout, interval).Should(BeTrue())
})

It("9. check if the moduleDeployment status is completed", func() {
It("9. check if the moduleDeployment status is Terminated", func() {
Eventually(func() error {
if err := k8sClient.Get(context.TODO(), nn, &moduleDeployment); err != nil {
return err
Expand All @@ -278,12 +287,16 @@ var _ = FDescribe("ModuleDeployment Controller", func() {
return fmt.Errorf("the module-deployment is paused")
}

if moduleDeployment.Status.ReleaseStatus == nil {
return fmt.Errorf("release status is nil")
}

if moduleDeployment.Status.ReleaseStatus.Progress != v1alpha1.ModuleDeploymentReleaseProgressTerminated {
return fmt.Errorf("expect status %v, but got %v",
v1alpha1.ModuleDeploymentReleaseProgressTerminated, moduleDeployment.Status.ReleaseStatus.Progress)
}
return nil
}, timeout, interval).Should(BeTrue())
}, timeout, interval).Should(Succeed())
})

It("10. clean module-deployment", func() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ package controller
import (
"context"
"fmt"
"github.com/sofastack/sofa-serverless/internal/event"
"sort"
"strconv"

"github.com/sofastack/sofa-serverless/internal/event"

"k8s.io/apimachinery/pkg/selection"

"golang.org/x/tools/container/intsets"
Expand Down Expand Up @@ -245,6 +246,7 @@ func (r *ModuleReplicaSetReconciler) handleDeletingModuleReplicaSet(ctx context.

// generate module
func (r *ModuleReplicaSetReconciler) generateModule(moduleReplicaSet *v1alpha1.ModuleReplicaSet, pod corev1.Pod) *v1alpha1.Module {
log.Log.Info(fmt.Sprintf("生成新的module, name 为%v", moduleReplicaSet.Spec.Template.Spec.Module.Name))

moduleLabels := moduleReplicaSet.Labels
moduleLabels[label.ModuleNameLabel] = moduleReplicaSet.Spec.Template.Spec.Module.Name
Expand Down

0 comments on commit 928a00b

Please sign in to comment.