@@ -31,13 +31,14 @@ const DefaultDevspaceDeploymentName = "devspace-default"
3131const CurrentConfigVersion = "v1alpha1"
3232
3333// Global config vars
34- var config * v1.Config
35- var configRaw * v1.Config
36- var overwriteConfig * v1.Config
37- var overwriteConfigRaw * v1.Config
34+ var config * v1.Config // merged config
35+ var configRaw * v1.Config // config from .devspace/config.yaml
36+ var overwriteConfig * v1.Config // overwrite config from .devspace/config.yaml
37+ var defaultConfig * v1.Config // default config values
3838
3939// Thread-safety helper
4040var getConfigOnce sync.Once
41+ var setDefaultsOnce sync.Once
4142
4243// ConfigExists checks whether the yaml file for the config exists
4344func ConfigExists () (bool , error ) {
@@ -57,9 +58,10 @@ func ConfigExists() (bool, error) {
5758func InitConfig () * v1.Config {
5859 getConfigOnce .Do (func () {
5960 config = makeConfig ()
61+ overwriteConfig = makeConfig ()
6062 configRaw = makeConfig ()
6163 overwriteConfig = makeConfig ()
62- overwriteConfigRaw = makeConfig ()
64+ defaultConfig = makeConfig ()
6365 })
6466
6567 return config
@@ -69,28 +71,28 @@ func InitConfig() *v1.Config {
6971func GetConfig () * v1.Config {
7072 getConfigOnce .Do (func () {
7173 config = makeConfig ()
74+ overwriteConfig = makeConfig ()
7275 configRaw = makeConfig ()
7376 overwriteConfig = makeConfig ()
74- overwriteConfigRaw = makeConfig ()
77+ defaultConfig = makeConfig ()
7578
7679 err := loadConfig (configRaw , ConfigPath )
7780 if err != nil {
7881 log .Errorf ("Loading config: %v" , err )
7982 log .Fatal ("Please run `devspace init -r` to repair your config" )
8083 }
8184
82- //ignore error as overwrite.yaml is optional
83- loadConfig (overwriteConfigRaw , OverwriteConfigPath )
84-
85- Merge (& config , configRaw )
86- Merge (& overwriteConfig , overwriteConfigRaw )
87- Merge (& config , overwriteConfig )
88-
89- if config .Version == nil || * config .Version != CurrentConfigVersion {
85+ if configRaw .Version == nil || * configRaw .Version != CurrentConfigVersion {
9086 log .Fatal ("Your config is out of date. Please run `devspace init -r` to update your config" )
9187 }
9288
93- SetDefaults (config )
89+ //ignore error as overwrite.yaml is optional
90+ loadConfig (overwriteConfig , OverwriteConfigPath )
91+
92+ Merge (& config , configRaw , false )
93+ Merge (& config , overwriteConfig , true )
94+
95+ SetDefaultsOnce ()
9496 })
9597
9698 return config
@@ -103,67 +105,78 @@ func GetOverwriteConfig() *v1.Config {
103105 return overwriteConfig
104106}
105107
106- // SetDefaults ensures that specific values are set in the config
107- func SetDefaults (config * v1.Config ) {
108- defaultNamespace , err := GetDefaultNamespace (config )
109- if err != nil {
110- log .Fatalf ("Error retrieving default namespace: %v" , err )
111- }
112-
113- // Initialize Namespaces
114- if config .DevSpace != nil {
115- needTiller := config .InternalRegistry != nil
108+ // SetDefaultsOnce ensures that specific values are set in the config
109+ func SetDefaultsOnce () {
110+ setDefaultsOnce .Do (func () {
111+ defaultNamespace , err := GetDefaultNamespace (config )
112+ if err != nil {
113+ log .Fatalf ("Error retrieving default namespace: %v" , err )
114+ }
116115
117- if config .DevSpace .Deployments != nil {
118- for index , deployConfig := range * config .DevSpace .Deployments {
119- if deployConfig .Name == nil {
120- log .Fatalf ("Error in config: Unnamed deployment at index %d" , index )
121- }
122- if deployConfig .Namespace == nil {
123- deployConfig .Namespace = String ("" )
124- }
125- if deployConfig .Helm != nil {
126- needTiller = true
116+ // Initialize Namespaces
117+ if config .DevSpace != nil {
118+ needTiller := config .InternalRegistry != nil
119+
120+ if config .DevSpace .Deployments != nil {
121+ for index , deployConfig := range * config .DevSpace .Deployments {
122+ if deployConfig .Name == nil {
123+ log .Fatalf ("Error in config: Unnamed deployment at index %d" , index )
124+ }
125+
126+ if deployConfig .Namespace == nil {
127+ defaultDeployments := * defaultConfig .DevSpace .Deployments
128+ defaultValue := String ("" )
129+
130+ defaultDeployments = append (defaultDeployments , & v1.DeploymentConfig {
131+ Namespace : defaultValue ,
132+ })
133+ defaultConfig .DevSpace .Deployments = & defaultDeployments
134+ deployConfig .Namespace = defaultValue
135+ }
136+
137+ if deployConfig .Helm != nil {
138+ needTiller = true
139+ }
127140 }
128141 }
129- }
130142
131- if config .DevSpace .Sync != nil {
132- for _ , syncPath := range * config .DevSpace .Sync {
133- if syncPath .Namespace == nil {
134- syncPath .Namespace = String ("" )
143+ if config .DevSpace .Sync != nil {
144+ for _ , syncPath := range * config .DevSpace .Sync {
145+ if syncPath .Namespace == nil {
146+ syncPath .Namespace = String ("" )
147+ }
135148 }
136149 }
137- }
138150
139- if config .DevSpace .Ports != nil {
140- for _ , portForwarding := range * config .DevSpace .Ports {
141- if portForwarding .Namespace == nil {
142- portForwarding .Namespace = String ("" )
151+ if config .DevSpace .Ports != nil {
152+ for _ , portForwarding := range * config .DevSpace .Ports {
153+ if portForwarding .Namespace == nil {
154+ portForwarding .Namespace = String ("" )
155+ }
143156 }
144157 }
145- }
146158
147- if needTiller && config .Tiller == nil {
148- config .Tiller = & v1.TillerConfig {
149- Namespace : & defaultNamespace ,
159+ if needTiller && config .Tiller == nil {
160+ config .Tiller = & v1.TillerConfig {
161+ Namespace : & defaultNamespace ,
162+ }
150163 }
151164 }
152- }
153165
154- if config .Images != nil {
155- for _ , buildConfig := range * config .Images {
156- if buildConfig .Build != nil && buildConfig .Build .Kaniko != nil {
157- if buildConfig .Build .Kaniko .Namespace == nil {
158- buildConfig .Build .Kaniko .Namespace = String ("" )
166+ if config .Images != nil {
167+ for _ , buildConfig := range * config .Images {
168+ if buildConfig .Build != nil && buildConfig .Build .Kaniko != nil {
169+ if buildConfig .Build .Kaniko .Namespace == nil {
170+ buildConfig .Build .Kaniko .Namespace = String ("" )
171+ }
159172 }
160173 }
161174 }
162- }
163175
164- if config .InternalRegistry != nil {
165- config .InternalRegistry .Namespace = & defaultNamespace
166- }
176+ if config .InternalRegistry != nil {
177+ config .InternalRegistry .Namespace = & defaultNamespace
178+ }
179+ })
167180}
168181
169182// GetDefaultNamespace retrieves the default namespace where to operate in, either from devspace config or kube config
0 commit comments