-
Notifications
You must be signed in to change notification settings - Fork 298
/
update_settings.go
54 lines (46 loc) · 1.15 KB
/
update_settings.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
package model
import "time"
const (
DefaultMaxParallelUpdates = 3
DefaultK8sUpsertTimeout = 30 * time.Second
)
type UpdateSettings struct {
maxParallelUpdates int // max number of updates to run concurrently
k8sUpsertTimeout time.Duration // timeout for k8s upsert operations
}
func (us UpdateSettings) MaxParallelUpdates() int {
// Min. value is 1
if us.maxParallelUpdates < 1 {
return 1
}
return us.maxParallelUpdates
}
func (us UpdateSettings) WithMaxParallelUpdates(n int) UpdateSettings {
// Min. value is 1
if n < 1 {
n = 1
}
us.maxParallelUpdates = n
return us
}
func (us UpdateSettings) K8sUpsertTimeout() time.Duration {
// Min. value is 1s
if us.k8sUpsertTimeout < time.Second {
return time.Second
}
return us.k8sUpsertTimeout
}
func (us UpdateSettings) WithK8sUpsertTimeout(timeout time.Duration) UpdateSettings {
// Min. value is 1s
if us.k8sUpsertTimeout < time.Second {
timeout = time.Second
}
us.k8sUpsertTimeout = timeout
return us
}
func DefaultUpdateSettings() UpdateSettings {
return UpdateSettings{
maxParallelUpdates: DefaultMaxParallelUpdates,
k8sUpsertTimeout: DefaultK8sUpsertTimeout,
}
}