-
Notifications
You must be signed in to change notification settings - Fork 127
/
pod_scheduling.go
157 lines (131 loc) · 5.21 KB
/
pod_scheduling.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
Copyright 2017 The go-marathon Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package marathon
// PodBackoff describes the backoff for re-run attempts of a pod
type PodBackoff struct {
Backoff *float64 `json:"backoff,omitempty"`
BackoffFactor *float64 `json:"backoffFactor,omitempty"`
MaxLaunchDelay *float64 `json:"maxLaunchDelay,omitempty"`
}
// PodUpgrade describes the policy for upgrading a pod in-place
type PodUpgrade struct {
MinimumHealthCapacity *float64 `json:"minimumHealthCapacity,omitempty"`
MaximumOverCapacity *float64 `json:"maximumOverCapacity,omitempty"`
}
// PodPlacement supports constraining which hosts a pod is placed on
type PodPlacement struct {
Constraints *[]Constraint `json:"constraints"`
AcceptedResourceRoles []string `json:"acceptedResourceRoles,omitempty"`
}
// PodSchedulingPolicy is the overarching pod scheduling policy
type PodSchedulingPolicy struct {
Backoff *PodBackoff `json:"backoff,omitempty"`
Upgrade *PodUpgrade `json:"upgrade,omitempty"`
Placement *PodPlacement `json:"placement,omitempty"`
UnreachableStrategy *UnreachableStrategy `json:"unreachableStrategy,omitempty"`
KillSelection string `json:"killSelection,omitempty"`
}
// Constraint describes the constraint for pod placement
type Constraint struct {
FieldName string `json:"fieldName"`
Operator string `json:"operator"`
Value string `json:"value,omitempty"`
}
// NewPodPlacement creates an empty PodPlacement
func NewPodPlacement() *PodPlacement {
return &PodPlacement{
Constraints: &[]Constraint{},
AcceptedResourceRoles: []string{},
}
}
// AddConstraint adds a new constraint
// constraints: the constraint definition, one constraint per array element
func (p *PodPlacement) AddConstraint(constraint Constraint) *PodPlacement {
c := *p.Constraints
c = append(c, constraint)
p.Constraints = &c
return p
}
// NewPodSchedulingPolicy creates an empty PodSchedulingPolicy
func NewPodSchedulingPolicy() *PodSchedulingPolicy {
return &PodSchedulingPolicy{
Placement: NewPodPlacement(),
}
}
// NewPodBackoff creates an empty PodBackoff
func NewPodBackoff() *PodBackoff {
return &PodBackoff{}
}
// NewPodUpgrade creates a new PodUpgrade
func NewPodUpgrade() *PodUpgrade {
return &PodUpgrade{}
}
// SetBackoff sets the base backoff interval for failed pod launches, in seconds
func (p *PodBackoff) SetBackoff(backoffSeconds float64) *PodBackoff {
p.Backoff = &backoffSeconds
return p
}
// SetBackoffFactor sets the backoff interval growth factor for failed pod launches
func (p *PodBackoff) SetBackoffFactor(backoffFactor float64) *PodBackoff {
p.BackoffFactor = &backoffFactor
return p
}
// SetMaxLaunchDelay sets the maximum backoff interval for failed pod launches, in seconds
func (p *PodBackoff) SetMaxLaunchDelay(maxLaunchDelaySeconds float64) *PodBackoff {
p.MaxLaunchDelay = &maxLaunchDelaySeconds
return p
}
// SetMinimumHealthCapacity sets the minimum amount of pod instances for healthy operation, expressed as a fraction of instance count
func (p *PodUpgrade) SetMinimumHealthCapacity(capacity float64) *PodUpgrade {
p.MinimumHealthCapacity = &capacity
return p
}
// SetMaximumOverCapacity sets the maximum amount of pod instances above the instance count, expressed as a fraction of instance count
func (p *PodUpgrade) SetMaximumOverCapacity(capacity float64) *PodUpgrade {
p.MaximumOverCapacity = &capacity
return p
}
// SetBackoff sets the pod's backoff settings
func (p *PodSchedulingPolicy) SetBackoff(backoff *PodBackoff) *PodSchedulingPolicy {
p.Backoff = backoff
return p
}
// SetUpgrade sets the pod's upgrade settings
func (p *PodSchedulingPolicy) SetUpgrade(upgrade *PodUpgrade) *PodSchedulingPolicy {
p.Upgrade = upgrade
return p
}
// SetPlacement sets the pod's placement settings
func (p *PodSchedulingPolicy) SetPlacement(placement *PodPlacement) *PodSchedulingPolicy {
p.Placement = placement
return p
}
// SetKillSelection sets the pod's kill selection criteria when terminating pod instances
func (p *PodSchedulingPolicy) SetKillSelection(killSelection string) *PodSchedulingPolicy {
p.KillSelection = killSelection
return p
}
// SetUnreachableStrategy sets the pod's unreachable strategy for lost instances
func (p *PodSchedulingPolicy) SetUnreachableStrategy(strategy EnabledUnreachableStrategy) *PodSchedulingPolicy {
p.UnreachableStrategy = &UnreachableStrategy{
EnabledUnreachableStrategy: strategy,
}
return p
}
// SetUnreachableStrategyDisabled disables the pod's unreachable strategy
func (p *PodSchedulingPolicy) SetUnreachableStrategyDisabled() *PodSchedulingPolicy {
p.UnreachableStrategy = &UnreachableStrategy{
AbsenceReason: UnreachableStrategyAbsenceReasonDisabled,
}
return p
}