Skip to content
Permalink
Browse files

add mesos sandbox mount (#1481)

  • Loading branch information
nsinkov committed Mar 21, 2020
1 parent c86d01a commit 50d8d316aab7ef638c64c467f6fc87faac25e47e
@@ -2866,6 +2866,23 @@ def test_docker_workdir(self):
finally:
util.kill_jobs(self.cook_url, [job_uuid], assert_response=False)

@unittest.skipUnless(util.docker_tests_enabled(), 'Requires docker support')
def test_docker_workdir_mesos_sandbox(self):
image = util.docker_image()
container = {'type': 'docker',
'docker': {'image': image,
'network': 'HOST',
'force-pull-image': False,
'parameters': [{'key': 'workdir',
'value': '/mnt/mesos/sandbox'}]}}
command = 'bash -c \'touch zzz; if [[ $(pwd) == "/mnt/mesos/sandbox" ]] && [[ -f zzz ]]; then exit 0; else exit 1; fi\''
job_uuid, resp = util.submit_job(self.cook_url, command=command, container=container)
self.assertEqual(201, resp.status_code, resp.text)
try:
util.wait_for_instance(self.cook_url, job_uuid, status='success')
finally:
util.kill_jobs(self.cook_url, [job_uuid], assert_response=False)

@unittest.skipUnless(util.docker_tests_enabled(), "Requires docker support.")
def test_default_container_volumes(self):
settings = util.settings(self.cook_url)
@@ -406,10 +406,12 @@
(not= "RW" mode))))
sandbox-volume (make-empty-volume cook-sandbox-volume-name)
sandbox-volume-mount-fn #(make-volume-mount sandbox-volume sandbox-dir %)
sandbox-volume-mount (sandbox-volume-mount-fn false)]
sandbox-volume-mount (sandbox-volume-mount-fn false)
; mesos-sandbox-volume-mount added for Mesos backward compatibility
mesos-sandbox-volume-mount (make-volume-mount sandbox-volume "/mnt/mesos/sandbox" false)]
{:sandbox-volume-mount-fn sandbox-volume-mount-fn
:volumes (conj volumes sandbox-volume)
:volume-mounts (conj volume-mounts sandbox-volume-mount)}))
:volume-mounts (conj volume-mounts sandbox-volume-mount mesos-sandbox-volume-mount)}))

(defn toleration-for-pool
"For a given cook pool name, create the right V1Toleration so that Cook will ignore that cook-pool taint."
@@ -177,6 +177,7 @@
#(str "uuid-" (swap! n inc))))

(def sandbox-path "/mnt/sandbox")
(def legacy-sandbox-path "/mnt/mesos/sandbox")

(def expected-sandbox-volume
{:name api/cook-sandbox-volume-name
@@ -186,14 +187,18 @@
{:name api/cook-sandbox-volume-name
:mount-path sandbox-path
:read-only? false})
(def expected-legacy-sandbox-mount
{:name api/cook-sandbox-volume-name
:mount-path legacy-sandbox-path
:read-only? false})

(deftest test-make-volumes
(testing "empty cook volumes"
(let [{:keys [volumes volume-mounts]} (api/make-volumes [] sandbox-path)
volumes (map k8s-volume->clj volumes)
volume-mounts (map k8s-mount->clj volume-mounts)]
(is (= volumes [expected-sandbox-volume]))
(is (= volume-mounts [expected-sandbox-mount]))))
(is (= volume-mounts [expected-sandbox-mount expected-legacy-sandbox-mount]))))

(testing "valid generated volume names"
(let [host-path "/tmp/main/foo"
@@ -216,7 +221,7 @@
expected-sandbox-volume]))
(is (= volume-mounts
[{:name "syn-uuid-1" :mount-path host-path :read-only? true}
expected-sandbox-mount])))))
expected-sandbox-mount expected-legacy-sandbox-mount])))))

(testing "correct values for fully specified volume"
(let [host-path "/tmp/foo"
@@ -236,10 +241,10 @@
(with-redefs [config/kubernetes (constantly {:disallowed-container-paths #{"/tmp/foo"}})]
(let [{:keys [volumes volume-mounts]} (api/make-volumes [{:host-path "/tmp/foo"}] "/tmp/unused")]
(is (= 1 (count volumes)))
(is (= 1 (count volume-mounts))))
(is (= 2 (count volume-mounts))))
(let [{:keys [volumes volume-mounts]} (api/make-volumes [{:container-path "/tmp/foo"}] "/tmp/unused")]
(is (= 1 (count volumes)))
(is (= 1 (count volume-mounts)))))))
(is (= 2 (count volume-mounts)))))))


(deftest test-pod->synthesized-pod-state

0 comments on commit 50d8d31

Please sign in to comment.
You can’t perform that action at this time.