Skip to content

Commit 35797d0

Browse files
committed
Added validations to reject invalid spec
1 parent 0bc8b7e commit 35797d0

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

pkg/validations/backingstore_validations.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,34 @@ const (
1818

1919
// ValidateBackingStore validates create validations on resource Backinstore
2020
func ValidateBackingStore(bs nbv1.BackingStore) error {
21+
//Ensure that the Spec contains the expected sub-spec for the declared type
22+
switch bs.Spec.Type {
23+
case nbv1.StoreTypeAWSS3:
24+
if bs.Spec.AWSS3 == nil {
25+
return util.ValidationError{Msg: "AWSS3 spec must be provided for type aws-s3"}
26+
}
27+
case nbv1.StoreTypeS3Compatible:
28+
if bs.Spec.S3Compatible == nil {
29+
return util.ValidationError{Msg: "S3Compatible spec must be provided for type s3-compatible"}
30+
}
31+
case nbv1.StoreTypeIBMCos:
32+
if bs.Spec.IBMCos == nil {
33+
return util.ValidationError{Msg: "IBMCos spec must be provided for type ibm-cos"}
34+
}
35+
case nbv1.StoreTypeAzureBlob:
36+
if bs.Spec.AzureBlob == nil {
37+
return util.ValidationError{Msg: "AzureBlob spec must be provided for type azure-blob"}
38+
}
39+
case nbv1.StoreTypeGoogleCloudStorage:
40+
if bs.Spec.GoogleCloudStorage == nil {
41+
return util.ValidationError{Msg: "GoogleCloudStorage spec must be provided for type google-cloud-storage"}
42+
}
43+
case nbv1.StoreTypePVPool:
44+
if bs.Spec.PVPool == nil {
45+
return util.ValidationError{Msg: "PVPool spec must be provided for type pv-pool"}
46+
}
47+
}
48+
2149
if err := ValidateBSEmptySecretName(bs); err != nil {
2250
return err
2351
}

pkg/validations/namespacestore_validations.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,34 @@ const (
1919

2020
// ValidateNamespaceStore validates namespacestore configuration
2121
func ValidateNamespaceStore(nsStore *nbv1.NamespaceStore) error {
22+
// ensure that the Spec contains the expected sub-spec for the declared type
23+
switch nsStore.Spec.Type {
24+
case nbv1.NSStoreTypeAWSS3:
25+
if nsStore.Spec.AWSS3 == nil {
26+
return util.ValidationError{Msg: "AWSS3 spec must be provided for type aws-s3"}
27+
}
28+
case nbv1.NSStoreTypeS3Compatible:
29+
if nsStore.Spec.S3Compatible == nil {
30+
return util.ValidationError{Msg: "S3Compatible spec must be provided for type s3-compatible"}
31+
}
32+
case nbv1.NSStoreTypeIBMCos:
33+
if nsStore.Spec.IBMCos == nil {
34+
return util.ValidationError{Msg: "IBMCos spec must be provided for type ibm-cos"}
35+
}
36+
case nbv1.NSStoreTypeAzureBlob:
37+
if nsStore.Spec.AzureBlob == nil {
38+
return util.ValidationError{Msg: "AzureBlob spec must be provided for type azure-blob"}
39+
}
40+
case nbv1.NSStoreTypeGoogleCloudStorage:
41+
if nsStore.Spec.GoogleCloudStorage == nil {
42+
return util.ValidationError{Msg: "GoogleCloudStorage spec must be provided for type google-cloud-storage"}
43+
}
44+
case nbv1.NSStoreTypeNSFS:
45+
if nsStore.Spec.NSFS == nil {
46+
return util.ValidationError{Msg: "NSFS spec must be provided for type nsfs"}
47+
}
48+
}
49+
2250
if err := ValidateNSEmptySecretName(*nsStore); err != nil {
2351
return err
2452
}

0 commit comments

Comments
 (0)