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 14, 2024
1 parent 6a3d8ce commit c09b36d
Show file tree
Hide file tree
Showing 11 changed files with 165 additions and 295 deletions.
3 changes: 3 additions & 0 deletions controllers/apps/cluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ var _ = Describe("Cluster Controller", func() {
Create(&testCtx).
GetObject()

By("Create a bpt obj")
testdp.CreateBackupPolicyTpl(&testCtx, compDefObj.Name)

By("Wait objects available")
Eventually(testapps.CheckObj(&testCtx, client.ObjectKeyFromObject(compDefObj),
func(g Gomega, compDef *appsv1.ComponentDefinition) {
Expand Down
26 changes: 3 additions & 23 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 @@ -1557,11 +1553,6 @@ var _ = Describe("Component Controller", func() {
})).ShouldNot(HaveOccurred())
Eventually(testapps.GetClusterComponentPhase(&testCtx, clusterKey, compName)).Should(Equal(kbappsv1.RunningComponentPhase))

By("the restore container has been removed from init containers")
Eventually(testapps.CheckObj(&testCtx, client.ObjectKeyFromObject(its), func(g Gomega, tmpIts *workloads.InstanceSet) {
g.Expect(tmpIts.Spec.Template.Spec.InitContainers).Should(BeEmpty())
})).Should(Succeed())

By("clean up annotations after cluster running")
Eventually(testapps.CheckObj(&testCtx, clusterKey, func(g Gomega, tmpCluster *kbappsv1.Cluster) {
g.Expect(tmpCluster.Status.Phase).Should(Equal(kbappsv1.RunningClusterPhase))
Expand Down Expand Up @@ -1746,7 +1737,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 +1764,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 +1782,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 +1806,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 c09b36d

Please sign in to comment.