Skip to content

Commit

Permalink
Extended tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasfrank committed Aug 8, 2023
1 parent 60f9cd0 commit 8f57970
Show file tree
Hide file tree
Showing 4 changed files with 229 additions and 46 deletions.
26 changes: 22 additions & 4 deletions poollet/volumepoollet/controllers/controllers_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes/scheme"
Expand Down Expand Up @@ -174,12 +175,12 @@ func SetupTest() (*corev1.Namespace, *storagev1alpha1.VolumePool, *storagev1alph

*expandableVc = storagev1alpha1.VolumeClass{
ObjectMeta: metav1.ObjectMeta{
GenerateName: "test-vc-",
GenerateName: "test-vc-expandable-",
},
ResizePolicy: storagev1alpha1.ResizePolicyExpandOnly,
Capabilities: corev1alpha1.ResourceList{
corev1alpha1.ResourceTPS: resource.MustParse("250Mi"),
corev1alpha1.ResourceIOPS: resource.MustParse("15000"),
corev1alpha1.ResourceIOPS: resource.MustParse("1000"),
},
}
Expect(k8sClient.Create(ctx, expandableVc)).To(Succeed(), "failed to create test volume class")
Expand All @@ -198,7 +199,19 @@ func SetupTest() (*corev1.Namespace, *storagev1alpha1.VolumePool, *storagev1alph
},
},
},
{
VolumeClassStatus: ori.VolumeClassStatus{
VolumeClass: &ori.VolumeClass{
Name: expandableVc.Name,
Capabilities: &ori.VolumeClassCapabilities{
Tps: 262144000,
Iops: 1000,
},
},
},
},
})
DeferCleanup(srv.SetVolumeClasses, []*volume.FakeVolumeClassStatus{})

k8sManager, err := ctrl.NewManager(cfg, ctrl.Options{
Scheme: scheme.Scheme,
Expand Down Expand Up @@ -230,13 +243,13 @@ func SetupTest() (*corev1.Namespace, *storagev1alpha1.VolumePool, *storagev1alph
Client: k8sManager.GetClient(),
VolumeRuntime: srv,
VolumeClassMapper: volumeClassMapper,
VolumePoolName: TestVolumePool,
VolumePoolName: vp.Name,
}).SetupWithManager(k8sManager)).To(Succeed())

Expect((&controllers.VolumePoolAnnotatorReconciler{
Client: k8sManager.GetClient(),
VolumeClassMapper: volumeClassMapper,
VolumePoolName: TestVolumePool,
VolumePoolName: vp.Name,
}).SetupWithManager(k8sManager)).To(Succeed())

go func() {
Expand All @@ -247,3 +260,8 @@ func SetupTest() (*corev1.Namespace, *storagev1alpha1.VolumePool, *storagev1alph

return ns, vp, vc, expandableVc, srv
}

func ExpectVolumeDeleted(ctx context.Context, volume *storagev1alpha1.Volume) {
Expect(k8sClient.Delete(ctx, volume)).Should(Succeed())
Eventually(Get(volume)).Should(Satisfy(errors.IsNotFound))
}
5 changes: 4 additions & 1 deletion poollet/volumepoollet/controllers/volume_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ var _ = Describe("VolumeController", func() {
},
}
Expect(k8sClient.Create(ctx, volume)).To(Succeed())
DeferCleanup(ExpectVolumeDeleted, volume)

By("waiting for the runtime to report the volume")
Eventually(srv).Should(SatisfyAll(
Expand Down Expand Up @@ -149,6 +150,7 @@ var _ = Describe("VolumeController", func() {
},
}
Expect(k8sClient.Create(ctx, volume)).To(Succeed())
DeferCleanup(ExpectVolumeDeleted, volume)

By("waiting for the runtime to report the volume")
Eventually(srv).Should(SatisfyAll(
Expand Down Expand Up @@ -183,6 +185,7 @@ var _ = Describe("VolumeController", func() {
},
}
Expect(k8sClient.Create(ctx, volume)).To(Succeed())
DeferCleanup(ExpectVolumeDeleted, volume)

By("waiting for the runtime to report the volume")
Eventually(srv).Should(SatisfyAll(
Expand All @@ -192,7 +195,7 @@ var _ = Describe("VolumeController", func() {
_, oriVolume := GetSingleMapEntry(srv.Volumes)

Expect(oriVolume.Spec.Image).To(Equal(""))
Expect(oriVolume.Spec.Class).To(Equal(vc.Name))
Expect(oriVolume.Spec.Class).To(Equal(expandableVc.Name))
Expect(oriVolume.Spec.Resources.StorageBytes).To(Equal(uint64(size.Value())))

By("update increasing the storage resource")
Expand Down
6 changes: 3 additions & 3 deletions poollet/volumepoollet/controllers/volumepool_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,19 @@ func (r *VolumePoolReconciler) calculateCapacity(
}

supported = append(supported, corev1.LocalObjectReference{Name: volumeClass.Name})
capacity[corev1alpha1.ClassCountFor(corev1alpha1.ClassTypeVolumeClass, volumeClass.Name)] = *resource.NewQuantity(quantity, resource.DecimalSI)
capacity[corev1alpha1.ClassCountFor(corev1alpha1.ClassTypeVolumeClass, volumeClass.Name)] = *resource.NewQuantity(quantity, resource.BinarySI)
}

usedResources := corev1alpha1.ResourceList{}
for _, volume := range volumes {
className := volume.Spec.VolumeClassRef.Name
res, ok := usedResources[corev1alpha1.ClassCountFor(corev1alpha1.ClassTypeVolumeClass, className)]
if !ok {
usedResources[corev1alpha1.ClassCountFor(corev1alpha1.ClassTypeVolumeClass, className)] = *resource.NewQuantity(1, resource.DecimalSI)
usedResources[corev1alpha1.ClassCountFor(corev1alpha1.ClassTypeVolumeClass, className)] = *volume.Spec.Resources.Storage()
continue
}

res.Add(resource.MustParse("1"))
res.Add(*volume.Spec.Resources.Storage())
}

return capacity, quota.SubtractWithNonNegativeResult(capacity, usedResources), supported, nil
Expand Down
Loading

0 comments on commit 8f57970

Please sign in to comment.