forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
interfaces.go
69 lines (59 loc) · 1.71 KB
/
interfaces.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
package strategy
import (
"strconv"
"strings"
corev1 "k8s.io/api/core/v1"
)
// DeploymentStrategy knows how to make a deployment active.
type DeploymentStrategy interface {
// Deploy transitions an old deployment to a new one.
Deploy(from *corev1.ReplicationController, to *corev1.ReplicationController, desiredReplicas int) error
}
// UpdateAcceptor is given a chance to accept or reject the new controller
// during a deployment each time the controller is scaled up.
//
// After the successful scale-up of the controller, the controller is given to
// the UpdateAcceptor. If the UpdateAcceptor rejects the controller, the
// deployment is stopped with an error.
//
// DEPRECATED: Acceptance checking has been incorporated into the rolling
// strategy, but we still need this around to support Recreate.
type UpdateAcceptor interface {
// Accept returns nil if the controller is okay, otherwise returns an error.
Accept(*corev1.ReplicationController) error
}
type errConditionReached struct {
msg string
}
func NewConditionReachedErr(msg string) error {
return &errConditionReached{msg: msg}
}
func (e *errConditionReached) Error() string {
return e.msg
}
func IsConditionReached(err error) bool {
value, ok := err.(*errConditionReached)
return ok && value != nil
}
func PercentageBetween(until string, min, max int) bool {
if !strings.HasSuffix(until, "%") {
return false
}
until = until[:len(until)-1]
i, err := strconv.Atoi(until)
if err != nil {
return false
}
return i >= min && i <= max
}
func Percentage(until string) (int, bool) {
if !strings.HasSuffix(until, "%") {
return 0, false
}
until = until[:len(until)-1]
i, err := strconv.Atoi(until)
if err != nil {
return 0, false
}
return i, true
}