-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8751f88
commit 0bceb34
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
roles/openshift_health_checker/openshift_checks/docker_storage_check.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# pylint: disable=missing-docstring | ||
from openshift_checks import OpenShiftCheck, get_var | ||
|
||
|
||
class DockerStorageCheck(OpenShiftCheck): | ||
"""Check Docker storage sanity. | ||
This check ensures that Docker is using the devicemapper | ||
storage driver, that thinpool usage is not close to 100%, | ||
and that Loopback is not being used. | ||
""" | ||
|
||
name = "docker_storage_check" | ||
tags = ["preflight"] | ||
|
||
def run(self, tmp, task_vars): | ||
info = self.module_executor("docker_info", {}, task_vars).get("info", {}) | ||
|
||
if not self.is_devicemapper_used(info): | ||
msg = "Unsupported Docker storage driver detected. Only \"devicemapper\" is currently supported." | ||
return {"failed": True, "msg": msg} | ||
|
||
if self.is_using_loopback_device(info): | ||
msg = "Use of loopback devices is discouraged. Try running Docker with `--storage-opt dm.thinpooldev`" | ||
return {"failed": True, "msg": msg} | ||
|
||
return {"failed": True, "msg": "%s" % info.get("Data Space Available")} | ||
|
||
return {"changed": False} | ||
|
||
@staticmethod | ||
def is_devicemapper_used(docker_info): | ||
return docker_info.get("Driver", None) == "devicemapper" | ||
|
||
@staticmethod | ||
def is_using_loopback_device(info): | ||
for status in info.get("DriverStatus"): | ||
if status[0] == "Data loop file": | ||
return bool(status[1]) | ||
|
||
return False |