From b05e24f4e3e702855f105f9b0887e53a92b341bd Mon Sep 17 00:00:00 2001 From: Denys Savchenko <56398430+dsavchenko@users.noreply.github.com> Date: Thu, 29 Aug 2024 10:17:57 +0200 Subject: [PATCH] kaniko pod antiaffinity (#198) --- nb2workflow/deploy.py | 10 ++++++++-- nb2workflow/templates/buildjob.yaml.jinja | 13 +++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/nb2workflow/deploy.py b/nb2workflow/deploy.py index ff82683..b9140a0 100644 --- a/nb2workflow/deploy.py +++ b/nb2workflow/deploy.py @@ -267,7 +267,10 @@ def build_with_kaniko(self, build_timestamp: bool = False, namespace: str = "oda-staging", cleanup: bool = True, - nb2wversion=version(print_it=False)) -> dict: + nb2wversion=version(print_it=False), + kaniko_pod_antiaffinity=True, + dispatcher_app_label='oda-dispatcher', + frontend_app_label='frontend') -> dict: #secret should be created beforehand https://github.com/GoogleContainerTools/kaniko#pushing-to-docker-hub @@ -291,7 +294,10 @@ def build_with_kaniko(self, suffix = suffix, namespace = namespace, no_push = no_push, - image = image + image = image, + kaniko_pod_antiaffinity = kaniko_pod_antiaffinity, + dispatcher_app_label = dispatcher_app_label, + frontend_app_label = frontend_app_label )) tmpl = jenv.get_template('dockerfile_cm.yaml.jinja') diff --git a/nb2workflow/templates/buildjob.yaml.jinja b/nb2workflow/templates/buildjob.yaml.jinja index 3294f88..06dae62 100644 --- a/nb2workflow/templates/buildjob.yaml.jinja +++ b/nb2workflow/templates/buildjob.yaml.jinja @@ -8,6 +8,19 @@ spec: ttlSecondsAfterFinished: 86400 template: spec: + {% if kaniko_pod_antiaffinity %} + affinity: + podAntiAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + - labelSelector: + matchExpressions: + - key: app.kubernetes.io/name + operator: In + values: + - {{ dispatcher_app_label }} + - {{ frontend_app_label }} + topologyKey: "kubernetes.io/hostname" + {% endif %} containers: - name: kaniko-build image: gcr.io/kaniko-project/executor:v1.22.0