Просмотр исходного кода

use custom cloud provider + no watchers for etl readonly mode

Ajay Tripathy 4 лет назад
Родитель
Сommit
cfbd8045e6
4 измененных файлов с 34 добавлено и 22 удалено
  1. 5 1
      pkg/cloud/provider.go
  2. 23 20
      pkg/clustercache/clustercache.go
  3. 0 1
      pkg/costmodel/router.go
  4. 6 0
      pkg/env/costmodelenv.go

+ 5 - 1
pkg/cloud/provider.go

@@ -423,7 +423,11 @@ func ShareTenancyCosts(p Provider) bool {
 func NewProvider(cache clustercache.ClusterCache, apiKey string, config *config.ConfigFileManager) (Provider, error) {
 	nodes := cache.GetAllNodes()
 	if len(nodes) == 0 {
-		return nil, fmt.Errorf("Could not locate any nodes for cluster.")
+		log.Infof("Could not locate any nodes for cluster.") // valid in ETL readonly mode
+		return &CustomProvider{
+			Clientset: cache,
+			Config:    NewProviderConfig(config, "default.json"),
+		}, nil
 	}
 
 	cp := getClusterProperties(nodes[0])

+ 23 - 20
pkg/clustercache/clustercache.go

@@ -134,27 +134,30 @@ func NewKubernetesClusterCache(client kubernetes.Interface) ClusterCache {
 	}
 
 	// Wait for each caching watcher to initialize
-	var wg sync.WaitGroup
-	wg.Add(16)
-
 	cancel := make(chan struct{})
-
-	go initializeCache(kcc.namespaceWatch, &wg, cancel)
-	go initializeCache(kcc.nodeWatch, &wg, cancel)
-	go initializeCache(kcc.podWatch, &wg, cancel)
-	go initializeCache(kcc.kubecostConfigMapWatch, &wg, cancel)
-	go initializeCache(kcc.serviceWatch, &wg, cancel)
-	go initializeCache(kcc.daemonsetsWatch, &wg, cancel)
-	go initializeCache(kcc.deploymentsWatch, &wg, cancel)
-	go initializeCache(kcc.statefulsetWatch, &wg, cancel)
-	go initializeCache(kcc.replicasetWatch, &wg, cancel)
-	go initializeCache(kcc.pvWatch, &wg, cancel)
-	go initializeCache(kcc.pvcWatch, &wg, cancel)
-	go initializeCache(kcc.storageClassWatch, &wg, cancel)
-	go initializeCache(kcc.jobsWatch, &wg, cancel)
-	go initializeCache(kcc.hpaWatch, &wg, cancel)
-	go initializeCache(kcc.podWatch, &wg, cancel)
-	go initializeCache(kcc.replicationControllerWatch, &wg, cancel)
+	var wg sync.WaitGroup
+	if env.GetETLReadOnlyMode() {
+		wg.Add(1)
+		go initializeCache(kcc.kubecostConfigMapWatch, &wg, cancel)
+	} else {
+		wg.Add(16)
+		go initializeCache(kcc.kubecostConfigMapWatch, &wg, cancel)
+		go initializeCache(kcc.namespaceWatch, &wg, cancel)
+		go initializeCache(kcc.nodeWatch, &wg, cancel)
+		go initializeCache(kcc.podWatch, &wg, cancel)
+		go initializeCache(kcc.serviceWatch, &wg, cancel)
+		go initializeCache(kcc.daemonsetsWatch, &wg, cancel)
+		go initializeCache(kcc.deploymentsWatch, &wg, cancel)
+		go initializeCache(kcc.statefulsetWatch, &wg, cancel)
+		go initializeCache(kcc.replicasetWatch, &wg, cancel)
+		go initializeCache(kcc.pvWatch, &wg, cancel)
+		go initializeCache(kcc.pvcWatch, &wg, cancel)
+		go initializeCache(kcc.storageClassWatch, &wg, cancel)
+		go initializeCache(kcc.jobsWatch, &wg, cancel)
+		go initializeCache(kcc.hpaWatch, &wg, cancel)
+		go initializeCache(kcc.podWatch, &wg, cancel)
+		go initializeCache(kcc.replicationControllerWatch, &wg, cancel)
+	}
 
 	wg.Wait()
 

+ 0 - 1
pkg/costmodel/router.go

@@ -1611,7 +1611,6 @@ func Initialize(additionalConfigWatchers ...*watcher.ConfigMapWatcher) *Accesses
 
 	// Initialize mechanism for subscribing to settings changes
 	a.InitializeSettingsPubSub()
-
 	err = a.CloudProvider.DownloadPricingData()
 	if err != nil {
 		log.Infof("Failed to download pricing data: " + err.Error())

+ 6 - 0
pkg/env/costmodelenv.go

@@ -84,8 +84,14 @@ const (
 	PrometheusRetryOnRateLimitDefaultWaitEnvVar = "PROMETHEUS_RETRY_ON_RATE_LIMIT_DEFAULT_WAIT"
 
 	IngestPodUIDEnvVar = "INGEST_POD_UID"
+
+	ETLReadOnlyMode = "ETL_READ_ONLY"
 )
 
+func GetETLReadOnlyMode() bool {
+	return GetBool(ETLReadOnlyMode, false)
+}
+
 // GetKubecostConfigBucket returns a file location for a mounted bucket configuration which is used to store
 // a subset of kubecost configurations that require sharing via remote storage.
 func GetKubecostConfigBucket() string {