Skip to content

Commit 39f9ac1

Browse files
committed
Several small fixes and simplifications
1 parent 031e02c commit 39f9ac1

4 files changed

Lines changed: 34 additions & 18 deletions

File tree

spawnctl/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ func actionDeploy(c *cli.Context) error {
205205
if len(timeoutStr) > 0 {
206206
timeout, err = time.ParseDuration(timeoutStr)
207207
if err != nil {
208-
fmt.Println("Illegal timeout parameter")
208+
fmt.Println("Illegal timeout parameter, must be in Go's time duration format, e.g. '5s'")
209209
os.Exit(1)
210210
} else if timeout < 0 {
211211
fmt.Println("Timeout duration must be positive")

spawnd/backend/docker.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const defaultSpawnpointImage = "jhkolb/spawnable:amd64"
2828
const logMaxSize = "50m"
2929
const cpuSharesPerCore = 1024
3030
const stopTimeout = 5 * time.Second
31+
const pidLimit = 8
3132

3233
type Docker struct {
3334
Alias string
@@ -118,6 +119,7 @@ func (dkr *Docker) StartService(ctx context.Context, svcConfig *service.Configur
118119
CPUShares: int64(svcConfig.CPUShares),
119120
Memory: int64(svcConfig.Memory * 1024 * 1024),
120121
Devices: devices,
122+
PidsLimit: pidLimit,
121123
},
122124
}
123125
if svcConfig.UseHostNet {

spawnd/daemon/core.go

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,23 @@ const heartbeatInterval = 10 * time.Second
1919
const persistenceInterval = 30 * time.Second
2020

2121
type Config struct {
22-
BW2Entity string `yaml:"bw2Entity"`
23-
BW2Agent string `yaml:"bw2Agent"`
24-
Path string `yaml:"path"`
25-
CPUShares uint64 `yaml:"cpuShares"`
26-
Memory uint64 `yaml:"memory"`
27-
Backend string `yaml:"backend"`
22+
BW2Entity string `yaml:"bw2Entity"`
23+
BW2Agent string `yaml:"bw2Agent"`
24+
Path string `yaml:"path"`
25+
CPUShares uint64 `yaml:"cpuShares"`
26+
Memory uint64 `yaml:"memory"`
27+
Backend string `yaml:"backend"`
28+
EnableHostNetworking bool `yaml:"enableHostNetworking"`
29+
EnableDeviceMapping bool `yaml:"enableDeviceMapping"`
2830
}
2931

3032
type SpawnpointDaemon struct {
33+
Config
3134
bw2Client *bw2.BW2Client
3235
bw2Service *bw2.Service
3336
backend backend.ServiceBackend
3437
logger *logging.Logger
35-
path string
3638
alias string
37-
totalCPUShares uint64
38-
totalMemory uint64
3939
availableCPUShares uint64
4040
availableMemory uint64
4141
resourceLock sync.RWMutex
@@ -56,11 +56,9 @@ func New(config *Config, logger *logging.Logger) (*SpawnpointDaemon, error) {
5656

5757
pathElements := strings.Split(config.Path, "/")
5858
daemon := SpawnpointDaemon{
59+
Config: *config,
5960
logger: logger,
6061
alias: pathElements[len(pathElements)-1],
61-
path: config.Path,
62-
totalCPUShares: config.CPUShares,
63-
totalMemory: config.Memory,
6462
availableCPUShares: config.CPUShares,
6563
availableMemory: config.Memory,
6664
serviceRegistry: make(map[string]*serviceManifest),
@@ -152,6 +150,22 @@ func (daemon *SpawnpointDaemon) handleConfig(msg *bw2.SimpleMessage) {
152150
return
153151
}
154152

153+
if svcConfig.UseHostNet && !daemon.EnableHostNetworking {
154+
daemon.logger.Debugf("(%s) Configuration requests use of host network, which is disabled", svcConfig.Name)
155+
msg := "[ERROR] Use of host networking stack not allowed on this host"
156+
if err := daemon.publishLogMessage(svcConfig.Name, msg); err != nil {
157+
daemon.logger.Errorf("(%s) Failed to publish log message", svcConfig.Name)
158+
}
159+
return
160+
} else if len(svcConfig.Devices) > 0 && !daemon.EnableDeviceMapping {
161+
daemon.logger.Debugf("(%s) Configuration requests device mapping(s), which are disabled", svcConfig.Name)
162+
msg := "[ERROR] Mapping devices into container not allowed on this host"
163+
if err := daemon.publishLogMessage(svcConfig.Name, msg); err != nil {
164+
daemon.logger.Errorf("(%s) Failed to publish log message", svcConfig.Name)
165+
}
166+
return
167+
}
168+
155169
svc := serviceManifest{Configuration: &svcConfig}
156170
daemon.addService(&svc, true)
157171
}

spawnd/daemon/heartbeat.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ func (daemon *SpawnpointDaemon) publishHeartbeatAux() {
5151
availableMemory := daemon.availableMemory
5252
daemon.resourceLock.RUnlock()
5353
daemon.logger.Debug("Publishing daemon heartbeat")
54-
daemon.logger.Debugf("CPU: %v/%v, Memory: %v/%v", availableCPU, daemon.totalCPUShares,
55-
availableMemory, daemon.totalMemory)
54+
daemon.logger.Debugf("CPU: %v/%v, Memory: %v/%v", availableCPU, daemon.CPUShares,
55+
availableMemory, daemon.Memory)
5656

5757
services := make([]string, len(daemon.serviceRegistry))
5858
daemon.registryLock.RLock()
@@ -66,8 +66,8 @@ func (daemon *SpawnpointDaemon) publishHeartbeatAux() {
6666
hb := Heartbeat{
6767
Version: util.VersionNum,
6868
Time: time.Now().UnixNano(),
69-
TotalCPU: daemon.totalCPUShares,
70-
TotalMemory: daemon.totalMemory,
69+
TotalCPU: daemon.CPUShares,
70+
TotalMemory: daemon.Memory,
7171
AvailableCPU: availableCPU,
7272
AvailableMemory: availableMemory,
7373
Services: services,
@@ -117,7 +117,7 @@ func (daemon *SpawnpointDaemon) publishServiceHeartbeats(ctx context.Context, sv
117117

118118
func (daemon *SpawnpointDaemon) Decommission() error {
119119
bw2Iface := daemon.bw2Service.RegisterInterface("daemon", "i.spawnpoint")
120-
daemon.logger.Debugf("Decomissioning spawnpoint %s", daemon.path)
120+
daemon.logger.Debugf("Decomissioning spawnpoint %s", daemon.Path)
121121
// A message without any POs is effectively a metadata de-persist
122122
if err := bw2Iface.PublishSignal("heartbeat"); err != nil {
123123
daemon.logger.Errorf("Failed to publish de-persist message: %s", err)

0 commit comments

Comments
 (0)