Merge "Kubernetes Driver: Allow cpu/mem resource limits"
This commit is contained in:
commit
71efc2ea9c
@ -1386,6 +1386,20 @@ Selecting the kubernetes driver adds the following options to the
|
||||
interpreter on Ansible >=2.8, and default to
|
||||
``/usr/bin/python2`` for earlier versions.
|
||||
|
||||
.. attr:: cpu
|
||||
:type: int
|
||||
|
||||
Only used by the
|
||||
:value:`providers.[kubernetes].pools.labels.type.pod` label type;
|
||||
specifies the number of cpu to request for the pod.
|
||||
|
||||
.. attr:: memory
|
||||
:type: int
|
||||
|
||||
Only used by the
|
||||
:value:`providers.[kubernetes].pools.labels.type.pod` label type;
|
||||
specifies the amount of memory in MB to request for the pod.
|
||||
|
||||
|
||||
|
||||
Openshift Driver
|
||||
|
@ -28,7 +28,9 @@ class KubernetesLabel(ConfigValue):
|
||||
other.type == self.type and
|
||||
other.image_pull == self.image_pull and
|
||||
other.python_path == self.python_path and
|
||||
other.image == self.image)
|
||||
other.image == self.image and
|
||||
other.cpu == self.cpu and
|
||||
other.memory == self.memory)
|
||||
return False
|
||||
|
||||
def __repr__(self):
|
||||
@ -57,6 +59,8 @@ class KubernetesPool(ConfigPool):
|
||||
pl.image = label.get('image')
|
||||
pl.image_pull = label.get('image-pull', 'IfNotPresent')
|
||||
pl.python_path = label.get('python-path', 'auto')
|
||||
pl.cpu = label.get('cpu')
|
||||
pl.memory = label.get('memory')
|
||||
pl.pool = self
|
||||
self.labels[pl.name] = pl
|
||||
full_config.labels[label['name']].pools.append(self)
|
||||
@ -99,6 +103,8 @@ class KubernetesProviderConfig(ProviderConfig):
|
||||
'image': str,
|
||||
'image-pull': str,
|
||||
'python-path': str,
|
||||
'cpu': int,
|
||||
'memory': int,
|
||||
}
|
||||
|
||||
pool = ConfigPool.getCommonSchemaDict()
|
||||
|
@ -269,25 +269,40 @@ class KubernetesProvider(Provider):
|
||||
return resource
|
||||
|
||||
def createPod(self, node, pool, label):
|
||||
resource = self.createNamespace(node, pool, restricted_access=True)
|
||||
namespace = resource['namespace']
|
||||
pod_body = {
|
||||
'apiVersion': 'v1',
|
||||
'kind': 'Pod',
|
||||
'metadata': {'name': label.name},
|
||||
'spec': {
|
||||
'containers': [{
|
||||
spec_body = {
|
||||
'name': label.name,
|
||||
'image': label.image,
|
||||
'imagePullPolicy': label.image_pull,
|
||||
'command': ["/bin/sh", "-c"],
|
||||
'args': ["while true; do sleep 30; done;"],
|
||||
'workingDir': '/tmp'
|
||||
}]
|
||||
'workingDir': '/tmp',
|
||||
}
|
||||
|
||||
if label.cpu or label.memory:
|
||||
spec_body['resources'] = {}
|
||||
for rtype in ('requests', 'limits'):
|
||||
rbody = {}
|
||||
if label.cpu:
|
||||
rbody['cpu'] = int(label.cpu)
|
||||
if label.memory:
|
||||
rbody['memory'] = '%dMi' % int(label.memory)
|
||||
spec_body['resources'][rtype] = rbody
|
||||
|
||||
pod_body = {
|
||||
'apiVersion': 'v1',
|
||||
'kind': 'Pod',
|
||||
'metadata': {'name': label.name},
|
||||
'spec': {
|
||||
'containers': [spec_body],
|
||||
},
|
||||
'restartPolicy': 'Never',
|
||||
}
|
||||
|
||||
resource = self.createNamespace(node, pool, restricted_access=True)
|
||||
namespace = resource['namespace']
|
||||
|
||||
self.k8s_client.create_namespaced_pod(namespace, pod_body)
|
||||
|
||||
for retry in range(300):
|
||||
pod = self.k8s_client.read_namespaced_pod(label.name, namespace)
|
||||
if pod.status.phase == "Running":
|
||||
|
@ -136,6 +136,8 @@ providers:
|
||||
- name: pod-fedora
|
||||
type: pod
|
||||
image: docker.io/fedora:28
|
||||
cpu: 2
|
||||
memory: 512
|
||||
|
||||
- name: openshift
|
||||
driver: openshift
|
||||
|
Loading…
x
Reference in New Issue
Block a user