Переглянути джерело

Merge pull request #912 from kubecost/AjayTripathy-configurable-configmapnames

configurable configmapnames
Ajay Tripathy 4 роки тому
батько
коміт
e1811e8862
2 змінених файлів з 10 додано та 3 видалено
  1. 4 3
      pkg/costmodel/router.go
  2. 6 0
      pkg/env/costmodelenv.go

+ 4 - 3
pkg/costmodel/router.go

@@ -1085,7 +1085,7 @@ func Initialize(additionalConfigWatchers ...ConfigWatchers) *Accesses {
 
 	watchConfigFunc := func(c interface{}) {
 		conf := c.(*v1.ConfigMap)
-		if conf.GetName() == "pricing-configs" {
+		if conf.GetName() == env.GetPricingConfigmapName() {
 			_, err := cloudProvider.UpdateConfigFromConfigMap(conf.Data)
 			if err != nil {
 				klog.Infof("ERROR UPDATING %s CONFIG: %s", "pricing-configs", err.Error())
@@ -1103,9 +1103,9 @@ func Initialize(additionalConfigWatchers ...ConfigWatchers) *Accesses {
 
 	kubecostNamespace := env.GetKubecostNamespace()
 	// We need an initial invocation because the init of the cache has happened before we had access to the provider.
-	configs, err := kubeClientset.CoreV1().ConfigMaps(kubecostNamespace).Get(context.Background(), "pricing-configs", metav1.GetOptions{})
+	configs, err := kubeClientset.CoreV1().ConfigMaps(kubecostNamespace).Get(context.Background(), env.GetPricingConfigmapName(), metav1.GetOptions{})
 	if err != nil {
-		klog.Infof("No %s configmap found at installtime, using existing configs: %s", "pricing-configs", err.Error())
+		klog.Infof("No %s configmap found at installtime, using existing configs: %s", env.GetPricingConfigmapName(), err.Error())
 	} else {
 		watchConfigFunc(configs)
 	}
@@ -1115,6 +1115,7 @@ func Initialize(additionalConfigWatchers ...ConfigWatchers) *Accesses {
 		if err != nil {
 			klog.Infof("No %s configmap found at installtime, using existing configs: %s", cw.ConfigmapName, err.Error())
 		} else {
+			klog.Infof("Found configmap %s, watching...", configs.Name)
 			watchConfigFunc(configs)
 		}
 	}

+ 6 - 0
pkg/env/costmodelenv.go

@@ -71,8 +71,14 @@ const (
 	LegacyExternalAPIDisabledVar = "LEGACY_EXTERNAL_API_DISABLED"
 
 	PromClusterIDLabelEnvVar = "PROM_CLUSTER_ID_LABEL"
+
+	PricingConfigmapName = "PRICING_CONFIGMAP_NAME"
 )
 
+func GetPricingConfigmapName() string {
+	return Get(PricingConfigmapName, "pricing-configs")
+}
+
 // GetAWSAccessKeyID returns the environment variable value for AWSAccessKeyIDEnvVar which represents
 // the AWS access key for authentication
 func GetAppVersion() string {