Merge "Add basic support of http liveness probe"
This commit is contained in:
commit
294fbf7dd3
|
@ -94,6 +94,28 @@ def serialize_env_variables(container):
|
|||
return env
|
||||
|
||||
|
||||
def serialize_liveness_probe(liveness):
|
||||
cont_spec = {}
|
||||
if liveness.get("type") == "httpGet":
|
||||
cont_spec["livenessProbe"] = {
|
||||
"httpGet": {
|
||||
"path": liveness["path"],
|
||||
"port": liveness["port"]
|
||||
},
|
||||
"timeoutSeconds": liveness.get("timeout", 1),
|
||||
"initialDelaySeconds": liveness.get("initialDelay", 10)
|
||||
}
|
||||
elif liveness.get("type") == "exec":
|
||||
cont_spec["livenessProbe"] = {
|
||||
"exec": {
|
||||
"command": [liveness["command"]]
|
||||
},
|
||||
"timeoutSeconds": liveness.get("timeout", 1),
|
||||
"initialDelaySeconds": liveness.get("initialDelay", 10)
|
||||
}
|
||||
return cont_spec
|
||||
|
||||
|
||||
def serialize_daemon_container_spec(container):
|
||||
cont_spec = {
|
||||
"name": container["name"],
|
||||
|
@ -112,13 +134,10 @@ def serialize_daemon_container_spec(container):
|
|||
"name": "CM_VERSION",
|
||||
"value": container['cm_version']
|
||||
})
|
||||
if container.get("probes", {}).get("liveness"):
|
||||
cont_spec["livenessProbe"] = {
|
||||
"exec": {
|
||||
"command": [container["probes"]["liveness"]]
|
||||
},
|
||||
"timeoutSeconds": 1
|
||||
}
|
||||
liveness = container.get("probes", {}).get("liveness", {})
|
||||
if liveness:
|
||||
liveness_spec = serialize_liveness_probe(liveness)
|
||||
cont_spec.update(liveness_spec)
|
||||
cont_spec["securityContext"] = {"privileged":
|
||||
container.get("privileged", False)}
|
||||
|
||||
|
|
|
@ -17,7 +17,13 @@ class TestDeploy(base.TestCase):
|
|||
"valuePath": "metadata.name"
|
||||
}
|
||||
}
|
||||
}]
|
||||
}],
|
||||
"probes": {
|
||||
"liveness": {
|
||||
"command": "true",
|
||||
"type": "exec"
|
||||
}
|
||||
}
|
||||
}
|
||||
container_spec = templates.serialize_daemon_container_spec(container)
|
||||
expected = {
|
||||
|
@ -49,6 +55,13 @@ class TestDeploy(base.TestCase):
|
|||
},
|
||||
"timeoutSeconds": 1
|
||||
},
|
||||
"livenessProbe": {
|
||||
"exec": {
|
||||
"command": ['true']
|
||||
},
|
||||
"timeoutSeconds": 1,
|
||||
"initialDelaySeconds": 10
|
||||
},
|
||||
"env": [{
|
||||
"name": "CCP_NODE_NAME",
|
||||
'valueFrom': {
|
||||
|
@ -74,3 +87,37 @@ class TestDeploy(base.TestCase):
|
|||
}
|
||||
}
|
||||
self.assertDictEqual(expected, container_spec)
|
||||
|
||||
def test_serialize_liveness_probe_exec(self):
|
||||
probe_definition = {"type": "exec", "command": "true"}
|
||||
expected = {
|
||||
"livenessProbe": {
|
||||
"exec": {
|
||||
"command": ["true"]
|
||||
},
|
||||
"timeoutSeconds": 1,
|
||||
"initialDelaySeconds": 10
|
||||
}
|
||||
}
|
||||
probe_spec = templates.serialize_liveness_probe(probe_definition)
|
||||
self.assertDictEqual(expected, probe_spec)
|
||||
|
||||
def test_serialize_liveness_probe_http(self):
|
||||
probe_definition = {
|
||||
"type": "httpGet",
|
||||
"path": "_status",
|
||||
"port": 8080,
|
||||
"initialDelay": 7
|
||||
}
|
||||
expected = {
|
||||
"livenessProbe": {
|
||||
"httpGet": {
|
||||
"path": "_status",
|
||||
"port": 8080
|
||||
},
|
||||
"timeoutSeconds": 1,
|
||||
"initialDelaySeconds": 7
|
||||
}
|
||||
}
|
||||
probe_spec = templates.serialize_liveness_probe(probe_definition)
|
||||
self.assertDictEqual(expected, probe_spec)
|
||||
|
|
|
@ -105,6 +105,50 @@ VOLUME_SCHEMA = {
|
|||
]
|
||||
}
|
||||
|
||||
TIMEOUT_SCHEMA = {
|
||||
"type": "integer",
|
||||
"minimum": 1,
|
||||
"maximum": 360
|
||||
}
|
||||
|
||||
PROBE_SCHEMA_EXEC = {
|
||||
"type": "object",
|
||||
"additionalProperties": False,
|
||||
"required": ["command", "type"],
|
||||
|
||||
"properties": {
|
||||
"type": "exec",
|
||||
"command": NOT_EMPTY_STRING_SCHEMA,
|
||||
"initialDelay": TIMEOUT_SCHEMA,
|
||||
"timeout": TIMEOUT_SCHEMA
|
||||
}
|
||||
}
|
||||
|
||||
PROBE_SCHEMA_HTTP = {
|
||||
"type": "object",
|
||||
"additionalProperties": False,
|
||||
"required": ["path", "type", "port"],
|
||||
|
||||
"properties": {
|
||||
"type": "httpGet",
|
||||
"port": {
|
||||
"type": "integer"
|
||||
},
|
||||
"path": NOT_EMPTY_STRING_SCHEMA,
|
||||
"initialDelay": TIMEOUT_SCHEMA,
|
||||
"timeout": TIMEOUT_SCHEMA
|
||||
}
|
||||
}
|
||||
|
||||
PROBE_SCHEMA = {
|
||||
"type": "object",
|
||||
"oneOf": [
|
||||
PROBE_SCHEMA_EXEC,
|
||||
PROBE_SCHEMA_HTTP
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
SERVICE_SCHEMA = {
|
||||
"type": "object",
|
||||
"additionalProperties": False,
|
||||
|
@ -168,7 +212,7 @@ SERVICE_SCHEMA = {
|
|||
|
||||
"properties": {
|
||||
"readiness": NOT_EMPTY_STRING_SCHEMA,
|
||||
"liveness": NOT_EMPTY_STRING_SCHEMA
|
||||
"liveness": PROBE_SCHEMA
|
||||
}
|
||||
},
|
||||
"volumes": {
|
||||
|
|
Loading…
Reference in New Issue