@@ -108,10 +108,10 @@ func Start(cc config.ClusterConfig, n config.Node, existingAddons map[string]boo
108
108
showVersionInfo (n .KubernetesVersion , cr )
109
109
110
110
var bs bootstrapper.Bootstrapper
111
- var kubeconfig * kubeconfig.Settings
111
+ var kcs * kubeconfig.Settings
112
112
if apiServer {
113
113
// Must be written before bootstrap, otherwise health checks may flake due to stale IP
114
- kubeconfig , err = setupKubeconfig (host , & cc , & n , cc .Name )
114
+ kcs = setupKubeconfig (host , & cc , & n , cc .Name )
115
115
if err != nil {
116
116
exit .WithError ("Failed to setup kubeconfig" , err )
117
117
}
@@ -122,6 +122,11 @@ func Start(cc config.ClusterConfig, n config.Node, existingAddons map[string]boo
122
122
if err != nil {
123
123
exit .WithLogEntries ("Error starting cluster" , err , logs .FindProblems (cr , bs , cc , mRunner ))
124
124
}
125
+
126
+ // write the kubeconfig to the file system after everything required (like certs) are created by the bootstrapper
127
+ if err := kubeconfig .Update (kcs ); err != nil {
128
+ exit .WithError ("Failed to update kubeconfig file." , err )
129
+ }
125
130
} else {
126
131
bs , err = cluster .Bootstrapper (machineAPI , viper .GetString (cmdcfg .Bootstrapper ), cc , n )
127
132
if err != nil {
@@ -131,7 +136,6 @@ func Start(cc config.ClusterConfig, n config.Node, existingAddons map[string]boo
131
136
if err = bs .SetupCerts (cc .KubernetesConfig , n ); err != nil {
132
137
exit .WithError ("setting up certs" , err )
133
138
}
134
-
135
139
}
136
140
137
141
configureMounts ()
@@ -182,8 +186,7 @@ func Start(cc config.ClusterConfig, n config.Node, existingAddons map[string]boo
182
186
}
183
187
}
184
188
185
- return kubeconfig
186
-
189
+ return kcs
187
190
}
188
191
189
192
// ConfigureRuntimes does what needs to happen to get a runtime going.
@@ -246,7 +249,7 @@ func setupKubeAdm(mAPI libmachine.API, cfg config.ClusterConfig, n config.Node)
246
249
return bs
247
250
}
248
251
249
- func setupKubeconfig (h * host.Host , cc * config.ClusterConfig , n * config.Node , clusterName string ) ( * kubeconfig.Settings , error ) {
252
+ func setupKubeconfig (h * host.Host , cc * config.ClusterConfig , n * config.Node , clusterName string ) * kubeconfig.Settings {
250
253
addr , err := apiServerURL (* h , * cc , * n )
251
254
if err != nil {
252
255
exit .WithError ("Failed to get API Server URL" , err )
@@ -266,10 +269,7 @@ func setupKubeconfig(h *host.Host, cc *config.ClusterConfig, n *config.Node, clu
266
269
}
267
270
268
271
kcs .SetPath (kubeconfig .PathFromEnv ())
269
- if err := kubeconfig .Update (kcs ); err != nil {
270
- return kcs , err
271
- }
272
- return kcs , nil
272
+ return kcs
273
273
}
274
274
275
275
func apiServerURL (h host.Host , cc config.ClusterConfig , n config.Node ) (string , error ) {
0 commit comments