// NewCluster is exported func NewCluster(scheduler *scheduler.Scheduler, TLSConfig *tls.Config, discovery discovery.Backend, options cluster.DriverOpts, engineOptions *cluster.EngineOpts) (cluster.Cluster, error) { log.WithFields(log.Fields{"name": "swarm"}).Debug("Initializing cluster") cluster := &Cluster{ eventHandlers: cluster.NewEventHandlers(), engines: make(map[string]*cluster.Engine), pendingEngines: make(map[string]*cluster.Engine), scheduler: scheduler, TLSConfig: TLSConfig, discovery: discovery, pendingContainers: make(map[string]*pendingContainer), overcommitRatio: 0.05, engineOpts: engineOptions, createRetry: 0, } if val, ok := options.Float("swarm.overcommit", ""); ok { cluster.overcommitRatio = val } if val, ok := options.Int("swarm.createretry", ""); ok { if val < 0 { log.Fatalf("swarm.createretry=%d is invalid", val) } cluster.createRetry = val } discoveryCh, errCh := cluster.discovery.Watch(nil) go cluster.monitorDiscovery(discoveryCh, errCh) go cluster.monitorPendingEngines() return cluster, nil }
// NewCluster is exported func NewCluster(scheduler *scheduler.Scheduler, TLSConfig *tls.Config, discovery discovery.Backend, options cluster.DriverOpts, engineOptions *cluster.EngineOpts) (cluster.Cluster, error) { log.WithFields(log.Fields{"name": "swarm"}).Debug("Initializing cluster") cluster := &Cluster{ eventHandlers: cluster.NewEventHandlers(), engines: make(map[string]*cluster.Engine), pendingEngines: make(map[string]*cluster.Engine), scheduler: scheduler, TLSConfig: TLSConfig, discovery: discovery, pendingContainers: make(map[string]*pendingContainer), overcommitRatio: 0.05, engineOpts: engineOptions, createRetry: 0, } if val, ok := options.Float("swarm.overcommit", ""); ok { if val <= float64(-1) { log.Fatalf("swarm.overcommit should be larger than -1, %f is invalid", val) } else if val < float64(0) { log.Warn("-1 < swarm.overcommit < 0 will make swarm take less resource than docker engine offers") cluster.overcommitRatio = val } else { cluster.overcommitRatio = val } } if val, ok := options.Int("swarm.createretry", ""); ok { if val < 0 { log.Fatalf("swarm.createretry can not be negative, %d is invalid", val) } cluster.createRetry = val } discoveryCh, errCh := cluster.discovery.Watch(nil) go cluster.monitorDiscovery(discoveryCh, errCh) go cluster.monitorPendingEngines() return cluster, nil }