Skip to content

Commit

Permalink
validate storageClaims in tiflash
Browse files Browse the repository at this point in the history
  • Loading branch information
hoyhbx committed Sep 28, 2022
1 parent 35f941e commit ebdd0e2
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/apis/pingcap/v1alpha1/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,14 @@ func validateTiFlashSpec(spec *v1alpha1.TiFlashSpec, fldPath *field.Path) field.
spec.StorageClaims, "storageClaims should be configured at least one item."))
}
allErrs = append(allErrs, validateScalePolicy(&spec.ScalePolicy, fldPath.Child("scalePolicy"))...)

// fix storageClaim
for _, storageClaim := range spec.StorageClaims {
if _, ok := storageClaim.Resources.Requests["storage"]; !ok {
allErrs = append(allErrs, field.Invalid(fldPath.Child("spec.StorageClaims.Resources.Requests"),
spec.StorageClaims, "spec.tiflash.storageClaims.resources[storage]: Required value."))
}
}
return allErrs
}

Expand Down
64 changes: 64 additions & 0 deletions pkg/apis/pingcap/v1alpha1/validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,62 @@ func TestValidatePumpSpec(t *testing.T) {
}
}

func TestValidateTiFlashSpec(t *testing.T) {
g := NewGomegaWithT(t)
tests := []struct {
name string
replicas int32
expectedErrors int
storageClaims []v1alpha1.StorageClaim
}{
{
name: "has storage request",
replicas: 1,
expectedErrors: 0,
storageClaims: []v1alpha1.StorageClaim{
{
Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceStorage: resource.MustParse("10G"),
},
},
},
},
},
{
name: "no storage request",
replicas: 1,
expectedErrors: 3,
storageClaims: []v1alpha1.StorageClaim{
{
Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{},
},
},
{
Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{},
},
},
{
Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{},
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tc := newTidbClusterWithTiflash()
tc.Spec.TiFlash.StorageClaims = tt.storageClaims
err := validateTiFlashSpec(tc.Spec.TiFlash, field.NewPath("spec", "tiflash"))
r := len(err)
g.Expect(r).Should(Equal(tt.expectedErrors))
})
}
}

func TestValidateRequestsStorage(t *testing.T) {
g := NewGomegaWithT(t)
tests := []struct {
Expand Down Expand Up @@ -542,6 +598,14 @@ func newTidbCluster() *v1alpha1.TidbCluster {
return tc
}

func newTidbClusterWithTiflash() *v1alpha1.TidbCluster {
tc := newTidbCluster()
tc.Spec.TiFlash = &v1alpha1.TiFlashSpec{
Replicas: 1,
}
return tc
}

func newService() *v1alpha1.ServiceSpec {
svc := &v1alpha1.ServiceSpec{}
return svc
Expand Down

0 comments on commit ebdd0e2

Please sign in to comment.