Skip to content

Commit 4f891d5

Browse files
authored
Merge pull request #7309 from linkvt/fix-embed-certs
Fix embed certs by updating kubeconfig after certs are populated
2 parents ca8b4cc + 7debdac commit 4f891d5

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

pkg/minikube/node/start.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@ func Start(cc config.ClusterConfig, n config.Node, existingAddons map[string]boo
108108
showVersionInfo(n.KubernetesVersion, cr)
109109

110110
var bs bootstrapper.Bootstrapper
111-
var kubeconfig *kubeconfig.Settings
111+
var kcs *kubeconfig.Settings
112112
if apiServer {
113113
// 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)
115115
if err != nil {
116116
exit.WithError("Failed to setup kubeconfig", err)
117117
}
@@ -122,6 +122,11 @@ func Start(cc config.ClusterConfig, n config.Node, existingAddons map[string]boo
122122
if err != nil {
123123
exit.WithLogEntries("Error starting cluster", err, logs.FindProblems(cr, bs, cc, mRunner))
124124
}
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+
}
125130
} else {
126131
bs, err = cluster.Bootstrapper(machineAPI, viper.GetString(cmdcfg.Bootstrapper), cc, n)
127132
if err != nil {
@@ -131,7 +136,6 @@ func Start(cc config.ClusterConfig, n config.Node, existingAddons map[string]boo
131136
if err = bs.SetupCerts(cc.KubernetesConfig, n); err != nil {
132137
exit.WithError("setting up certs", err)
133138
}
134-
135139
}
136140

137141
configureMounts()
@@ -182,8 +186,7 @@ func Start(cc config.ClusterConfig, n config.Node, existingAddons map[string]boo
182186
}
183187
}
184188

185-
return kubeconfig
186-
189+
return kcs
187190
}
188191

189192
// 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)
246249
return bs
247250
}
248251

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 {
250253
addr, err := apiServerURL(*h, *cc, *n)
251254
if err != nil {
252255
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
266269
}
267270

268271
kcs.SetPath(kubeconfig.PathFromEnv())
269-
if err := kubeconfig.Update(kcs); err != nil {
270-
return kcs, err
271-
}
272-
return kcs, nil
272+
return kcs
273273
}
274274

275275
func apiServerURL(h host.Host, cc config.ClusterConfig, n config.Node) (string, error) {

test/integration/start_stop_delete_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ func TestStartStop(t *testing.T) {
7171
"--disable-driver-mounts",
7272
"--extra-config=kubeadm.ignore-preflight-errors=SystemVerification",
7373
}},
74+
{"embed-certs", constants.DefaultKubernetesVersion, []string{
75+
"--embed-certs",
76+
}},
7477
}
7578

7679
for _, tc := range tests {

0 commit comments

Comments
 (0)