-
Notifications
You must be signed in to change notification settings - Fork 90
/
metaserver.go
192 lines (149 loc) · 7.17 KB
/
metaserver.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/*
Copyright 2022 The Katalyst Authors.
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 metaserver
import (
"time"
"golang.org/x/time/rate"
cliflag "k8s.io/component-base/cli/flag"
"github.com/kubewharf/katalyst-core/pkg/config/agent/metaserver"
)
const (
defaultCheckpointManagerDir = "/var/lib/katalyst/metaserver/checkpoints"
defaultEnableMetricsFetcher = true
defaultEnableCNCFetcher = true
)
const (
defaultConfigCacheTTL = 15 * time.Second
defaultConfigDisableDynamic = false
defaultConfigSkipFailedInitialization = true
defaultConfigCheckpointGraceTime = 2 * time.Hour
)
const (
defaultServiceProfileSkipCorruptionError = true
defaultServiceProfileCacheTTL = 1 * time.Minute
)
const (
defaultKubeletPodCacheSyncPeriod = 30 * time.Second
defaultKubeletPodCacheSyncMaxRate = 5
defaultKubeletPodCacheSyncBurstBulk = 1
defaultRuntimePodCacheSyncPeriod = 30 * time.Second
)
const defaultCustomNodeResourceCacheTTL = 15 * time.Second
const defaultCustomNodeConfigCacheTTL = 15 * time.Second
// MetaServerOptions holds all the configurations for metaserver.
// we will not try to separate this structure into several individual
// structures since it will not be used directly by other components; instead,
// we will only separate them with blanks in a single structure.
// todo separate this option-structure into individual structures
type MetaServerOptions struct {
// generic configurations for metaserver
CheckpointManagerDir string
EnableMetricsFetcher bool
EnableCNCFetcher bool
// configurations for kcc
ConfigCacheTTL time.Duration
ConfigDisableDynamic bool
ConfigSkipFailedInitialization bool
ConfigCheckpointGraceTime time.Duration
// configurations for spd
ServiceProfileSkipCorruptionError bool
ServiceProfileCacheTTL time.Duration
// configurations for pod-cache
KubeletPodCacheSyncPeriod time.Duration
KubeletPodCacheSyncMaxRate int
KubeletPodCacheSyncBurstBulk int
RuntimePodCacheSyncPeriod time.Duration
// configurations for cnr
CNRCacheTTL time.Duration
// configurations for cnc
CustomNodeConfigCacheTTL time.Duration
// configurations for metric-fetcher
*MetricFetcherOptions
}
func NewMetaServerOptions() *MetaServerOptions {
return &MetaServerOptions{
CheckpointManagerDir: defaultCheckpointManagerDir,
EnableMetricsFetcher: defaultEnableMetricsFetcher,
EnableCNCFetcher: defaultEnableCNCFetcher,
ConfigCacheTTL: defaultConfigCacheTTL,
ConfigDisableDynamic: defaultConfigDisableDynamic,
ConfigSkipFailedInitialization: defaultConfigSkipFailedInitialization,
ConfigCheckpointGraceTime: defaultConfigCheckpointGraceTime,
ServiceProfileSkipCorruptionError: defaultServiceProfileSkipCorruptionError,
ServiceProfileCacheTTL: defaultServiceProfileCacheTTL,
KubeletPodCacheSyncPeriod: defaultKubeletPodCacheSyncPeriod,
KubeletPodCacheSyncMaxRate: defaultKubeletPodCacheSyncMaxRate,
KubeletPodCacheSyncBurstBulk: defaultKubeletPodCacheSyncBurstBulk,
RuntimePodCacheSyncPeriod: defaultRuntimePodCacheSyncPeriod,
CNRCacheTTL: defaultCustomNodeResourceCacheTTL,
CustomNodeConfigCacheTTL: defaultCustomNodeConfigCacheTTL,
MetricFetcherOptions: NewMetricFetcherOptions(),
}
}
// AddFlags adds flags to the specified FlagSet.
func (o *MetaServerOptions) AddFlags(fss *cliflag.NamedFlagSets) {
fs := fss.FlagSet("meta-server")
fs.StringVar(&o.CheckpointManagerDir, "checkpoint-manager-directory", o.CheckpointManagerDir,
"The checkpoint manager directory")
fs.BoolVar(&o.EnableMetricsFetcher, "enable-metrics-fetcher", o.EnableMetricsFetcher,
"Whether to enable metrics fetcher")
fs.BoolVar(&o.EnableCNCFetcher, "enable-cnc-fetcher", o.EnableCNCFetcher,
"Whether to enable cnc fetcher")
fs.DurationVar(&o.ConfigCacheTTL, "config-cache-ttl", o.ConfigCacheTTL,
"The ttl of katalyst custom config loader cache remote config")
fs.BoolVar(&o.ConfigDisableDynamic, "config-disable-dynamic", o.ConfigDisableDynamic,
"Whether disable dynamic configuration")
fs.BoolVar(&o.ConfigSkipFailedInitialization, "config-skip-failed-initialization", o.ConfigSkipFailedInitialization,
"Whether skip if updating dynamic configuration fails")
fs.DurationVar(&o.ConfigCheckpointGraceTime, "config-checkpoint-grace-time", o.ConfigCheckpointGraceTime,
"The grace time of meta server config checkpoint")
fs.BoolVar(&o.ServiceProfileSkipCorruptionError, "service-profile-skip-corruption-error", o.ServiceProfileSkipCorruptionError,
"Whether to skip corruption error when loading spd checkpoint")
fs.DurationVar(&o.ServiceProfileCacheTTL, "service-profile-cache-ttl", o.ServiceProfileCacheTTL,
"The ttl of service profile manager cache remote spd")
fs.DurationVar(&o.KubeletPodCacheSyncPeriod, "kubelet-pod-cache-sync-period", o.KubeletPodCacheSyncPeriod,
"The period of meta server to sync pod from kubelet 10255 port")
fs.IntVar(&o.KubeletPodCacheSyncMaxRate, "kubelet-pod-cache-sync-max-rate", o.KubeletPodCacheSyncMaxRate,
"The max rate for kubelet pod sync")
fs.IntVar(&o.KubeletPodCacheSyncBurstBulk, "kubelet-pod-cache-sync-burst-bulk", o.KubeletPodCacheSyncBurstBulk,
"The burst bulk for kubelet pod sync")
fs.DurationVar(&o.RuntimePodCacheSyncPeriod, "runtime-pod-cache-sync-period", o.RuntimePodCacheSyncPeriod,
"The period of meta server to sync pod from cri")
fs.DurationVar(&o.CNRCacheTTL, "cnr-cache-ttl", o.CNRCacheTTL,
"The sync period of cnr fetcher to sync remote to local")
fs.DurationVar(&o.CustomNodeConfigCacheTTL, "custom-node-config-cache-ttl", o.CustomNodeConfigCacheTTL,
"The ttl of custom node config fetcher cache remote cnc")
o.MetricFetcherOptions.AddFlags(fss)
}
// ApplyTo fills up config with options
func (o *MetaServerOptions) ApplyTo(c *metaserver.MetaServerConfiguration) error {
c.CheckpointManagerDir = o.CheckpointManagerDir
c.EnableMetricsFetcher = o.EnableMetricsFetcher
c.EnableCNCFetcher = o.EnableCNCFetcher
c.ConfigCacheTTL = o.ConfigCacheTTL
c.ConfigDisableDynamic = o.ConfigDisableDynamic
c.ConfigSkipFailedInitialization = o.ConfigSkipFailedInitialization
c.ConfigCheckpointGraceTime = o.ConfigCheckpointGraceTime
c.ServiceProfileSkipCorruptionError = o.ServiceProfileSkipCorruptionError
c.ServiceProfileCacheTTL = o.ServiceProfileCacheTTL
c.KubeletPodCacheSyncPeriod = o.KubeletPodCacheSyncPeriod
c.KubeletPodCacheSyncMaxRate = rate.Limit(o.KubeletPodCacheSyncMaxRate)
c.KubeletPodCacheSyncBurstBulk = o.KubeletPodCacheSyncBurstBulk
c.RuntimePodCacheSyncPeriod = o.RuntimePodCacheSyncPeriod
c.CNRCacheTTL = o.CNRCacheTTL
c.CustomNodeConfigCacheTTL = o.CustomNodeConfigCacheTTL
if err := o.MetricFetcherOptions.ApplyTo(c.MetricConfiguration); err != nil {
return err
}
return nil
}