-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⭐ Allow enabling pod discovery with an env var (#473)
- Loading branch information
Showing
4 changed files
with
65 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package feature_flags | ||
|
||
import ( | ||
"os" | ||
"strings" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
const FeatureFlagPrefix = "FEATURE_" | ||
|
||
var ( | ||
enablePodDiscovery bool | ||
allFeatureFlags = make(map[string]string) | ||
) | ||
|
||
func init() { | ||
envs := os.Environ() | ||
for _, e := range envs { | ||
// If it has the feature flag prefix, then parse the env var. | ||
if strings.HasPrefix(e, FeatureFlagPrefix) { | ||
val := strings.Split(e, "=") | ||
allFeatureFlags[val[0]] = val[1] | ||
setGlobalFlags(val[0], val[1]) | ||
} | ||
} | ||
} | ||
|
||
func AllFeatureFlags() map[string]string { | ||
return allFeatureFlags | ||
} | ||
|
||
func AllFeatureFlagsAsEnv() []corev1.EnvVar { | ||
var env []corev1.EnvVar | ||
for k, v := range allFeatureFlags { | ||
env = append(env, corev1.EnvVar{Name: k, Value: v}) | ||
} | ||
return env | ||
} | ||
|
||
func GetEnablePodDiscovery() bool { | ||
return enablePodDiscovery | ||
} | ||
|
||
func setGlobalFlags(k, v string) { | ||
switch k { | ||
case "FEATURE_DISCOVER_PODS": | ||
enablePodDiscovery = true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters