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
|
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):
|
def serialize_daemon_container_spec(container):
|
||||||
cont_spec = {
|
cont_spec = {
|
||||||
"name": container["name"],
|
"name": container["name"],
|
||||||
|
@ -112,13 +134,10 @@ def serialize_daemon_container_spec(container):
|
||||||
"name": "CM_VERSION",
|
"name": "CM_VERSION",
|
||||||
"value": container['cm_version']
|
"value": container['cm_version']
|
||||||
})
|
})
|
||||||
if container.get("probes", {}).get("liveness"):
|
liveness = container.get("probes", {}).get("liveness", {})
|
||||||
cont_spec["livenessProbe"] = {
|
if liveness:
|
||||||
"exec": {
|
liveness_spec = serialize_liveness_probe(liveness)
|
||||||
"command": [container["probes"]["liveness"]]
|
cont_spec.update(liveness_spec)
|
||||||
},
|
|
||||||
"timeoutSeconds": 1
|
|
||||||
}
|
|
||||||
cont_spec["securityContext"] = {"privileged":
|
cont_spec["securityContext"] = {"privileged":
|
||||||
container.get("privileged", False)}
|
container.get("privileged", False)}
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,13 @@ class TestDeploy(base.TestCase):
|
||||||
"valuePath": "metadata.name"
|
"valuePath": "metadata.name"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}]
|
}],
|
||||||
|
"probes": {
|
||||||
|
"liveness": {
|
||||||
|
"command": "true",
|
||||||
|
"type": "exec"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
container_spec = templates.serialize_daemon_container_spec(container)
|
container_spec = templates.serialize_daemon_container_spec(container)
|
||||||
expected = {
|
expected = {
|
||||||
|
@ -49,6 +55,13 @@ class TestDeploy(base.TestCase):
|
||||||
},
|
},
|
||||||
"timeoutSeconds": 1
|
"timeoutSeconds": 1
|
||||||
},
|
},
|
||||||
|
"livenessProbe": {
|
||||||
|
"exec": {
|
||||||
|
"command": ['true']
|
||||||
|
},
|
||||||
|
"timeoutSeconds": 1,
|
||||||
|
"initialDelaySeconds": 10
|
||||||
|
},
|
||||||
"env": [{
|
"env": [{
|
||||||
"name": "CCP_NODE_NAME",
|
"name": "CCP_NODE_NAME",
|
||||||
'valueFrom': {
|
'valueFrom': {
|
||||||
|
@ -74,3 +87,37 @@ class TestDeploy(base.TestCase):
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.assertDictEqual(expected, container_spec)
|
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 = {
|
SERVICE_SCHEMA = {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"additionalProperties": False,
|
"additionalProperties": False,
|
||||||
|
@ -168,7 +212,7 @@ SERVICE_SCHEMA = {
|
||||||
|
|
||||||
"properties": {
|
"properties": {
|
||||||
"readiness": NOT_EMPTY_STRING_SCHEMA,
|
"readiness": NOT_EMPTY_STRING_SCHEMA,
|
||||||
"liveness": NOT_EMPTY_STRING_SCHEMA
|
"liveness": PROBE_SCHEMA
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"volumes": {
|
"volumes": {
|
||||||
|
|
Loading…
Reference in New Issue