Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix embed certs by updating kubeconfig after certs are populated #7309

Merged
merged 2 commits into from
Mar 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions pkg/minikube/node/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ func Start(cc config.ClusterConfig, n config.Node, existingAddons map[string]boo
showVersionInfo(n.KubernetesVersion, cr)

var bs bootstrapper.Bootstrapper
var kubeconfig *kubeconfig.Settings
var kcs *kubeconfig.Settings
if apiServer {
// Must be written before bootstrap, otherwise health checks may flake due to stale IP
kubeconfig, err = setupKubeconfig(host, &cc, &n, cc.Name)
kcs = setupKubeconfig(host, &cc, &n, cc.Name)
if err != nil {
exit.WithError("Failed to setup kubeconfig", err)
}
Expand All @@ -115,6 +115,11 @@ func Start(cc config.ClusterConfig, n config.Node, existingAddons map[string]boo
if err != nil {
exit.WithLogEntries("Error starting cluster", err, logs.FindProblems(cr, bs, cc, mRunner))
}

// write the kubeconfig to the file system after everything required (like certs) are created by the bootstrapper
if err := kubeconfig.Update(kcs); err != nil {
exit.WithError("Failed to update kubeconfig file.", err)
}
} else {
bs, err = cluster.Bootstrapper(machineAPI, viper.GetString(cmdcfg.Bootstrapper), cc, n)
if err != nil {
Expand All @@ -124,7 +129,6 @@ func Start(cc config.ClusterConfig, n config.Node, existingAddons map[string]boo
if err = bs.SetupCerts(cc.KubernetesConfig, n); err != nil {
exit.WithError("setting up certs", err)
}

}

configureMounts()
Expand Down Expand Up @@ -175,8 +179,7 @@ func Start(cc config.ClusterConfig, n config.Node, existingAddons map[string]boo
}
}

return kubeconfig

return kcs
}

// ConfigureRuntimes does what needs to happen to get a runtime going.
Expand Down Expand Up @@ -239,7 +242,7 @@ func setupKubeAdm(mAPI libmachine.API, cfg config.ClusterConfig, n config.Node)
return bs
}

func setupKubeconfig(h *host.Host, cc *config.ClusterConfig, n *config.Node, clusterName string) (*kubeconfig.Settings, error) {
func setupKubeconfig(h *host.Host, cc *config.ClusterConfig, n *config.Node, clusterName string) *kubeconfig.Settings {
addr, err := apiServerURL(*h, *cc, *n)
if err != nil {
exit.WithError("Failed to get API Server URL", err)
Expand All @@ -259,10 +262,7 @@ func setupKubeconfig(h *host.Host, cc *config.ClusterConfig, n *config.Node, clu
}

kcs.SetPath(kubeconfig.PathFromEnv())
if err := kubeconfig.Update(kcs); err != nil {
return kcs, err
}
return kcs, nil
return kcs
}

func apiServerURL(h host.Host, cc config.ClusterConfig, n config.Node) (string, error) {
Expand Down
3 changes: 3 additions & 0 deletions test/integration/start_stop_delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ func TestStartStop(t *testing.T) {
"--disable-driver-mounts",
"--extra-config=kubeadm.ignore-preflight-errors=SystemVerification",
}},
{"embed-certs", constants.DefaultKubernetesVersion, []string{
"--embed-certs",
}},
}

for _, tc := range tests {
Expand Down