-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathevents.py
More file actions
44 lines (38 loc) · 1.5 KB
/
events.py
File metadata and controls
44 lines (38 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from scheduler.exceptions import KubeHTTPException
from scheduler.resources import Resource
from datetime import datetime
import uuid
DATETIME_FORMAT = '%Y-%m-%dT%H:%M:%SZ'
class Events(Resource):
"""
Events resource.
Warning! Used ONLY for testing purposes
"""
short_name = 'ev'
def create(self, namespace, name, message, **kwargs):
url = self.api('/namespaces/{}/events'.format(namespace))
data = {
'kind': 'Event',
'apiVersion': self.api_version,
'count': kwargs.get('count', 1),
'metadata': {
'creationTimestamp': datetime.now().strftime(DATETIME_FORMAT),
'namespace': namespace,
'name': name,
'resourceVersion': kwargs.get('resourceVersion', ''),
'uid': str(uuid.uuid4()),
},
'message': message,
'type': kwargs.get('type', 'Normal'),
'firstTimestamp': datetime.now().strftime(DATETIME_FORMAT),
'lastTimestamp': datetime.now().strftime(DATETIME_FORMAT),
'reason': kwargs.get('reason', ''),
'source': {
'component': kwargs.get('component', ''),
},
'involvedObject': kwargs.get('involvedObject', {})
}
response = self.http_post(url, json=data)
if not response.status_code == 201:
raise KubeHTTPException(response, 'create Event for namespace {}'.format(namespace)) # noqa
return response