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

Merge pull request #1012 from kubecost/bolt/agent-export-options

Add the option to disable cluster info emission
Matt Bolt 4 лет назад
Родитель
Сommit
cea2de44e0
2 измененных файлов с 15 добавлено и 2 удалено
  1. 8 2
      pkg/cmd/agent/agent.go
  2. 7 0
      pkg/env/kubemetricsenv.go

+ 8 - 2
pkg/cmd/agent/agent.go

@@ -177,9 +177,15 @@ func Execute(opts *AgentOpts) error {
 	}
 	}
 
 
 	// ClusterInfo Provider to provide the cluster map with local and remote cluster data
 	// ClusterInfo Provider to provide the cluster map with local and remote cluster data
-	clusterInfoConf := confManager.ConfigFileAt("/var/configs/cluster-info.json")
 	localClusterInfo := costmodel.NewLocalClusterInfoProvider(k8sClient, cloudProvider)
 	localClusterInfo := costmodel.NewLocalClusterInfoProvider(k8sClient, cloudProvider)
-	clusterInfoProvider := costmodel.NewClusterInfoWriteOnRequest(localClusterInfo, clusterInfoConf)
+
+	var clusterInfoProvider clusters.ClusterInfoProvider
+	if env.IsExportClusterInfoEnabled() {
+		clusterInfoConf := confManager.ConfigFileAt("/var/configs/cluster-info.json")
+		clusterInfoProvider = costmodel.NewClusterInfoWriteOnRequest(localClusterInfo, clusterInfoConf)
+	} else {
+		clusterInfoProvider = localClusterInfo
+	}
 
 
 	// Initialize ClusterMap for maintaining ClusterInfo by ClusterID
 	// Initialize ClusterMap for maintaining ClusterInfo by ClusterID
 	clusterMap := clusters.NewClusterMap(promCli, clusterInfoProvider, 5*time.Minute)
 	clusterMap := clusters.NewClusterMap(promCli, clusterInfoProvider, 5*time.Minute)

+ 7 - 0
pkg/env/kubemetricsenv.go

@@ -4,6 +4,7 @@ const (
 	KubecostMetricsPodEnabledEnvVar = "KUBECOST_METRICS_POD_ENABLED"
 	KubecostMetricsPodEnabledEnvVar = "KUBECOST_METRICS_POD_ENABLED"
 	KubecostMetricsPodPortEnvVar    = "KUBECOST_METRICS_PORT"
 	KubecostMetricsPodPortEnvVar    = "KUBECOST_METRICS_PORT"
 	ExportClusterCacheEnabledEnvVar = "EXPORT_CLUSTER_CACHE_ENABLED"
 	ExportClusterCacheEnabledEnvVar = "EXPORT_CLUSTER_CACHE_ENABLED"
+	ExportClusterInfoEnabledEnvVar  = "EXPORT_CLUSTER_INFO_ENABLED"
 )
 )
 
 
 func GetKubecostMetricsPort() int {
 func GetKubecostMetricsPort() int {
@@ -20,3 +21,9 @@ func IsKubecostMetricsPodEnabled() bool {
 func IsExportClusterCacheEnabled() bool {
 func IsExportClusterCacheEnabled() bool {
 	return GetBool(ExportClusterCacheEnabledEnvVar, false)
 	return GetBool(ExportClusterCacheEnabledEnvVar, false)
 }
 }
+
+// IsExportClusterInfoEnabled is set to true if the metrics pod should export its own cluster info
+// data to a target file location
+func IsExportClusterInfoEnabled() bool {
+	return GetBool(ExportClusterInfoEnabledEnvVar, false)
+}