Add k8s annotations to pods
This allows adding key/value pairs under metadata.annotations in the kubernetes resource specification. This information can be used by different tools to govern handling of resources. One particular use-case is the runai-scheduler which uses annotations to allocate fractional GPU resources to a pod. Change-Id: Ib319caffe51e00bedda2861e8e1f2bbe04340322
This commit is contained in:
parent
4e3690812b
commit
60195adaea
|
@ -224,6 +224,16 @@ Selecting the kubernetes driver adds the following options to the
|
|||
that this field contains arbitrary key/value pairs and is
|
||||
unrelated to the concept of labels in Nodepool.
|
||||
|
||||
.. attr:: annotations
|
||||
:type: dict
|
||||
|
||||
A dictionary of additional values to be added to the
|
||||
pod metadata. The value of this field is
|
||||
added to the `metadata.annotations` field in OpenShift.
|
||||
This field contains arbitrary key/value pairs that can be accessed
|
||||
by tools and libraries. E.g custom schedulers can make use of this
|
||||
metadata.
|
||||
|
||||
.. attr:: python-path
|
||||
:type: str
|
||||
:default: auto
|
||||
|
|
|
@ -174,6 +174,16 @@ Selecting the openshift pods driver adds the following options to the
|
|||
that this field contains arbitrary key/value pairs and is
|
||||
unrelated to the concept of labels in Nodepool.
|
||||
|
||||
.. attr:: annotations
|
||||
:type: dict
|
||||
|
||||
A dictionary of additional values to be added to the
|
||||
pod metadata. The value of this field is
|
||||
added to the `metadata.annotations` field in OpenShift.
|
||||
This field contains arbitrary key/value pairs that can be accessed
|
||||
by tools and libraries. E.g custom schedulers can make use of this
|
||||
metadata.
|
||||
|
||||
.. attr:: cpu
|
||||
:type: int
|
||||
|
||||
|
|
|
@ -222,6 +222,16 @@ Selecting the openshift driver adds the following options to the
|
|||
that this field contains arbitrary key/value pairs and is
|
||||
unrelated to the concept of labels in Nodepool.
|
||||
|
||||
.. attr:: annotations
|
||||
:type: dict
|
||||
|
||||
A dictionary of additional values to be added to the
|
||||
pod metadata. The value of this field is
|
||||
added to the `metadata.annotations` field in OpenShift.
|
||||
This field contains arbitrary key/value pairs that can be accessed
|
||||
by tools and libraries. E.g custom schedulers can make use of this
|
||||
metadata.
|
||||
|
||||
.. attr:: python-path
|
||||
:type: str
|
||||
:default: auto
|
||||
|
|
|
@ -79,6 +79,7 @@ class KubernetesPool(ConfigPool):
|
|||
pl.volumes = label.get('volumes')
|
||||
pl.volume_mounts = label.get('volume-mounts')
|
||||
pl.labels = label.get('labels')
|
||||
pl.annotations = label.get('annotations')
|
||||
pl.pool = self
|
||||
self.labels[pl.name] = pl
|
||||
full_config.labels[label['name']].pools.append(self)
|
||||
|
@ -133,6 +134,7 @@ class KubernetesProviderConfig(ProviderConfig):
|
|||
'volumes': list,
|
||||
'volume-mounts': list,
|
||||
'labels': dict,
|
||||
'annotations': dict,
|
||||
}
|
||||
|
||||
pool = ConfigPool.getCommonSchemaDict()
|
||||
|
|
|
@ -371,12 +371,17 @@ class KubernetesProvider(Provider, QuotaSupport):
|
|||
'nodepool_node_label': label.name,
|
||||
})
|
||||
|
||||
k8s_annotations = {}
|
||||
if label.annotations:
|
||||
k8s_annotations.update(label.annotations)
|
||||
|
||||
pod_body = {
|
||||
'apiVersion': 'v1',
|
||||
'kind': 'Pod',
|
||||
'metadata': {
|
||||
'name': label.name,
|
||||
'labels': k8s_labels,
|
||||
'annotations': k8s_annotations,
|
||||
},
|
||||
'spec': spec_body,
|
||||
'restartPolicy': 'Never',
|
||||
|
|
|
@ -79,6 +79,7 @@ class OpenshiftPool(ConfigPool):
|
|||
pl.volumes = label.get('volumes')
|
||||
pl.volume_mounts = label.get('volume-mounts')
|
||||
pl.labels = label.get('labels')
|
||||
pl.annotations = label.get('annotations')
|
||||
pl.pool = self
|
||||
self.labels[pl.name] = pl
|
||||
full_config.labels[label['name']].pools.append(self)
|
||||
|
@ -135,6 +136,7 @@ class OpenshiftProviderConfig(ProviderConfig):
|
|||
'volumes': list,
|
||||
'volume-mounts': list,
|
||||
'labels': dict,
|
||||
'annotations': dict,
|
||||
}
|
||||
|
||||
pool = ConfigPool.getCommonSchemaDict()
|
||||
|
|
|
@ -288,12 +288,17 @@ class OpenshiftProvider(Provider, QuotaSupport):
|
|||
'nodepool_node_label': label.name,
|
||||
})
|
||||
|
||||
k8s_annotations = {}
|
||||
if label.annotations:
|
||||
k8s_annotations.update(label.annotations)
|
||||
|
||||
pod_body = {
|
||||
'apiVersion': 'v1',
|
||||
'kind': 'Pod',
|
||||
'metadata': {
|
||||
'name': pod_name,
|
||||
'labels': k8s_labels,
|
||||
'annotations': k8s_annotations,
|
||||
},
|
||||
'spec': spec_body,
|
||||
'restartPolicy': 'Never',
|
||||
|
|
|
@ -69,6 +69,7 @@ class OpenshiftPodsProviderConfig(OpenshiftProviderConfig):
|
|||
'volumes': list,
|
||||
'volume-mounts': list,
|
||||
'labels': dict,
|
||||
'annotations': dict,
|
||||
}
|
||||
|
||||
pool = ConfigPool.getCommonSchemaDict()
|
||||
|
|
|
@ -138,6 +138,7 @@ class TestDriverKubernetes(tests.DBTestCase):
|
|||
ns, pod = self.fake_k8s_client._pod_requests[0]
|
||||
self.assertEqual(pod['metadata'], {
|
||||
'name': 'pod-fedora',
|
||||
'annotations': {},
|
||||
'labels': {
|
||||
'nodepool_node_id': '0000000000',
|
||||
'nodepool_provider_name': 'kubespray',
|
||||
|
@ -190,6 +191,7 @@ class TestDriverKubernetes(tests.DBTestCase):
|
|||
ns, pod = self.fake_k8s_client._pod_requests[0]
|
||||
self.assertEqual(pod['metadata'], {
|
||||
'name': 'pod-extra',
|
||||
'annotations': {},
|
||||
'labels': {
|
||||
'environment': 'qa',
|
||||
'nodepool_node_id': '0000000000',
|
||||
|
|
|
@ -169,6 +169,7 @@ class TestDriverOpenshift(tests.DBTestCase):
|
|||
ns, pod = self.fake_k8s_client._pod_requests[0]
|
||||
self.assertEqual(pod['metadata'], {
|
||||
'name': 'pod-fedora',
|
||||
'annotations': {},
|
||||
'labels': {
|
||||
'nodepool_node_id': '0000000000',
|
||||
'nodepool_provider_name': 'openshift',
|
||||
|
@ -224,6 +225,7 @@ class TestDriverOpenshift(tests.DBTestCase):
|
|||
ns, pod = self.fake_k8s_client._pod_requests[0]
|
||||
self.assertEqual(pod['metadata'], {
|
||||
'name': 'pod-extra',
|
||||
'annotations': {},
|
||||
'labels': {
|
||||
'environment': 'qa',
|
||||
'nodepool_node_id': '0000000000',
|
||||
|
|
Loading…
Reference in New Issue