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

Merge pull request #1779 from opencost/niko/var-config-const

Make "/var/configs" a const and create new env helper called GetCostAnalyzerVolumeMountPath
Niko Kovacevic 3 лет назад
Родитель
Сommit
7bb5343caa

+ 1 - 1
pkg/cmd/agent/agent.go

@@ -181,7 +181,7 @@ func Execute(opts *AgentOpts) error {
 
 
 	clusterCache.SetConfigMapUpdateFunc(watchConfigFunc)
 	clusterCache.SetConfigMapUpdateFunc(watchConfigFunc)
 
 
-	configPrefix := env.GetConfigPathWithDefault("/var/configs/")
+	configPrefix := env.GetConfigPathWithDefault(env.DefaultConfigMountPath)
 
 
 	// Initialize cluster exporting if it's enabled
 	// Initialize cluster exporting if it's enabled
 	if env.IsExportClusterCacheEnabled() {
 	if env.IsExportClusterCacheEnabled() {

+ 1 - 1
pkg/costmodel/router.go

@@ -1363,7 +1363,7 @@ func (a *Accesses) AddServiceKey(w http.ResponseWriter, r *http.Request, ps http
 
 
 	key := r.PostForm.Get("key")
 	key := r.PostForm.Get("key")
 	k := []byte(key)
 	k := []byte(key)
-	err := os.WriteFile(path.Join(env.GetConfigPathWithDefault("/var/configs/"), "key.json"), k, 0644)
+	err := os.WriteFile(path.Join(env.GetConfigPathWithDefault(env.DefaultConfigMountPath), "key.json"), k, 0644)
 	if err != nil {
 	if err != nil {
 		fmt.Fprintf(w, "Error writing service key: "+err.Error())
 		fmt.Fprintf(w, "Error writing service key: "+err.Error())
 	}
 	}

+ 6 - 4
pkg/env/costmodelenv.go

@@ -99,6 +99,8 @@ const (
 	regionOverrideList = "REGION_OVERRIDE_LIST"
 	regionOverrideList = "REGION_OVERRIDE_LIST"
 )
 )
 
 
+const DefaultConfigMountPath = "/var/configs"
+
 var offsetRegex = regexp.MustCompile(`^(\+|-)(\d\d):(\d\d)$`)
 var offsetRegex = regexp.MustCompile(`^(\+|-)(\d\d):(\d\d)$`)
 
 
 func IsETLReadOnlyMode() bool {
 func IsETLReadOnlyMode() bool {
@@ -314,10 +316,10 @@ func GetCSVPath() string {
 	return Get(CSVPathEnvVar, "")
 	return Get(CSVPathEnvVar, "")
 }
 }
 
 
-// GetConfigPath returns the environment variable value for ConfigPathEnvVar which represents the cost
-// model configuration path
-func GetConfigPath() string {
-	return Get(ConfigPathEnvVar, "")
+// GetCostAnalyzerVolumeMountPath is an alias of GetConfigPath, which returns the mount path for the
+// Cost Analyzer volume, which stores configs, persistent data, etc.
+func GetCostAnalyzerVolumeMountPath() string {
+	return GetConfigPathWithDefault(DefaultConfigMountPath)
 }
 }
 
 
 // GetConfigPath returns the environment variable value for ConfigPathEnvVar which represents the cost
 // GetConfigPath returns the environment variable value for ConfigPathEnvVar which represents the cost

+ 1 - 1
pkg/metrics/metricsconfig.go

@@ -13,7 +13,7 @@ import (
 
 
 var (
 var (
 	metricsConfigLock = new(sync.Mutex)
 	metricsConfigLock = new(sync.Mutex)
-	metricsFilePath   = path.Join(env.GetConfigPathWithDefault("/var/configs/"), "metrics.json")
+	metricsFilePath   = path.Join(env.GetCostAnalyzerVolumeMountPath(), "metrics.json")
 )
 )
 
 
 type MetricsConfig struct {
 type MetricsConfig struct {

+ 1 - 1
pkg/services/clusterservice.go

@@ -15,7 +15,7 @@ func NewClusterManagerService() HTTPService {
 
 
 // newClusterManager creates a new cluster manager instance for use in the service
 // newClusterManager creates a new cluster manager instance for use in the service
 func newClusterManager() *clusters.ClusterManager {
 func newClusterManager() *clusters.ClusterManager {
-	clustersConfigFile := path.Join(env.GetConfigPathWithDefault("/var/configs/"), "clusters/default-clusters.yaml")
+	clustersConfigFile := path.Join(env.GetCostAnalyzerVolumeMountPath(), "clusters/default-clusters.yaml")
 
 
 	// Return a memory-backed cluster manager populated by configmap
 	// Return a memory-backed cluster manager populated by configmap
 	return clusters.NewConfiguredClusterManager(clusters.NewMapDBClusterStorage(), clustersConfigFile)
 	return clusters.NewConfiguredClusterManager(clusters.NewMapDBClusterStorage(), clustersConfigFile)