Skip to content

Commit 8d287b9

Browse files
authored
ref(scheduler): move image pull policy settings from scheduler to App model and remove SLUG_RUNNER_IMAGE_PULL_POLICY (#1053)
Removes the last of django.settings from scheduler main line code (not tests) IMAGE_PULL_POLICY is now the only thing used and can be set per app, SLUG_RUNNER_IMAGE_PULL_POLICY has been removed
1 parent bceb4c9 commit 8d287b9

3 files changed

Lines changed: 26 additions & 10 deletions

File tree

rootfs/api/models/app.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,9 @@ def _scale_pods(self, scale_types):
417417
# get application level pod termination grace period
418418
pod_termination_grace_period_seconds = release.config.values.get('KUBERNETES_POD_TERMINATION_GRACE_PERIOD_SECONDS', settings.KUBERNETES_POD_TERMINATION_GRACE_PERIOD_SECONDS) # noqa
419419

420+
# set the image pull policy that is associated with the application container
421+
image_pull_policy = release.config.values.get('IMAGE_PULL_POLICY', settings.IMAGE_PULL_POLICY) # noqa
422+
420423
# create image pull secret if needed
421424
image_pull_secret_name = self.image_pull_secret(self.id, registry, image)
422425

@@ -450,8 +453,14 @@ def _scale_pods(self, scale_types):
450453
'deploy_timeout': deploy_timeout,
451454
'pod_termination_grace_period_seconds': pod_termination_grace_period_seconds,
452455
'image_pull_secret_name': image_pull_secret_name,
456+
'image_pull_policy': image_pull_policy
453457
}
454458

459+
# Check if it is a slug builder image.
460+
if release.build.type == 'buildpack':
461+
# overwrite image so slugrunner image is used in the container
462+
image = settings.SLUGRUNNER_IMAGE
463+
455464
# gather all proc types to be deployed
456465
tasks.append(
457466
functools.partial(
@@ -512,6 +521,9 @@ def deploy(self, release, force_deploy=False, rollback_on_failure=True): # noqa
512521
# get application level pod termination grace period
513522
pod_termination_grace_period_seconds = release.config.values.get('KUBERNETES_POD_TERMINATION_GRACE_PERIOD_SECONDS', settings.KUBERNETES_POD_TERMINATION_GRACE_PERIOD_SECONDS) # noqa
514523

524+
# set the image pull policy that is associated with the application container
525+
image_pull_policy = release.config.values.get('IMAGE_PULL_POLICY', settings.IMAGE_PULL_POLICY) # noqa
526+
515527
# create image pull secret if needed
516528
image_pull_secret_name = self.image_pull_secret(self.id, registry, image)
517529

@@ -549,6 +561,7 @@ def deploy(self, release, force_deploy=False, rollback_on_failure=True): # noqa
549561
'release_summary': release.summary,
550562
'pod_termination_grace_period_seconds': pod_termination_grace_period_seconds,
551563
'image_pull_secret_name': image_pull_secret_name,
564+
'image_pull_policy': image_pull_policy
552565
}
553566

554567
# Sort deploys so routable comes first
@@ -561,6 +574,10 @@ def deploy(self, release, force_deploy=False, rollback_on_failure=True): # noqa
561574
# create the application config in k8s (secret in this case) for all deploy objects
562575
self._scheduler.set_application_config(self.id, envs, version)
563576

577+
if release.build.type == 'buildpack':
578+
# overwrite image so slugrunner image is used in the container
579+
image = settings.SLUGRUNNER_IMAGE
580+
564581
# gather all proc types to be deployed
565582
tasks = [
566583
functools.partial(
@@ -778,6 +795,9 @@ def pod_name(size=5, chars=string.ascii_lowercase + string.digits):
778795
# get application level pod termination grace period
779796
pod_termination_grace_period_seconds = release.config.values.get('KUBERNETES_POD_TERMINATION_GRACE_PERIOD_SECONDS', settings.KUBERNETES_POD_TERMINATION_GRACE_PERIOD_SECONDS) # noqa
780797

798+
# set the image pull policy that is associated with the application container
799+
image_pull_policy = release.config.values.get('IMAGE_PULL_POLICY', settings.IMAGE_PULL_POLICY) # noqa
800+
781801
# create image pull secret if needed
782802
image_pull_secret_name = self.image_pull_secret(self.id, registry, image)
783803

@@ -795,8 +815,14 @@ def pod_name(size=5, chars=string.ascii_lowercase + string.digits):
795815
'deploy_timeout': deploy_timeout,
796816
'pod_termination_grace_period_seconds': pod_termination_grace_period_seconds,
797817
'image_pull_secret_name': image_pull_secret_name,
818+
'image_pull_policy': image_pull_policy
798819
}
799820

821+
# Check if it is a slug builder image.
822+
if release.build.type == 'buildpack':
823+
# overwrite image so slugrunner image is used in the container
824+
image = settings.SLUGRUNNER_IMAGE
825+
800826
try:
801827
exit_code, output = self._scheduler.run(
802828
self.id,

rootfs/api/settings/production.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,6 @@
254254

255255
# k8s image policies
256256
SLUGRUNNER_IMAGE = os.environ.get('SLUGRUNNER_IMAGE_NAME', 'quay.io/deisci/slugrunner:canary') # noqa
257-
SLUG_RUNNER_IMAGE_PULL_POLICY = os.environ.get('SLUG_RUNNER_IMAGE_PULL_POLICY', "IfNotPresent") # noqa
258257
IMAGE_PULL_POLICY = os.environ.get('IMAGE_PULL_POLICY', "IfNotPresent") # noqa
259258

260259
# Define a global default on how many pods to bring up and then

rootfs/scheduler/resources/pod.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import os
44
import time
55

6-
from django.conf import settings
76
from scheduler.exceptions import KubeException, KubeHTTPException
87
from scheduler.resources import Resource
98
from scheduler.states import PodState
@@ -110,9 +109,6 @@ def manifest(self, namespace, name, image, **kwargs):
110109
# How long until a pod is forcefully terminated. 30 is kubernetes default
111110
spec['terminationGracePeriodSeconds'] = kwargs.get('pod_termination_grace_period_seconds', 30) # noqa
112111

113-
# set the image pull policy that is associated with the application container
114-
kwargs['image_pull_policy'] = settings.IMAGE_PULL_POLICY
115-
116112
# Check if it is a slug builder image.
117113
if build_type == "buildpack":
118114
# only buildpack apps need access to object storage
@@ -137,11 +133,6 @@ def manifest(self, namespace, name, image, **kwargs):
137133
'readOnly': True
138134
}]
139135

140-
# overwrite image so slugrunner image is used in the container
141-
image = settings.SLUGRUNNER_IMAGE
142-
# slugrunner pull policy
143-
kwargs['image_pull_policy'] = settings.SLUG_RUNNER_IMAGE_PULL_POLICY
144-
145136
# create the base container
146137
container = {}
147138

0 commit comments

Comments
 (0)