Skip to content

Commit

Permalink
Node tolerations
Browse files Browse the repository at this point in the history
  • Loading branch information
henrod committed Jun 14, 2017
1 parent 4a9a598 commit 57b28e6
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 16 deletions.
3 changes: 3 additions & 0 deletions controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,9 @@ func createServiceAndPod(logger logrus.FieldLogger, mr *models.MixedMetricsRepor
if configYAML.NodeAffinity != "" {
pod.SetAffinity(configYAML.NodeAffinity)
}
if configYAML.NodeToleration != "" {
pod.SetToleration(configYAML.NodeToleration)
}
var kubePod *v1.Pod
err = mr.WithSegment(models.SegmentPod, func() error {
kubePod, err = pod.Create(clientset)
Expand Down
2 changes: 1 addition & 1 deletion helm/charts/maestro-main/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: maestro-main
home: https://github.com/topfreegames/maestro
description: Maestro api and worker
version: 2.8.0
version: 2.8.2
maintainers:
- name: TFGCo
email: backend@tfgco.com
2 changes: 1 addition & 1 deletion helm/charts/maestro/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: maestro
home: https://github.com/topfreegames/maestro
description: Maestro
version: 0.1.17
version: 0.1.19
maintainers:
- name: TFGCo
email: backend@tfgco.com
2 changes: 1 addition & 1 deletion helm/charts/maestro/requirements.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ dependencies:
version: 0.1.0
repository: http://helm.tfgco.com
- name: maestro-main
version: 2.8.0
version: 2.8.2
repository: http://helm.tfgco.com
21 changes: 13 additions & 8 deletions models/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,22 @@ metadata:
app: {{.Name}}
spec:
terminationGracePeriodSeconds: {{.ShutdownTimeout}}
{{- if ne .NodeToleration ""}}
tolerations:
- key: "game"
- key: "dedicated"
operator: "Equal"
value: {{.Game}}
value: {{.NodeToleration}}
effect: "NoSchedule"
{{- end}}
{{- if ne .NodeAffinity ""}}
affinity:
nodeAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 1
preference:
matchExpressions:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: {{.NodeAffinity}}
operator: In
values:
- "true"
values: ["true"]
{{- end}}
containers:
- name: {{.Name}}
Expand Down Expand Up @@ -84,6 +84,7 @@ type Pod struct {
ResourcesRequestsMemory string
ShutdownTimeout int
NodeAffinity string
NodeToleration string
}

// NewPod is the pod constructor
Expand Down Expand Up @@ -116,6 +117,10 @@ func (p *Pod) SetAffinity(affinity string) {
p.NodeAffinity = affinity
}

func (p *Pod) SetToleration(toleration string) {
p.NodeToleration = toleration
}

// Create creates a pod in Kubernetes
func (p *Pod) Create(clientset kubernetes.Interface) (*v1.Pod, error) {
tmpl, err := template.New("create").Parse(podYaml)
Expand Down
9 changes: 5 additions & 4 deletions models/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ var _ = Describe("Pod", func() {
command,
env,
)
pod.SetToleration(game)
podv1, err := pod.Create(clientset)
Expect(err).NotTo(HaveOccurred())

Expand All @@ -135,7 +136,7 @@ var _ = Describe("Pod", func() {
Expect(podv1.ObjectMeta.Labels["app"]).To(Equal(name))
Expect(*podv1.Spec.TerminationGracePeriodSeconds).To(BeEquivalentTo(shutdownTimeout))
Expect(podv1.Spec.Tolerations).To(HaveLen(1))
Expect(podv1.Spec.Tolerations[0].Key).To(Equal("game"))
Expect(podv1.Spec.Tolerations[0].Key).To(Equal("dedicated"))
Expect(podv1.Spec.Tolerations[0].Operator).To(Equal(v1.TolerationOpEqual))
Expect(podv1.Spec.Tolerations[0].Value).To(Equal(game))
Expect(podv1.Spec.Tolerations[0].Effect).To(Equal(v1.TaintEffectNoSchedule))
Expand Down Expand Up @@ -183,9 +184,9 @@ var _ = Describe("Pod", func() {
podv1, err := pod.Create(clientset)
Expect(err).NotTo(HaveOccurred())

Expect(podv1.Spec.Affinity.NodeAffinity.PreferredDuringSchedulingIgnoredDuringExecution[0].Preference.MatchExpressions[0].Key).To(Equal(game))
Expect(podv1.Spec.Affinity.NodeAffinity.PreferredDuringSchedulingIgnoredDuringExecution[0].Preference.MatchExpressions[0].Operator).To(Equal(v1.NodeSelectorOpIn))
Expect(podv1.Spec.Affinity.NodeAffinity.PreferredDuringSchedulingIgnoredDuringExecution[0].Preference.MatchExpressions[0].Values).To(ConsistOf("true"))
Expect(podv1.Spec.Affinity.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms[0].MatchExpressions[0].Key).To(Equal(game))
Expect(podv1.Spec.Affinity.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms[0].MatchExpressions[0].Operator).To(Equal(v1.NodeSelectorOpIn))
Expect(podv1.Spec.Affinity.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms[0].MatchExpressions[0].Values).To(ConsistOf("true"))
})

It("should return error when creating existing pod", func() {
Expand Down
3 changes: 2 additions & 1 deletion models/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ type ConfigYAML struct {
AutoScaling *AutoScaling `yaml:"autoscaling" json:"autoscaling" valid:"required"`
Env []*EnvVar `yaml:"env" json:"env"`
Cmd []string `yaml:"cmd" json:"cmd"`
NodeAffinity string `yaml:"nodeAffinity" json:"nodeAffinity"`
NodeAffinity string `yaml:"affinity" json:"affinity"`
NodeToleration string `yaml:"toleration" json:"toleration"`
}

// NewScheduler is the scheduler constructor
Expand Down

0 comments on commit 57b28e6

Please sign in to comment.