mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 19:13:34 +00:00
feat: set default log driver for service containers to 'local' (#83)
This commit is contained in:
+11
-4
@@ -30,8 +30,10 @@ const (
|
||||
PullPolicyNever = "never"
|
||||
)
|
||||
|
||||
var serviceIDRegexp = regexp.MustCompile("^[0-9a-f]{32}$")
|
||||
var dnsLabelRegexp = regexp.MustCompile(`^[a-z0-9]([-a-z0-9]*[a-z0-9])?$`)
|
||||
var (
|
||||
serviceIDRegexp = regexp.MustCompile("^[0-9a-f]{32}$")
|
||||
dnsLabelRegexp = regexp.MustCompile(`^[a-z0-9]([-a-z0-9]*[a-z0-9])?$`)
|
||||
)
|
||||
|
||||
func ValidateServiceID(id string) bool {
|
||||
return serviceIDRegexp.MatchString(id)
|
||||
@@ -104,7 +106,7 @@ func (s *ServiceSpec) Validate() error {
|
||||
default:
|
||||
return fmt.Errorf("invalid mode: %q", s.Mode)
|
||||
}
|
||||
|
||||
|
||||
if s.Name != "" {
|
||||
if len(s.Name) > 63 {
|
||||
return fmt.Errorf("service name too long (max 63 characters): %q", s.Name)
|
||||
@@ -146,7 +148,6 @@ func (s *ServiceSpec) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
func (s *ServiceSpec) Clone() ServiceSpec {
|
||||
spec := *s
|
||||
|
||||
@@ -200,6 +201,12 @@ type ContainerSpec struct {
|
||||
// SetDefaults returns a copy of the container spec with default values set.
|
||||
func (s *ContainerSpec) SetDefaults() ContainerSpec {
|
||||
spec := s.Clone()
|
||||
if spec.LogDriver == nil {
|
||||
spec.LogDriver = &LogDriver{
|
||||
Name: "local",
|
||||
Options: map[string]string{},
|
||||
}
|
||||
}
|
||||
if spec.PullPolicy == "" {
|
||||
spec.PullPolicy = PullPolicyMissing
|
||||
}
|
||||
|
||||
@@ -62,7 +62,6 @@ func assertContainerMatchesSpec(t *testing.T, ctr api.ServiceContainer, spec api
|
||||
assert.Equal(t, spec.Container.Init, ctr.HostConfig.Init)
|
||||
assert.True(t, strings.HasPrefix(ctr.Name, spec.Name+"-"))
|
||||
|
||||
// If LogDriver is not set, any log driver set as default in the Docker daemon config could be used.
|
||||
if spec.Container.LogDriver != nil {
|
||||
assert.Equal(t, spec.Container.LogDriver.Name, ctr.HostConfig.LogConfig.Type)
|
||||
assert.Equal(t, spec.Container.LogDriver.Options, ctr.HostConfig.LogConfig.Config)
|
||||
|
||||
Reference in New Issue
Block a user