|
9 | 9 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
10 | 10 | "k8s.io/apimachinery/pkg/types" |
11 | 11 | "sigs.k8s.io/controller-runtime/pkg/reconcile" |
| 12 | + |
| 13 | + psmdbv1 "github.com/percona/percona-server-mongodb-operator/pkg/apis/psmdb/v1" |
12 | 14 | ) |
13 | 15 |
|
14 | 16 | var _ = Describe("PerconaServerMongoDB", Ordered, func() { |
@@ -52,3 +54,58 @@ var _ = Describe("PerconaServerMongoDB", Ordered, func() { |
52 | 54 | Expect(err).To(Succeed()) |
53 | 55 | }) |
54 | 56 | }) |
| 57 | + |
| 58 | +var _ = Describe("PerconaServerMongoDB CRD Validation", Ordered, func() { |
| 59 | + ctx := context.Background() |
| 60 | + const ns = "psmdb-validation" |
| 61 | + namespace := &corev1.Namespace{ |
| 62 | + ObjectMeta: metav1.ObjectMeta{ |
| 63 | + Name: ns, |
| 64 | + Namespace: ns, |
| 65 | + }, |
| 66 | + } |
| 67 | + |
| 68 | + BeforeAll(func() { |
| 69 | + By("Creating the Namespace to perform the tests") |
| 70 | + err := k8sClient.Create(ctx, namespace) |
| 71 | + Expect(err).To(Not(HaveOccurred())) |
| 72 | + }) |
| 73 | + |
| 74 | + AfterAll(func() { |
| 75 | + By("Deleting the Namespace to perform the tests") |
| 76 | + _ = k8sClient.Delete(ctx, namespace) |
| 77 | + }) |
| 78 | + |
| 79 | + Context("StorageScaling validation", func() { |
| 80 | + It("should reject autoscaling enabled when enableVolumeScaling is disabled", func() { |
| 81 | + cr, err := readDefaultCR("psmdb-invalid-autoscaling", ns) |
| 82 | + Expect(err).NotTo(HaveOccurred()) |
| 83 | + |
| 84 | + cr.Spec.StorageScaling = &psmdbv1.StorageScalingSpec{ |
| 85 | + EnableVolumeScaling: false, |
| 86 | + Autoscaling: &psmdbv1.AutoscalingSpec{ |
| 87 | + Enabled: true, |
| 88 | + }, |
| 89 | + } |
| 90 | + |
| 91 | + err = k8sClient.Create(ctx, cr) |
| 92 | + Expect(err).To(HaveOccurred()) |
| 93 | + Expect(err.Error()).To(ContainSubstring("autoscaling cannot be enabled when enableVolumeScaling is disabled")) |
| 94 | + }) |
| 95 | + |
| 96 | + It("should allow autoscaling enabled when enableVolumeScaling is enabled", func() { |
| 97 | + cr, err := readDefaultCR("psmdb-valid-autoscaling", ns) |
| 98 | + Expect(err).NotTo(HaveOccurred()) |
| 99 | + |
| 100 | + cr.Spec.StorageScaling = &psmdbv1.StorageScalingSpec{ |
| 101 | + EnableVolumeScaling: true, |
| 102 | + Autoscaling: &psmdbv1.AutoscalingSpec{ |
| 103 | + Enabled: true, |
| 104 | + }, |
| 105 | + } |
| 106 | + |
| 107 | + err = k8sClient.Create(ctx, cr) |
| 108 | + Expect(err).NotTo(HaveOccurred()) |
| 109 | + }) |
| 110 | + }) |
| 111 | +}) |
0 commit comments