VictoriaMetrics/lib/promscrape/discovery/kubernetes/api.go
Nikolay 9b2246c29b
vmagent kubernetes watch stream discovery. (#1082)
* 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>
2021-02-26 16:46:13 +02:00

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
}