mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
9b2246c29b
* started work on sd for k8s * continue work on watch sd * fixes * continue work * continue work on sd k8s * disable gzip * fixes typos * log errror * minor fix Co-authored-by: Aliaksandr Valialkin <valyala@gmail.com>
42 lines
1 KiB
Go
42 lines
1 KiB
Go
package kubernetes
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
|
|
)
|
|
|
|
// apiConfig contains config for API server
|
|
type apiConfig struct {
|
|
setName string
|
|
namespaces []string
|
|
selectors []Selector
|
|
wc *watchClient
|
|
targetChan chan SyncEvent
|
|
watchOnce sync.Once
|
|
}
|
|
|
|
var configMap = discoveryutils.NewConfigMap()
|
|
|
|
func getAPIConfig(watchCfg *WatchConfig, setName string, sdc *SDConfig, baseDir string) (*apiConfig, error) {
|
|
v, err := configMap.Get(sdc, func() (interface{}, error) { return newAPIConfig(watchCfg, setName, sdc, baseDir) })
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return v.(*apiConfig), nil
|
|
}
|
|
|
|
func newAPIConfig(watchCfg *WatchConfig, setName string, sdc *SDConfig, baseDir string) (*apiConfig, error) {
|
|
wc, err := newWatchClient(watchCfg.WG, sdc, baseDir)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
cfg := &apiConfig{
|
|
setName: setName,
|
|
targetChan: watchCfg.WatchChan,
|
|
wc: wc,
|
|
namespaces: sdc.Namespaces.Names,
|
|
selectors: sdc.Selectors,
|
|
}
|
|
return cfg, nil
|
|
}
|