Skip to content

Commit

Permalink
validate csidriverlvm-config
Browse files Browse the repository at this point in the history
  • Loading branch information
ostempel committed Nov 12, 2024
1 parent dd51c25 commit c40d048
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/apis/csidriverlvm/v1alpha1/types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package v1alpha1

import (
"regexp"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -17,3 +19,9 @@ type CsiDriverLvmConfig struct {
DevicePattern *string `json:"devicePattern,omitempty"`
HostWritePath *string `json:"hostWritePath,omitempty"`
}

func (config *CsiDriverLvmConfig) IsVaild() bool {
re := regexp.MustCompile(`^(/[^/ ]*)+/?$`)

return re.MatchString(*config.HostWritePath) && re.MatchString(*config.DevicePattern)
}
4 changes: 4 additions & 0 deletions pkg/controller/csi-driver-lvm/actuator.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ func (a *actuator) Reconcile(ctx context.Context, log logr.Logger, ex *extension
}
}

if !csidriverlvmConfig.IsVaild() {
return fmt.Errorf("invalid csi-driver-lvm configuration")
}

var hostwritepath = csidriverlvmConfig.HostWritePath
var devicepattern = csidriverlvmConfig.DevicePattern

Expand Down

0 comments on commit c40d048

Please sign in to comment.