-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
config.go
53 lines (46 loc) · 1.76 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation and Dapr Contributors.
// Licensed under the MIT License.
// ------------------------------------------------------------
package injector
import (
"github.com/kelseyhightower/envconfig"
"github.com/dapr/dapr/utils"
)
// Config represents configuration options for the Dapr Sidecar Injector webhook server.
type Config struct {
TLSCertFile string `envconfig:"TLS_CERT_FILE" required:"true"`
TLSKeyFile string `envconfig:"TLS_KEY_FILE" required:"true"`
SidecarImage string `envconfig:"SIDECAR_IMAGE" required:"true"`
SidecarImagePullPolicy string `envconfig:"SIDECAR_IMAGE_PULL_POLICY"`
Namespace string `envconfig:"NAMESPACE" required:"true"`
KubeClusterDomain string `envconfig:"KUBE_CLUSTER_DOMAIN"`
}
// NewConfigWithDefaults returns a Config object with default values already
// applied. Callers are then free to set custom values for the remaining fields
// and/or override default values.
func NewConfigWithDefaults() Config {
return Config{
SidecarImagePullPolicy: "Always",
}
}
// GetConfig returns configuration derived from environment variables.
func GetConfig() (Config, error) {
// get config from environment variables
c := NewConfigWithDefaults()
err := envconfig.Process("", &c)
if err != nil {
return c, err
}
if c.KubeClusterDomain == "" {
// auto-detect KubeClusterDomain from resolv.conf file
clusterDomain, err := utils.GetKubeClusterDomain()
if err != nil {
log.Errorf("failed to get clusterDomain err:%s, set default:%s", err, utils.DefaultKubeClusterDomain)
c.KubeClusterDomain = utils.DefaultKubeClusterDomain
} else {
c.KubeClusterDomain = clusterDomain
}
}
return c, nil
}