Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(kubernetes) Support Tolerations in Pod spec #1430

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,6 +32,7 @@ public class KubernetesSettings {
Map<String, String> podAnnotations = new HashMap<>();
Map<String, String> podLabels = new HashMap<>();
Map<String, String> serviceLabels = new HashMap<>();
List<Toleration> tolerations = new ArrayList<>();
List<ConfigSource> volumes = new ArrayList<>();
String serviceAccountName = null;
String serviceType = "ClusterIP";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -675,13 +675,19 @@ default String getAffinity(AccountDeploymentDetails<KubernetesAccount> details)
}
}

default String getTolerations(AccountDeploymentDetails<KubernetesAccount> details) {
List<Toleration> toleration =
details
.getDeploymentConfiguration()
.getDeploymentEnvironment()
.getTolerations()
.getOrDefault(getService().getServiceName(), new ArrayList<>());
default String getTolerations(
ServiceSettings settings, AccountDeploymentDetails<KubernetesAccount> details) {

List<Toleration> toleration = settings.getKubernetes().getTolerations();

if (toleration.isEmpty()) {
toleration =
details
.getDeploymentConfiguration()
.getDeploymentEnvironment()
.getTolerations()
.getOrDefault(getService().getServiceName(), new ArrayList<>());
}

if (toleration.isEmpty()) {
toleration =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"}]')
}
}