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

Adding secretef Webhook For Backingstore and Namespacestore #930

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/admission/validate_namespacestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ func (nsv *ResourceValidator) ValidateUpdateNS() {
nsv.SetValidationResult(false, err.Error())
return
}
if err := validations.ValidateNamespacestoreSecretRefNamespace(*ns); err != nil && util.IsValidationError(err) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that the call for ValidateNamespacestoreSecretRefNamespace should be inside ValidateNamespaceStore function, that way this validation will be checked in creation ops as well.

nsv.SetValidationResult(false, err.Error())
return
}
}
}

Expand Down
38 changes: 36 additions & 2 deletions pkg/validations/backingstore_validations.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func ValidateBackingStore(bs nbv1.BackingStore) error {
if err := ValidateBSEmptyTargetBucket(bs); err != nil {
return err
}

switch bs.Spec.Type {
case nbv1.StoreTypePVPool:
if err := ValidatePvpoolNameLength(bs); err != nil {
Expand All @@ -39,10 +40,25 @@ func ValidateBackingStore(bs nbv1.BackingStore) error {
return err
}
case nbv1.StoreTypeS3Compatible:
return ValidateSigVersion(bs.Spec.S3Compatible.SignatureVersion)
if err := ValidateSigVersion(bs.Spec.S3Compatible.SignatureVersion); err != nil {
return err
}
if err := ValidateBackingstoreSecretRefNamespace(bs); err != nil {
return err
}
return nil
case nbv1.StoreTypeIBMCos:
return ValidateSigVersion(bs.Spec.IBMCos.SignatureVersion)
if err := ValidateSigVersion(bs.Spec.IBMCos.SignatureVersion); err != nil {
return err
}
if err := ValidateBackingstoreSecretRefNamespace(bs); err != nil {
return err
}
return nil
case nbv1.StoreTypeAWSS3, nbv1.StoreTypeAzureBlob, nbv1.StoreTypeGoogleCloudStorage:
if err := ValidateBackingstoreSecretRefNamespace(bs); err != nil {
return err
}
return nil
default:
return util.ValidationError{
Expand Down Expand Up @@ -272,3 +288,21 @@ func ValidateBackingstoreDeletion(bs nbv1.BackingStore, systemInfo nb.SystemInfo

return nil
}

// ValidateBackingstoreSecretRefNamespace validates that the secretref have namespace in it.
func ValidateBackingstoreSecretRefNamespace(bs nbv1.BackingStore) error{
secretRef, err := util.GetBackingStoreSecretByType(&bs);
if err != nil {
return util.ValidationError{
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not a validation error, it's an error in the retrieval of the Backingstore secret reference.
same goes for Namespacestore.

Msg: err.Error(),
}
}
if secretRef.Namespace == "" {
return util.ValidationError{
Msg: fmt.Sprintf("Secret ref %q in Backingstore %q must have namespace", secretRef.Name, bs.Name),
}
}

return nil

}
25 changes: 25 additions & 0 deletions pkg/validations/namespacestore_validations.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ func ValidateNamespaceStore(nsStore *nbv1.NamespaceStore) error {
if err := ValidateNSEmptyTargetBucket(*nsStore); err != nil {
return err
}

if nsStore.Spec.Type != nbv1.NSStoreTypeNSFS {
if err := ValidateNamespacestoreSecretRefNamespace(*nsStore); err != nil {
return err
}
}

switch nsStore.Spec.Type {

case nbv1.NSStoreTypeNSFS:
Expand Down Expand Up @@ -315,3 +322,21 @@ func ValidateNamespacestoreDeletion(ns nbv1.NamespaceStore, systemInfo nb.System

return nil
}

// ValidateNamespacestoreSecretRefNamespace validates that the secretref have namespace in it.
func ValidateNamespacestoreSecretRefNamespace(ns nbv1.NamespaceStore) error{
secretRef, err := util.GetNamespaceStoreSecretByType(&ns);
if err != nil {
return util.ValidationError{
Msg: err.Error(),
}
}
if secretRef.Namespace == "" {
return util.ValidationError{
Msg: fmt.Sprintf("Secret ref %q in NamespaceStore %q must have namespace", secretRef.Name, ns.Name),
}
}

return nil

}