Skip to content

Commit 6e8fc9a

Browse files
Sivaram Mothikimboersma
authored andcommitted
feat(deisctl): add support for swarm scheduler components
fix(swarm): change swarm binary path in swarm.go ref(swarm): refactor code fix(test): add /deis/scheduler directory in controller functional test
1 parent 57e7fc3 commit 6e8fc9a

14 files changed

Lines changed: 235 additions & 169 deletions

File tree

builder/image/bin/boot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ DOCKER_PID=$!
6666

6767
# wait for docker to start
6868
while [[ ! -e /var/run/docker.sock ]]; do
69-
sleep 1
69+
sleep 1
7070
done
7171

7272
# build required images

contrib/coreos/user-data.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ write_files:
126126
content: |
127127
[Service]
128128
EnvironmentFile=/etc/environment_proxy
129-
Environment="DOCKER_OPTS=--insecure-registry 10.0.0.0/8 --insecure-registry 172.16.0.0/12 --insecure-registry 192.168.0.0/16 --insecure-registry 100.64.0.0/10 "
129+
Environment="DOCKER_OPTS=--insecure-registry 10.0.0.0/8 --insecure-registry 172.16.0.0/12 --insecure-registry 192.168.0.0/16 --insecure-registry 100.64.0.0/10"
130130
- path: /run/deis/bin/get_image
131131
permissions: '0755'
132132
content: |

controller/scheduler/swarm.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,31 +35,27 @@ def create(self, name, image, command='', template=None, **kwargs):
3535
self.docker_cli.create_container(image=cimage, name=name,
3636
command=command.encode('utf-8'), mem_limit=mem,
3737
cpu_shares=cpu,
38-
environment=[affinity])
39-
self.docker_cli.stop(name)
38+
environment=[affinity],
39+
host_config={'PublishAllPorts': True})
4040

4141
def start(self, name):
4242
"""
4343
Start a container
4444
"""
45-
self.docker_cli.start(name, publish_all_ports=True)
46-
47-
return
45+
self.docker_cli.start(name)
4846

4947
def stop(self, name):
5048
"""
5149
Stop a container
5250
"""
5351
self.docker_cli.stop(name)
54-
return
5552

5653
def destroy(self, name):
5754
"""
5855
Destroy a container
5956
"""
6057
self.stop(name)
6158
self.docker_cli.remove_container(name)
62-
return
6359

6460
def run(self, name, image, entrypoint, command):
6561
"""
@@ -97,20 +93,13 @@ def _get_container_state(self, name):
9793

9894
def state(self, name):
9995
try:
100-
# NOTE (bacongobbler): this call to ._get_unit() acts as a pre-emptive check to
101-
# determine if the job no longer exists (will raise a RuntimeError on 404)
10296
for _ in range(30):
10397
return self._get_container_state(name)
10498
time.sleep(1)
105-
# FIXME (bacongobbler): when fleet loads a job, sometimes it'll automatically start and
106-
# stop the container, which in our case will return as 'failed', even though
107-
# the container is perfectly fine.
99+
# FIXME (smothiki): should be able to send JobState.crashed
108100
except KeyError:
109-
# failed retrieving a proper response from the fleet API
110101
return JobState.error
111102
except RuntimeError:
112-
# failed to retrieve a response from the fleet API,
113-
# which means it does not exist
114103
return JobState.destroyed
115104

116105
def attach(self, name):

controller/templates/confd_settings.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212

1313
# scheduler swarm manager host
1414
SWARM_HOST = '{{ if exists "/deis/scheduler/swarm/host" }}{{ getv "/deis/scheduler/swarm/host" }}{{ else }}127.0.0.1{{ end }}'
15-
#SWARM_HOST = '{{ or (.deis_scheduler_swarm_host) "127.0.0.1" }}'
16-
1715

1816
# base64-encoded SSH private key to facilitate current version of "deis run"
1917
SSH_PRIVATE_KEY = """{{ if exists "/deis/platform/sshPrivateKey" }}{{ getv "/deis/platform/sshPrivateKey" }}{{ else }}""{{end}}"""

controller/tests/controller_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ func TestController(t *testing.T) {
2424
"/deis/database",
2525
"/deis/registry",
2626
"/deis/domains",
27+
"/deis/scheduler",
2728
}
2829
tag, etcdPort := utils.BuildTag(), utils.RandomPort()
2930
imageName := utils.ImagePrefix() + "controller" + ":" + tag

deisctl/cmd/cmd.go

Lines changed: 30 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
const (
2424
// PlatformCommand is shorthand for "all the Deis components."
2525
PlatformCommand string = "platform"
26+
swarm string = "swarm"
2627
)
2728

2829
// ListUnits prints a list of installed units.
@@ -100,10 +101,14 @@ Usage:
100101
// if target is platform, install all services
101102
targets := args["<target>"].([]string)
102103

103-
if len(targets) == 1 && targets[0] == PlatformCommand {
104-
return StartPlatform(b)
104+
if len(targets) == 1 {
105+
if targets[0] == PlatformCommand {
106+
return StartPlatform(b)
107+
}
108+
if targets[0] == swarm {
109+
return StartSwarm(b)
110+
}
105111
}
106-
107112
outchan := make(chan string)
108113
errchan := make(chan error)
109114
var wg sync.WaitGroup
@@ -132,28 +137,6 @@ deisctl config platform set sshPrivateKey=<path-to-key>
132137
return nil
133138
}
134139

135-
// StartPlatform activates all components.
136-
func StartPlatform(b backend.Backend) error {
137-
138-
outchan := make(chan string)
139-
errchan := make(chan error)
140-
var wg sync.WaitGroup
141-
142-
go printState(outchan, errchan, 500*time.Millisecond)
143-
144-
outchan <- utils.DeisIfy("Starting Deis...")
145-
146-
startDefaultServices(b, &wg, outchan, errchan)
147-
148-
wg.Wait()
149-
close(outchan)
150-
151-
fmt.Println("Done.")
152-
fmt.Println()
153-
fmt.Println("Please use `deis register` to setup an administrator account.")
154-
return nil
155-
}
156-
157140
func startDefaultServices(b backend.Backend, wg *sync.WaitGroup, outchan chan string, errchan chan error) {
158141

159142
// create separate channels for background tasks
@@ -218,8 +201,13 @@ Usage:
218201
targets := args["<target>"].([]string)
219202

220203
// if target is platform, stop all services
221-
if len(targets) == 1 && targets[0] == PlatformCommand {
222-
return StopPlatform(b)
204+
if len(targets) == 1 {
205+
if targets[0] == PlatformCommand {
206+
return StopPlatform(b)
207+
}
208+
if targets[0] == swarm {
209+
return StopSwarm(b)
210+
}
223211
}
224212

225213
outchan := make(chan string)
@@ -235,28 +223,6 @@ Usage:
235223
return nil
236224
}
237225

238-
// StopPlatform deactivates all components.
239-
func StopPlatform(b backend.Backend) error {
240-
241-
outchan := make(chan string)
242-
errchan := make(chan error)
243-
var wg sync.WaitGroup
244-
245-
go printState(outchan, errchan, 500*time.Millisecond)
246-
247-
outchan <- utils.DeisIfy("Stopping Deis...")
248-
249-
stopDefaultServices(b, &wg, outchan, errchan)
250-
251-
wg.Wait()
252-
close(outchan)
253-
254-
fmt.Println("Done.")
255-
fmt.Println()
256-
fmt.Println("Please run `deisctl start platform` to restart Deis.")
257-
return nil
258-
}
259-
260226
func stopDefaultServices(b backend.Backend, wg *sync.WaitGroup, outchan chan string, errchan chan error) {
261227

262228
outchan <- fmt.Sprintf("Routing mesh...")
@@ -372,12 +338,16 @@ Usage:
372338
return err
373339
}
374340

375-
// if target is platform, install all services
376341
targets := args["<target>"].([]string)
377-
if len(targets) == 1 && targets[0] == PlatformCommand {
378-
return InstallPlatform(b)
342+
// if target is platform, install all services
343+
if len(targets) == 1 {
344+
if targets[0] == PlatformCommand {
345+
return InstallPlatform(b)
346+
}
347+
if targets[0] == swarm {
348+
return InstallSwarm(b)
349+
}
379350
}
380-
381351
outchan := make(chan string)
382352
errchan := make(chan error)
383353
var wg sync.WaitGroup
@@ -392,33 +362,6 @@ Usage:
392362
return nil
393363
}
394364

395-
// InstallPlatform loads all components' definitions from local unit files.
396-
// After InstallPlatform, all components will be available for StartPlatform.
397-
func InstallPlatform(b backend.Backend) error {
398-
399-
if err := checkRequiredKeys(); err != nil {
400-
return err
401-
}
402-
403-
outchan := make(chan string)
404-
errchan := make(chan error)
405-
var wg sync.WaitGroup
406-
407-
go printState(outchan, errchan, 500*time.Millisecond)
408-
409-
outchan <- utils.DeisIfy("Installing Deis...")
410-
411-
installDefaultServices(b, &wg, outchan, errchan)
412-
413-
wg.Wait()
414-
close(outchan)
415-
416-
fmt.Println("Done.")
417-
fmt.Println()
418-
fmt.Println("Please run `deisctl start platform` to boot up Deis.")
419-
return nil
420-
}
421-
422365
func installDefaultServices(b backend.Backend, wg *sync.WaitGroup, outchan chan string, errchan chan error) {
423366

424367
outchan <- fmt.Sprintf("Storage subsystem...")
@@ -460,8 +403,13 @@ Usage:
460403

461404
// if target is platform, uninstall all services
462405
targets := args["<target>"].([]string)
463-
if len(targets) == 1 && targets[0] == PlatformCommand {
464-
return UninstallPlatform(b)
406+
if len(targets) == 1 {
407+
if targets[0] == PlatformCommand {
408+
return UninstallPlatform(b)
409+
}
410+
if targets[0] == swarm {
411+
return UnInstallSwarm(b)
412+
}
465413
}
466414

467415
outchan := make(chan string)
@@ -478,27 +426,6 @@ Usage:
478426
return nil
479427
}
480428

481-
// UninstallPlatform unloads all components' definitions.
482-
// After UninstallPlatform, all components will be unavailable.
483-
func UninstallPlatform(b backend.Backend) error {
484-
485-
outchan := make(chan string)
486-
errchan := make(chan error)
487-
var wg sync.WaitGroup
488-
489-
go printState(outchan, errchan, 500*time.Millisecond)
490-
491-
outchan <- utils.DeisIfy("Uninstalling Deis...")
492-
493-
uninstallAllServices(b, &wg, outchan, errchan)
494-
495-
wg.Wait()
496-
close(outchan)
497-
498-
fmt.Println("Done.")
499-
return nil
500-
}
501-
502429
func uninstallAllServices(b backend.Backend, wg *sync.WaitGroup, outchan chan string, errchan chan error) error {
503430

504431
outchan <- fmt.Sprintf("Routing mesh...")

deisctl/cmd/platform.go

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"sync"
6+
"time"
7+
8+
"github.com/deis/deis/deisctl/backend"
9+
"github.com/deis/deis/deisctl/utils"
10+
)
11+
12+
// InstallPlatform loads all components' definitions from local unit files.
13+
// After InstallPlatform, all components will be available for StartPlatform.
14+
func InstallPlatform(b backend.Backend) error {
15+
16+
if err := checkRequiredKeys(); err != nil {
17+
return err
18+
}
19+
20+
outchan := make(chan string)
21+
errchan := make(chan error)
22+
var wg sync.WaitGroup
23+
24+
go printState(outchan, errchan, 500*time.Millisecond)
25+
26+
outchan <- utils.DeisIfy("Installing Deis...")
27+
28+
installDefaultServices(b, &wg, outchan, errchan)
29+
30+
wg.Wait()
31+
close(outchan)
32+
33+
fmt.Println("Done.")
34+
fmt.Println()
35+
fmt.Println("Please run `deisctl start platform` to boot up Deis.")
36+
return nil
37+
}
38+
39+
// StartPlatform activates all components.
40+
func StartPlatform(b backend.Backend) error {
41+
42+
outchan := make(chan string)
43+
errchan := make(chan error)
44+
var wg sync.WaitGroup
45+
46+
go printState(outchan, errchan, 500*time.Millisecond)
47+
48+
outchan <- utils.DeisIfy("Starting Deis...")
49+
50+
startDefaultServices(b, &wg, outchan, errchan)
51+
52+
wg.Wait()
53+
close(outchan)
54+
55+
fmt.Println("Done.")
56+
fmt.Println()
57+
fmt.Println("Please use `deis register` to setup an administrator account.")
58+
return nil
59+
}
60+
61+
// StopPlatform deactivates all components.
62+
func StopPlatform(b backend.Backend) error {
63+
64+
outchan := make(chan string)
65+
errchan := make(chan error)
66+
var wg sync.WaitGroup
67+
68+
go printState(outchan, errchan, 500*time.Millisecond)
69+
70+
outchan <- utils.DeisIfy("Stopping Deis...")
71+
72+
stopDefaultServices(b, &wg, outchan, errchan)
73+
74+
wg.Wait()
75+
close(outchan)
76+
77+
fmt.Println("Done.")
78+
fmt.Println()
79+
fmt.Println("Please run `deisctl start platform` to restart Deis.")
80+
return nil
81+
}
82+
83+
// UninstallPlatform unloads all components' definitions.
84+
// After UninstallPlatform, all components will be unavailable.
85+
func UninstallPlatform(b backend.Backend) error {
86+
87+
outchan := make(chan string)
88+
errchan := make(chan error)
89+
var wg sync.WaitGroup
90+
91+
go printState(outchan, errchan, 500*time.Millisecond)
92+
93+
outchan <- utils.DeisIfy("Uninstalling Deis...")
94+
95+
uninstallAllServices(b, &wg, outchan, errchan)
96+
97+
wg.Wait()
98+
close(outchan)
99+
100+
fmt.Println("Done.")
101+
return nil
102+
}

0 commit comments

Comments
 (0)