Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
leon-inf committed Nov 13, 2024
1 parent 6a3d8ce commit a13e5c2
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 282 deletions.
21 changes: 3 additions & 18 deletions controllers/apps/component_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ var _ = Describe("Component Controller", func() {
testapps.ClearResourcesWithRemoveFinalizerOption(&testCtx, generics.PodSignature, true, inNS, ml)
testapps.ClearResourcesWithRemoveFinalizerOption(&testCtx, generics.BackupSignature, true, inNS, ml)
testapps.ClearResourcesWithRemoveFinalizerOption(&testCtx, generics.BackupPolicySignature, true, inNS, ml)
testapps.ClearResourcesWithRemoveFinalizerOption(&testCtx, generics.VolumeSnapshotSignature, true, inNS)
// non-namespaced
testapps.ClearResources(&testCtx, generics.BackupPolicyTemplateSignature, ml)
testapps.ClearResources(&testCtx, generics.ActionSetSignature, ml)
Expand Down Expand Up @@ -603,9 +602,6 @@ var _ = Describe("Component Controller", func() {
AddVolumeClaimTemplate(testapps.LogVolumeName, pvcSpec)
})

// REVIEW: this test flow, wait for running phase?
testk8s.MockEnableVolumeSnapshot(&testCtx, testk8s.DefaultStorageClassName)

horizontalScale(int(updatedReplicas), testk8s.DefaultStorageClassName, compDefName)
}

Expand Down Expand Up @@ -1746,7 +1742,7 @@ var _ = Describe("Component Controller", func() {
testHorizontalScale(defaultCompName, compDefObj.Name, 3, 0)
})

Context("with different backup methods", func() {
Context("scale-out multiple components", func() {
createNWaitClusterObj := func(components map[string]string,
processor func(compName string, factory *testapps.MockClusterFactory),
withFixedName ...bool) {
Expand All @@ -1773,7 +1769,8 @@ var _ = Describe("Component Controller", func() {
waitForCreatingResourceCompletely(clusterKey, compNames...)
}

testMultiCompHScale := func() {
// TODO
It("h-scale with data actions", func() {
compNameNDef := map[string]string{
fmt.Sprintf("%s-0", defaultCompName): compDefObj.Name,
fmt.Sprintf("%s-1", defaultCompName): compDefObj.Name,
Expand All @@ -1790,17 +1787,6 @@ var _ = Describe("Component Controller", func() {
}, false)

horizontalScale(int(updatedReplicas), testk8s.DefaultStorageClassName, compDefObj.Name)
}

It("h-scale with volume snapshot", func() {
testk8s.MockEnableVolumeSnapshot(&testCtx, testk8s.DefaultStorageClassName)
testMultiCompHScale()
})

// TODO
It("h-scale with data actions", func() {
testk8s.MockDisableVolumeSnapshot(&testCtx, testk8s.DefaultStorageClassName)
testMultiCompHScale()
})
})
})
Expand All @@ -1825,7 +1811,6 @@ var _ = Describe("Component Controller", func() {

It("scale-out", func() {
testVolumeExpansion(compDefObj, defaultCompName, mockStorageClass)
testk8s.MockEnableVolumeSnapshot(&testCtx, mockStorageClass.Name)
horizontalScale(5, mockStorageClass.Name, compDefObj.Name)
})
})
Expand Down
40 changes: 27 additions & 13 deletions controllers/apps/transformer_component_workload.go
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,9 @@ func (r *componentWorkloadOps) deletePVCs4ScaleIn(itsObj *workloads.InstanceSet)
}
pvc := corev1.PersistentVolumeClaim{}
if err := r.cli.Get(r.reqCtx.Ctx, pvcKey, &pvc, inDataContext4C()); err != nil {
if apierrors.IsNotFound(err) {
continue // the pvc is already deleted or not created
}
return err
}
// Since there are no order guarantee between updating ITS and deleting PVCs, if there is any error occurred
Expand All @@ -600,32 +603,43 @@ func (r *componentWorkloadOps) deletePVCs4ScaleIn(itsObj *workloads.InstanceSet)
}

func (r *componentWorkloadOps) scaleOut() error {
if r.synthesizeComp.LifecycleActions == nil {
return nil
}
dataDump := r.synthesizeComp.LifecycleActions.DataDump
dataLoad := r.synthesizeComp.LifecycleActions.DataLoad
if dataDump == nil || dataDump.Exec == nil || dataLoad == nil || dataLoad.Exec == nil {
return nil
}

// replicas in provisioning
provisioningReplicas, err := component.ReplicasInProvisioning(r.component)
if err != nil {
return err
}

// replicas to be created
newReplicas := r.desiredCompPodNameSet.Difference(r.runningItsPodNameSet).UnsortedList()

// update replicas of the workload
graphCli := model.NewGraphClient(r.cli)
v := graphCli.Do(r.dag, nil, r.protoITS, model.ActionUpdatePtr(), nil)

newReplicas := r.desiredCompPodNameSet.Difference(r.runningItsPodNameSet).UnsortedList()
hasDataActionDefined := func() bool {
if r.synthesizeComp.LifecycleActions == nil {
return false
}
dataDump := r.synthesizeComp.LifecycleActions.DataDump
dataLoad := r.synthesizeComp.LifecycleActions.DataLoad
if dataDump == nil || dataDump.Exec == nil || dataLoad == nil || dataLoad.Exec == nil {
return false
}
return true
}()

// build and assign data replication tasks
if err := func() error {
source, err := r.sourceReplica(dataDump)
if !hasDataActionDefined {
return nil
}

source, err := r.sourceReplica(r.synthesizeComp.LifecycleActions.DataDump)
if err != nil {
return err
}

replicas := append(newReplicas, provisioningReplicas...)
replicas := append(slices.Clone(newReplicas), provisioningReplicas...)
parameters, err := component.NewReplicaTask(r.synthesizeComp.FullCompName, r.synthesizeComp.Generation, source, replicas)
if err != nil {
return err
Expand All @@ -646,7 +660,7 @@ func (r *componentWorkloadOps) scaleOut() error {
return err
}

return component.NewReplicas(r.component, newReplicas)
return component.NewReplicas(r.component, newReplicas, hasDataActionDefined)
}

func (r *componentWorkloadOps) sourceReplica(dataDump *appsv1.Action) (*corev1.Pod, error) {
Expand Down
Loading

0 comments on commit a13e5c2

Please sign in to comment.