diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-02-13 02:34:42 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-13 02:34:42 +0100 |
commit | a65f6b888ac4df13efec70c0d86c61af9090e3b7 (patch) | |
tree | 81c6598455eddfb6c4861265e76596b1bf561b5d /pkg/spec/parse.go | |
parent | 2281cbdd6d5b1b7bca99a605ffc8625b6bee7eb3 (diff) | |
parent | d3260738d330b6141fec5f11f1a3a91f40365018 (diff) | |
download | podman-a65f6b888ac4df13efec70c0d86c61af9090e3b7.tar.gz podman-a65f6b888ac4df13efec70c0d86c61af9090e3b7.tar.bz2 podman-a65f6b888ac4df13efec70c0d86c61af9090e3b7.zip |
Merge pull request #5152 from QiWang19/device-cgroup-rule
support device-cgroup-rule
Diffstat (limited to 'pkg/spec/parse.go')
-rw-r--r-- | pkg/spec/parse.go | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/pkg/spec/parse.go b/pkg/spec/parse.go index 6fa0b0636..a5dfccdb9 100644 --- a/pkg/spec/parse.go +++ b/pkg/spec/parse.go @@ -2,12 +2,17 @@ package createconfig import ( "fmt" + "regexp" "strconv" "strings" "github.com/docker/go-units" + "github.com/pkg/errors" ) +// deviceCgroupRulegex defines the valid format of device-cgroup-rule +var deviceCgroupRuleRegex = regexp.MustCompile(`^([acb]) ([0-9]+|\*):([0-9]+|\*) ([rwm]{1,3})$`) + // Pod signifies a kernel namespace is being shared // by a container with the pod it is associated with const Pod = "pod" @@ -205,3 +210,16 @@ func IsValidDeviceMode(mode string) bool { } return true } + +// validateDeviceCgroupRule validates the format of deviceCgroupRule +func validateDeviceCgroupRule(deviceCgroupRule string) error { + if !deviceCgroupRuleRegex.MatchString(deviceCgroupRule) { + return errors.Errorf("invalid device cgroup rule format: '%s'", deviceCgroupRule) + } + return nil +} + +// parseDeviceCgroupRule matches and parses the deviceCgroupRule into slice +func parseDeviceCgroupRule(deviceCgroupRule string) [][]string { + return deviceCgroupRuleRegex.FindAllStringSubmatch(deviceCgroupRule, -1) +} |