Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
cupnes committed Mar 8, 2024
1 parent 663513c commit ad9361c
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions internal/controller/rbdpvcbackup_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,4 +475,75 @@ var _ = Describe("RBDPVCBackup controller", func() {
return nil
}).Should(Succeed())
})

It("should fail the resource creation the second time if the same RBDPVCBackup is created twice", func() {
ctx := context.Background()
ns := createNamespace()

csiPVSource := corev1.CSIPersistentVolumeSource{
Driver: "driver",
VolumeHandle: "handle",
VolumeAttributes: map[string]string{
"imageName": "imageName",
"pool": "pool",
},
}
pv := corev1.PersistentVolume{
ObjectMeta: metav1.ObjectMeta{
Name: "pv4",
},
Spec: corev1.PersistentVolumeSpec{
Capacity: corev1.ResourceList{
"storage": resource.MustParse("5Gi"),
},
PersistentVolumeSource: corev1.PersistentVolumeSource{
CSI: &csiPVSource,
},
AccessModes: []corev1.PersistentVolumeAccessMode{
corev1.ReadWriteOnce,
},
},
}
err := k8sClient.Create(ctx, &pv)
Expect(err).NotTo(HaveOccurred())

pvc := corev1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{
Name: "pvc",
Namespace: ns,
},
Spec: corev1.PersistentVolumeClaimSpec{
AccessModes: []corev1.PersistentVolumeAccessMode{
corev1.ReadWriteOnce,
},
VolumeName: pv.Name,
Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceStorage: *resource.NewQuantity(1, resource.BinarySI),
},
},
},
}
err = k8sClient.Create(ctx, &pvc)
Expect(err).NotTo(HaveOccurred())

pvc.Status.Phase = corev1.ClaimBound
err = k8sClient.Status().Update(ctx, &pvc)
Expect(err).NotTo(HaveOccurred())

backup := backupv1.RBDPVCBackup{
ObjectMeta: metav1.ObjectMeta{
Name: "backup",
Namespace: ns,
},
Spec: backupv1.RBDPVCBackupSpec{
PVC: pvc.Name,
},
}
err = k8sClient.Create(ctx, &backup)
Expect(err).NotTo(HaveOccurred())

err = k8sClient.Create(ctx, &backup)
Expect(err).To(HaveOccurred())
})
})

0 comments on commit ad9361c

Please sign in to comment.