Kaynağa Gözat

Switch to detecting presence of Kubernetes-provided environment variables

Using KUBERNETES_PORT from https://kubernetes.io/docs/tutorials/services/connect-applications-service/#environment-variables

Signed-off-by: Matt Ray <github@mattray.dev>
Matt Ray 2 yıl önce
ebeveyn
işleme
f8272a48f4
2 değiştirilmiş dosya ile 7 ekleme ve 13 silme
  1. 3 2
      pkg/env/costmodelenv.go
  2. 4 11
      pkg/env/costmodelenv_test.go

+ 3 - 2
pkg/env/costmodelenv.go

@@ -114,7 +114,8 @@ const (
 
 	DataRetentionDailyResolutionDaysEnvVar = "DATA_RETENTION_DAILY_RESOLUTION_DAYS"
 
-	KubernetesEnabledEnvVar         = "KUBERNETES_ENABLED"
+	// We assume that Kubernetes is enabled if there is a KUBERNETES_PORT environment variable present
+	KubernetesEnabledEnvVar         = "KUBERNETES_PORT"
 	CloudCostEnabledEnvVar          = "CLOUD_COST_ENABLED"
 	CloudCostConfigPath             = "CLOUD_COST_CONFIG_PATH"
 	CloudCostMonthToDateIntervalVar = "CLOUD_COST_MONTH_TO_DATE_INTERVAL"
@@ -638,7 +639,7 @@ func GetDataRetentionDailyResolutionDays() int64 {
 }
 
 func IsKubernetesEnabled() bool {
-	return GetBool(KubernetesEnabledEnvVar, true)
+	return Get(KubernetesEnabledEnvVar, "") != ""
 }
 
 func IsCloudCostEnabled() bool {

+ 4 - 11
pkg/env/costmodelenv_test.go

@@ -131,21 +131,14 @@ func TestGetKubernetesEnabled(t *testing.T) {
 		pre  func()
 	}{
 		{
-			name: "Ensure the default value is true",
-			want: true,
+			name: "Ensure the default value is false",
+			want: false,
 		},
 		{
-			name: "Ensure the value is true when KUBERNETES_ENABLED is set to true",
+			name: "Ensure the value is true when KUBERNETES_PORT has a value",
 			want: true,
 			pre: func() {
-				os.Setenv("KUBERNETES_ENABLED", "true")
-			},
-		},
-		{
-			name: "Ensure the value is false when KUBERNETES_ENABLED is set to false",
-			want: false,
-			pre: func() {
-				os.Setenv("KUBERNETES_ENABLED", "false")
+				os.Setenv("KUBERNETES_PORT", "tcp://10.43.0.1:443")
 			},
 		},
 	}