-
Notifications
You must be signed in to change notification settings - Fork 41
/
config.go
78 lines (65 loc) · 1.92 KB
/
config.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
package nodestream
import (
"time"
"github.com/bottlerocket-os/bottlerocket-update-operator/pkg/marker"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
const (
defaultResyncPeriod = time.Minute * 10
)
type Config struct {
// NodeName limits the nodestream to a single Node resource with the
// provided name.
NodeName string
// ResyncPeriod is the time between complete resynchronization of the cached
// resource data.
ResyncPeriod time.Duration
// PlatformVersion, when specified, limits the nodestream to Nodes that are
// labeled with the provided PlatformVersion.
PlatformVersion marker.PlatformVersion
// OperatorVersion, when specified, limits the nodestream to Nodes that are
// labeled with the provided OperatorVersion.
OperatorVersion marker.OperatorVersion
// LabelSelectorExtra is a free-form selector appended to the calculated
// selector.
LabelSelectorExtra string
// FieldSelectorExtra is a free-form selector appended to the calculated
// selector.
FieldSelectorExtra string
}
// TODO: test this func
func (c *Config) selector() func(options *metav1.ListOptions) {
var (
fieldSelector string
labelSelector string
)
// TODO: use k8s.io/apimachinery/pkg/labels for dynamic validated
// construction of selectors.
if c.NodeName != "" {
// limit the streamed updates to the specified node.
fieldSelector = "metadata.name=" + c.NodeName
}
labelSelector = marker.NodeSelectorLabel
if c.LabelSelectorExtra != "" {
if labelSelector != "" {
labelSelector += ","
}
labelSelector += c.LabelSelectorExtra
}
if c.FieldSelectorExtra != "" {
if fieldSelector != "" {
fieldSelector += ","
}
fieldSelector += c.FieldSelectorExtra
}
return func(options *metav1.ListOptions) {
options.LabelSelector = labelSelector
options.FieldSelector = fieldSelector
}
}
func (c *Config) resyncPeriod() time.Duration {
if c.ResyncPeriod == 0 {
return defaultResyncPeriod
}
return c.ResyncPeriod
}