diff options
Diffstat (limited to 'libpod/options.go')
-rw-r--r-- | libpod/options.go | 60 |
1 files changed, 42 insertions, 18 deletions
diff --git a/libpod/options.go b/libpod/options.go index 33b423bce..8e0d3df86 100644 --- a/libpod/options.go +++ b/libpod/options.go @@ -4,11 +4,11 @@ import ( "net" "os" "path/filepath" - "regexp" "syscall" "github.com/containers/common/pkg/config" "github.com/containers/image/v5/manifest" + "github.com/containers/image/v5/types" "github.com/containers/libpod/libpod/define" "github.com/containers/libpod/libpod/events" "github.com/containers/libpod/pkg/namespaces" @@ -18,15 +18,7 @@ import ( "github.com/containers/storage/pkg/idtools" "github.com/cri-o/ocicni/pkg/ocicni" "github.com/pkg/errors" -) - -var ( - // NameRegex is a regular expression to validate container/pod names. - // This must NOT be changed from outside of Libpod. It should be a - // constant, but Go won't let us do that. - NameRegex = regexp.MustCompile("^[a-zA-Z0-9][a-zA-Z0-9_.-]*$") - // RegexError is thrown in presence of an invalid container/pod name. - RegexError = errors.Wrapf(define.ErrInvalidArg, "names must match [a-zA-Z0-9][a-zA-Z0-9_.-]*") + "github.com/sirupsen/logrus" ) // Runtime Creation Options @@ -254,6 +246,22 @@ func WithStaticDir(dir string) RuntimeOption { } } +// WithRegistriesConf configures the runtime to always use specified +// registries.conf for image processing. +func WithRegistriesConf(path string) RuntimeOption { + logrus.Debugf("Setting custom registries.conf: %q", path) + return func(rt *Runtime) error { + if _, err := os.Stat(path); err != nil { + return errors.Wrap(err, "error locating specified registries.conf") + } + if rt.imageContext == nil { + rt.imageContext = &types.SystemContext{} + } + rt.imageContext.SystemRegistriesConfPath = path + return nil + } +} + // WithHooksDir sets the directories to look for OCI runtime hook configuration. func WithHooksDir(hooksDirs ...string) RuntimeOption { return func(rt *Runtime) error { @@ -665,8 +673,8 @@ func WithName(name string) CtrCreateOption { } // Check the name against a regex - if !NameRegex.MatchString(name) { - return RegexError + if !define.NameRegex.MatchString(name) { + return define.RegexError } ctr.config.Name = name @@ -1383,8 +1391,8 @@ func WithVolumeName(name string) VolumeCreateOption { } // Check the name against a regex - if !NameRegex.MatchString(name) { - return RegexError + if !define.NameRegex.MatchString(name) { + return define.RegexError } volume.config.Name = name @@ -1502,8 +1510,8 @@ func WithPodName(name string) PodCreateOption { } // Check the name against a regex - if !NameRegex.MatchString(name) { - return RegexError + if !define.NameRegex.MatchString(name) { + return define.RegexError } pod.config.Name = name @@ -1520,8 +1528,8 @@ func WithPodHostname(hostname string) PodCreateOption { } // Check the hostname against a regex - if !NameRegex.MatchString(hostname) { - return RegexError + if !define.NameRegex.MatchString(hostname) { + return define.RegexError } pod.config.Hostname = hostname @@ -1692,6 +1700,22 @@ func WithPodUTS() PodCreateOption { } } +// WithPodCgroup tells containers in this pod to use the cgroup namespace +// created for this pod. +// Containers in a pod will inherit the kernel namespaces from the first +// container added. +func WithPodCgroup() PodCreateOption { + return func(pod *Pod) error { + if pod.valid { + return define.ErrPodFinalized + } + + pod.config.UsePodCgroupNS = true + + return nil + } +} + // WithInfraContainer tells the pod to create a pause container func WithInfraContainer() PodCreateOption { return func(pod *Pod) error { |