Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pv support #109

Merged
merged 9 commits into from
Mar 28, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions controllers/gatling_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (

gatlingv1alpha1 "github.com/st-tech/gatling-operator/api/v1alpha1"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/pointer"
//+kubebuilder:scaffold:imports
Expand Down Expand Up @@ -84,5 +86,99 @@ var _ = Context("Inside of a new namespace", func() {
Expect(job.Spec.Completions).Should(Equal(pointer.Int32Ptr(2)))
})

It("shoud create a New Gatling resource with PersistentVolume resources", func() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shoud -> should

pvFS := corev1.PersistentVolumeFilesystem
gatling := &gatlingv1alpha1.Gatling{
ObjectMeta: metav1.ObjectMeta{
Name: gatlingName,
Namespace: ns.Name,
},
Spec: gatlingv1alpha1.GatlingSpec{
GenerateReport: false,
NotifyReport: false,
CleanupAfterJobDone: false,
PodSpec: gatlingv1alpha1.PodSpec{
Volumes: []corev1.Volume{
{
Name: "resource-vol",
VolumeSource: corev1.VolumeSource{
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
ClaimName: "resource-pvc",
},
},
},
},
},
PersistentVolumeSpec: gatlingv1alpha1.PersistentVolumeSpec{
Name: "resource-pv",
Spec: corev1.PersistentVolumeSpec{
VolumeMode: &pvFS,
AccessModes: []corev1.PersistentVolumeAccessMode{
corev1.ReadWriteOnce,
},
StorageClassName: "",
Capacity: corev1.ResourceList{
corev1.ResourceStorage: resource.MustParse("1Gi"),
},
PersistentVolumeSource: corev1.PersistentVolumeSource{
Local: &corev1.LocalVolumeSource{Path: "/tmp"},
},
NodeAffinity: &corev1.VolumeNodeAffinity{
Required: &corev1.NodeSelector{
NodeSelectorTerms: []corev1.NodeSelectorTerm{
{
MatchExpressions: []corev1.NodeSelectorRequirement{{Key: "kubernetes.io/os", Operator: corev1.NodeSelectorOpIn, Values: []string{"linux"}}},
},
},
},
},
},
},
PersistentVolumeClaimSpec: gatlingv1alpha1.PersistentVolumeClaimSpec{
Name: "resource-pvc",
Spec: corev1.PersistentVolumeClaimSpec{
AccessModes: []corev1.PersistentVolumeAccessMode{
corev1.ReadWriteOnce,
},
VolumeName: "resource-pv",
Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{corev1.ResourceStorage: resource.MustParse("1Gi")},
},
},
},
TestScenarioSpec: gatlingv1alpha1.TestScenarioSpec{
SimulationClass: "PersistentVolumeSampleSimulation",
Parallelism: 1,
VolumeMounts: []corev1.VolumeMount{
{
Name: "resource-vol",
MountPath: "/opt/gatling/user-files/resources/pv",
},
},
},
},
}
err := k8sClient.Create(ctx, gatling)
Expect(err).NotTo(HaveOccurred(), "failed to create test Gatling resource")

job := &batchv1.Job{}
Eventually(func() error {
return k8sClient.Get(
ctx, client.ObjectKey{Namespace: ns.Name, Name: gatlingName + "-runner"}, job)
}).Should(Succeed())

pv := &corev1.PersistentVolume{}
Eventually(func() error {
return k8sClient.Get(
ctx, client.ObjectKey{Namespace: ns.Name, Name: "resource-pv"}, pv)
}).Should(Succeed())

pvc := &corev1.PersistentVolumeClaim{}
Eventually(func() error {
return k8sClient.Get(
ctx, client.ObjectKey{Namespace: ns.Name, Name: "resource-pvc"}, pvc)
}).Should(Succeed())
})

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a question.

Are the below codes needed here?

Expect(job.Spec.Parallelism).Should(Equal(pointer.Int32Ptr(1)))
Expect(job.Spec.Completions).Should(Equal(pointer.Int32Ptr(1)))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the code confirms that the results of getGatlingRunnerJobParallelism are correct, we consider it unnecessary in the added test code. Of course, it can be added.

})
})
Loading