File tree Expand file tree Collapse file tree 5 files changed +92
-18
lines changed Expand file tree Collapse file tree 5 files changed +92
-18
lines changed Original file line number Diff line number Diff line change 1+ job "privileged-not-allowed" {
2+ datacenters = [" dc1" ]
3+
4+ group "privileged-not-allowed-group" {
5+ task "privileged-not-allowed-task" {
6+ driver = " containerd-driver"
7+
8+ config {
9+ image = " ubuntu:16.04"
10+ command = " sleep"
11+ args = [" 600s" ]
12+ privileged = true
13+ }
14+
15+ resources {
16+ cpu = 500
17+ memory = 256
18+ }
19+ }
20+ }
21+ }
File renamed without changes.
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ source $SRCDIR /utils.sh
4+ job_name=privileged-not-allowed
5+
6+ # allow_privileged=false set in the plugin config, should deny all privileged jobs.
7+ test_allow_privileged () {
8+ pushd ~ /go/src/github.com/Roblox/nomad-driver-containerd/example
9+
10+ cp agent.hcl agent.hcl.bkp
11+
12+ sed -i ' 8 i \ allow_privileged = false' agent.hcl
13+ sudo systemctl restart nomad
14+ is_systemd_service_active " nomad.service" true
15+
16+ echo " INFO: Starting nomad ${job_name} job using nomad-driver-containerd."
17+ nomad job run privileged_not_allowed.nomad
18+ # Sleep for 5 seconds, to allow ${alloc_id} to get populated.
19+ sleep 5s
20+
21+ echo " INFO: Checking status of ${job_name} job."
22+ alloc_id=$( nomad job status ${job_name} | grep failed| awk ' NR==1' | cut -d ' ' -f 1)
23+ output=$( nomad alloc status $alloc_id )
24+ echo -e " $output " | grep " Running privileged jobs are not allowed" & > /dev/null
25+ if [ $? -ne 0 ]; then
26+ echo " ERROR: ${job_name} should have failed to run."
27+ return 1
28+ fi
29+
30+ echo " INFO: purge nomad ${job_name} job."
31+ nomad job stop -purge ${job_name}
32+
33+ mv agent.hcl.bkp agent.hcl
34+ popd
35+ }
36+
37+ cleanup () {
38+ if [ -f agent.hcl.bkp ]; then
39+ mv agent.hcl.bkp agent.hcl
40+ fi
41+ sudo systemctl restart nomad
42+ is_systemd_service_active " nomad.service" false
43+ }
44+
45+ trap cleanup EXIT
46+
47+ test_allow_privileged
Original file line number Diff line number Diff line change 132132 sudo systemctl unmask containerd
133133 echo " INFO: Starting containerd daemon."
134134 sudo systemctl start containerd
135- is_systemd_service_active " containerd.service"
135+ is_systemd_service_active " containerd.service" false
136136
137137 # Remove default golang (1.7.3) and install a custom version (1.14.3) of golang.
138138 # This is required for supporting go mod, and to be able to compile nomad-driver-containerd.
184184
185185 echo " INFO: Starting nomad server and nomad-driver-containerd."
186186 sudo systemctl start nomad
187- is_systemd_service_active " nomad.service"
187+ is_systemd_service_active " nomad.service" false
188188 popd
189189}
190190
@@ -216,20 +216,4 @@ is_containerd_driver_active() {
216216 fi
217217}
218218
219- is_systemd_service_active () {
220- local service_name=$1
221- i=" 0"
222- while test $i -lt 5 && ! (systemctl -q is-active " $service_name " ); do
223- printf " INFO: %s is down, sleep for 4 seconds.\n" $service_name
224- sleep 4s
225- i=$[$i +1]
226- done
227-
228- if [ $i -ge 5 ]; then
229- printf " ERROR: %s didn't come up. exit 1.\n" $service_name
230- exit 1
231- fi
232- printf " INFO: %s is up and running\n" $service_name
233- }
234-
235219main " $@ "
Original file line number Diff line number Diff line change @@ -25,3 +25,25 @@ is_container_active() {
2525 exit 1
2626 fi
2727}
28+
29+ is_systemd_service_active () {
30+ local service_name=$1
31+ local is_sleep=$2
32+
33+ i=" 0"
34+ while test $i -lt 5 && ! (systemctl -q is-active " $service_name " ); do
35+ printf " INFO: %s is down, sleep for 4 seconds.\n" $service_name
36+ sleep 4s
37+ i=$[$i +1]
38+ done
39+
40+ if [ $i -ge 5 ]; then
41+ printf " ERROR: %s didn't come up. exit 1.\n" $service_name
42+ exit 1
43+ fi
44+
45+ if [ " $is_sleep " = true ]; then
46+ sleep 7s
47+ fi
48+ printf " INFO: %s is up and running\n" $service_name
49+ }
You can’t perform that action at this time.
0 commit comments