Merge pull request #4103 from RolandMa1986/feat-env-param
feat: load configuration from Environment variables
This commit is contained in:
@@ -49,6 +49,10 @@ spec:
|
||||
name: kubesphere-config
|
||||
- mountPath: /etc/localtime
|
||||
name: host-time
|
||||
env:
|
||||
{{- if .Values.env }}
|
||||
{{- toYaml .Values.env | nindent 8 }}
|
||||
{{- end }}
|
||||
livenessProbe:
|
||||
failureThreshold: 8
|
||||
httpGet:
|
||||
|
||||
@@ -52,6 +52,10 @@ spec:
|
||||
name: webhook-secret
|
||||
- mountPath: /etc/localtime
|
||||
name: host-time
|
||||
env:
|
||||
{{- if .Values.env }}
|
||||
{{- toYaml .Values.env | nindent 8 }}
|
||||
{{- end }}
|
||||
dnsPolicy: ClusterFirst
|
||||
restartPolicy: Always
|
||||
schedulerName: default-scheduler
|
||||
|
||||
@@ -116,3 +116,4 @@ tolerations:
|
||||
tolerationSeconds: 60
|
||||
|
||||
affinity: {}
|
||||
env: []
|
||||
@@ -141,6 +141,11 @@ func TryLoadFromDisk() (*Config, error) {
|
||||
// Load from current working directory, only used for debugging
|
||||
viper.AddConfigPath(".")
|
||||
|
||||
// Load from Environment variables
|
||||
viper.SetEnvPrefix("kubesphere")
|
||||
viper.AutomaticEnv()
|
||||
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
|
||||
|
||||
if err := viper.ReadInConfig(); err != nil {
|
||||
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
|
||||
return nil, err
|
||||
|
||||
@@ -85,7 +85,7 @@ func newTestConfig() (*Config, error) {
|
||||
RedisOptions: &cache.Options{
|
||||
Host: "localhost",
|
||||
Port: 6379,
|
||||
Password: "P@88w0rd",
|
||||
Password: "KUBESPHERE_REDIS_PASSWORD",
|
||||
DB: 0,
|
||||
},
|
||||
S3Options: &s3.Options{
|
||||
@@ -216,6 +216,9 @@ func TestGet(t *testing.T) {
|
||||
saveTestConfig(t, conf)
|
||||
defer cleanTestConfig(t)
|
||||
|
||||
conf.RedisOptions.Password = "P@88w0rd"
|
||||
os.Setenv("KUBESPHERE_REDIS_PASSWORD", "P@88w0rd")
|
||||
|
||||
conf2, err := TryLoadFromDisk()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
Reference in New Issue
Block a user