diff --git a/halyard-deploy/src/main/java/com/netflix/spinnaker/halyard/deploy/spinnaker/v1/service/KubernetesSettings.java b/halyard-deploy/src/main/java/com/netflix/spinnaker/halyard/deploy/spinnaker/v1/service/KubernetesSettings.java index 253dec8bdc..e531787866 100644 --- a/halyard-deploy/src/main/java/com/netflix/spinnaker/halyard/deploy/spinnaker/v1/service/KubernetesSettings.java +++ b/halyard-deploy/src/main/java/com/netflix/spinnaker/halyard/deploy/spinnaker/v1/service/KubernetesSettings.java @@ -16,6 +16,7 @@ package com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service; +import com.netflix.spinnaker.halyard.config.model.v1.node.Toleration; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -31,6 +32,7 @@ public class KubernetesSettings { Map podAnnotations = new HashMap<>(); Map podLabels = new HashMap<>(); Map serviceLabels = new HashMap<>(); + List tolerations = new ArrayList<>(); List volumes = new ArrayList<>(); String serviceAccountName = null; String serviceType = "ClusterIP"; diff --git a/halyard-deploy/src/main/java/com/netflix/spinnaker/halyard/deploy/spinnaker/v1/service/distributed/kubernetes/v2/KubernetesV2Service.java b/halyard-deploy/src/main/java/com/netflix/spinnaker/halyard/deploy/spinnaker/v1/service/distributed/kubernetes/v2/KubernetesV2Service.java index 78ac1018dd..43d89f0f6b 100644 --- a/halyard-deploy/src/main/java/com/netflix/spinnaker/halyard/deploy/spinnaker/v1/service/distributed/kubernetes/v2/KubernetesV2Service.java +++ b/halyard-deploy/src/main/java/com/netflix/spinnaker/halyard/deploy/spinnaker/v1/service/distributed/kubernetes/v2/KubernetesV2Service.java @@ -254,7 +254,7 @@ default String getPodSpecYaml( .addBinding("terminationGracePeriodSeconds", terminationGracePeriodSeconds()) .addBinding("nodeSelector", settings.getKubernetes().getNodeSelector()) .addBinding("affinity", getAffinity(details)) - .addBinding("tolerations", getTolerations(details)) + .addBinding("tolerations", getTolerations(settings, details)) .addBinding( "volumes", combineVolumes(configSources, settings.getKubernetes(), sidecarConfigs)) .addBinding("securityContext", settings.getKubernetes().getSecurityContext()) @@ -675,13 +675,19 @@ default String getAffinity(AccountDeploymentDetails details) } } - default String getTolerations(AccountDeploymentDetails details) { - List toleration = - details - .getDeploymentConfiguration() - .getDeploymentEnvironment() - .getTolerations() - .getOrDefault(getService().getServiceName(), new ArrayList<>()); + default String getTolerations( + ServiceSettings settings, AccountDeploymentDetails details) { + + List toleration = settings.getKubernetes().getTolerations(); + + if (toleration.isEmpty()) { + toleration = + details + .getDeploymentConfiguration() + .getDeploymentEnvironment() + .getTolerations() + .getOrDefault(getService().getServiceName(), new ArrayList<>()); + } if (toleration.isEmpty()) { toleration = diff --git a/halyard-deploy/src/test/groovy/com/netflix/spinnaker/halyard/deploy/spinnaker/v1/service/distributed/kubernetes/v2/KubernetesV2ServiceTest.groovy b/halyard-deploy/src/test/groovy/com/netflix/spinnaker/halyard/deploy/spinnaker/v1/service/distributed/kubernetes/v2/KubernetesV2ServiceTest.groovy index 4b1ee52e46..07dccf0a8d 100644 --- a/halyard-deploy/src/test/groovy/com/netflix/spinnaker/halyard/deploy/spinnaker/v1/service/distributed/kubernetes/v2/KubernetesV2ServiceTest.groovy +++ b/halyard-deploy/src/test/groovy/com/netflix/spinnaker/halyard/deploy/spinnaker/v1/service/distributed/kubernetes/v2/KubernetesV2ServiceTest.groovy @@ -394,4 +394,22 @@ class KubernetesV2ServiceTest extends Specification { then: yaml.contains('"tolerations": [{"key":"test","operator":"Equal","value":"a","effect":"NoSchedule"}]') } + def "Can we set PodSpec.tolerations?"() { + setup: + def toleration = new Toleration( + key: "test", + value: "my-node", + effect: "NoSchedule", + operator: Toleration.Operator.Equal + ) + serviceSettings.getKubernetes().tolerations = new ArrayList<>() + serviceSettings.getKubernetes().tolerations.add(toleration) + def executor = Mock(KubernetesV2Executor) + + when: + String yaml = testService.getPodSpecYaml(executor, details, config) + + then: + yaml.contains('"tolerations": [{"key":"test","operator":"Equal","value":"my-node","effect":"NoSchedule"}]') + } }