-
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
970ef2c
commit 3225aa0
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
roles/openshift_health_checker/openshift_checks/docker_storage_driver_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,48 @@ | ||
# pylint: disable=missing-docstring | ||
from openshift_checks import OpenShiftCheck, get_var | ||
|
||
|
||
class DockerStorageDriverCheck(OpenShiftCheck): | ||
"""Check Docker storage driver compatibility. | ||
This check ensures that Docker is using a supported storage driver, | ||
and that Loopback is not being used (if using devicemapper). | ||
""" | ||
|
||
name = "docker_storage_driver_check" | ||
tags = ["preflight"] | ||
|
||
storage_drivers = ["devicemapper", "overlay2"] | ||
|
||
def run(self, tmp, task_vars): | ||
is_containerized = get_var(task_vars, "openshift", "common", "is_containerized") | ||
if not is_containerized: | ||
return {"changed": False} | ||
|
||
info = self.execute_module("docker_info", {}, task_vars).get("info", {}) | ||
|
||
if not self.is_supported_storage_driver(info): | ||
msg = "Unsupported Docker storage driver detected. Supported storage drivers: {drivers}" | ||
return {"failed": True, "msg": msg.format(drivers=self.storage_drivers)} | ||
|
||
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 {"changed": False} | ||
|
||
def is_supported_storage_driver(self, docker_info): | ||
return docker_info.get("Driver", "") in self.storage_drivers | ||
|
||
@staticmethod | ||
def is_using_loopback_device(docker_info): | ||
# Loopback device usage is only an issue if using devicemapper. | ||
# Skip this check if using any other storage driver. | ||
if docker_info.get("Driver", "") != "devicemapper": | ||
return False | ||
|
||
for status in docker_info.get("DriverStatus", []): | ||
if status[0] == "Data loop file": | ||
return bool(status[1]) | ||
|
||
return False |