Skip to content

Commit 67d8695

Browse files
committed
feat(deployment.py): add spec_annotations to deployments and carry forward
Add the spec_annotations dict and carry it forward to all the functions that control the manifest for deployments.
1 parent 919f49a commit 67d8695

2 files changed

Lines changed: 20 additions & 8 deletions

File tree

rootfs/scheduler/__init__.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ def deploy(self, namespace, name, image, entrypoint, command, **kwargs): # noqa
232232
"""Deploy Deployment depending on what's requested"""
233233
app_type = kwargs.get('app_type')
234234
version = kwargs.get('version')
235+
spec_annotations = {}
235236

236237
# If an RC already exists then stop processing of the deploy
237238
try:
@@ -255,19 +256,24 @@ def deploy(self, namespace, name, image, entrypoint, command, **kwargs): # noqa
255256
}
256257
# this depends on the deployment object having the latest information
257258
deployment = self.deployment.get(namespace, name).json()
259+
# a hack to persist the spec annotations on the deployment object to next release
260+
# instantiate spec_annotations and set to blank to avoid errors
261+
if 'annotations' in deployment['spec']['template']['metadata'].keys():
262+
old_spec_annotations = deployment['spec']['template']['metadata']['annotations']
263+
spec_annotations = old_spec_annotations
258264
if deployment['spec']['template']['metadata']['labels'] == labels:
259265
self.log(namespace, 'Deployment {} with release {} already exists. Stopping deploy'.format(name, version)) # noqa
260266
return
261267
except KubeException:
262268
# create the initial deployment object (and the first revision)
263269
self.deployment.create(
264-
namespace, name, image, entrypoint, command, **kwargs
270+
namespace, name, image, entrypoint, command, spec_annotations, **kwargs
265271
)
266272
else:
267273
try:
268274
# kick off a new revision of the deployment
269275
self.deployment.update(
270-
namespace, name, image, entrypoint, command, **kwargs
276+
namespace, name, image, entrypoint, command, spec_annotations, **kwargs
271277
)
272278
except KubeException as e:
273279
raise KubeException(
@@ -283,7 +289,10 @@ def scale(self, namespace, name, image, entrypoint, command, **kwargs):
283289
if e.response.status_code == 404:
284290
# create missing deployment - deleted if it fails
285291
try:
286-
self.deployment.create(namespace, name, image, entrypoint, command, **kwargs)
292+
spec_annotations = {}
293+
self.deployment.create(
294+
namespace, name, image, entrypoint, command, spec_annotations, **kwargs
295+
)
287296
except KubeException:
288297
# see if the deployment got created
289298
try:

rootfs/scheduler/resources/deployment.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def get(self, namespace, name=None, **kwargs):
3030

3131
return response
3232

33-
def manifest(self, namespace, name, image, entrypoint, command, **kwargs):
33+
def manifest(self, namespace, name, image, entrypoint, command, spec_annotations, **kwargs):
3434
replicas = kwargs.get('replicas', 0)
3535
batches = kwargs.get('deploy_batches', None)
3636
tags = kwargs.get('tags', {})
@@ -104,11 +104,14 @@ def manifest(self, namespace, name, image, entrypoint, command, **kwargs):
104104
# pod manifest spec
105105
manifest['spec']['template'] = self.pod.manifest(namespace, name, image, **kwargs)
106106

107+
# set the old deployment spec annotations on this deployment
108+
manifest['spec']['template']['metadata']['annotations'] = spec_annotations
109+
107110
return manifest
108111

109-
def create(self, namespace, name, image, entrypoint, command, **kwargs):
112+
def create(self, namespace, name, image, entrypoint, command, spec_annotations, **kwargs):
110113
manifest = self.manifest(namespace, name, image,
111-
entrypoint, command, **kwargs)
114+
entrypoint, command, spec_annotations, **kwargs)
112115

113116
url = self.api("/namespaces/{}/deployments", namespace)
114117
response = self.http_post(url, json=manifest)
@@ -124,9 +127,9 @@ def create(self, namespace, name, image, entrypoint, command, **kwargs):
124127

125128
return response
126129

127-
def update(self, namespace, name, image, entrypoint, command, **kwargs):
130+
def update(self, namespace, name, image, entrypoint, command, spec_annotations, **kwargs):
128131
manifest = self.manifest(namespace, name, image,
129-
entrypoint, command, **kwargs)
132+
entrypoint, command, spec_annotations, **kwargs)
130133

131134
url = self.api("/namespaces/{}/deployments/{}", namespace, name)
132135
response = self.http_put(url, json=manifest)

0 commit comments

Comments
 (0)