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

Wait to add aliases to /etc/hosts before starting kubelet #8035

Merged
merged 19 commits into from
May 8, 2020
Merged
Show file tree
Hide file tree
Changes from 15 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
1 change: 0 additions & 1 deletion pkg/drivers/kic/kic.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ func (d *Driver) Restart() error {
return fmt.Errorf("start during restart %v", err)
}
return nil

}

// Start an already created kic container
Expand Down
14 changes: 3 additions & 11 deletions pkg/minikube/bootstrapper/kubeadm/kubeadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,7 @@ func (k *Bootstrapper) restartCluster(cfg config.ClusterConfig) error {
cmds := []string{
fmt.Sprintf("%s phase certs all --config %s", baseCmd, conf),
fmt.Sprintf("%s phase kubeconfig all --config %s", baseCmd, conf),
fmt.Sprintf("sudo systemctl restart kubelet"),
priyawadhwa marked this conversation as resolved.
Show resolved Hide resolved
fmt.Sprintf("%s phase %s all --config %s", baseCmd, controlPlane, conf),
fmt.Sprintf("%s phase etcd local --config %s", baseCmd, conf),
}
Expand Down Expand Up @@ -775,7 +776,7 @@ func (k *Bootstrapper) UpdateNode(cfg config.ClusterConfig, n config.Node, r cru
return errors.Wrap(err, "host alias")
}

if err := startKubeletIfRequired(k.c, sm); err != nil {
if err := startKubelet(k.c, sm); err != nil {
return errors.Wrap(err, "reload")
}

Expand All @@ -801,7 +802,7 @@ func copyFiles(runner command.Runner, files []assets.CopyableFile) error {
return nil
}

func startKubeletIfRequired(runner command.Runner, sm sysinit.Manager) error {
func startKubelet(runner command.Runner, sm sysinit.Manager) error {
priyawadhwa marked this conversation as resolved.
Show resolved Hide resolved
now := time.Now()
defer func() {
glog.Infof("reloadKubelet took %s", time.Since(now))
Expand All @@ -810,20 +811,11 @@ func startKubeletIfRequired(runner command.Runner, sm sysinit.Manager) error {
svc := bsutil.KubeletServiceFile
conf := bsutil.KubeletSystemdConfFile

checkCmd := exec.Command("/bin/bash", "-c", fmt.Sprintf("pgrep kubelet && diff -u %s %s.new && diff -u %s %s.new", svc, svc, conf, conf))
if _, err := runner.RunCmd(checkCmd); err == nil {
glog.Infof("kubelet is already running with the right configs")
return nil
}

startCmd := exec.Command("/bin/bash", "-c", fmt.Sprintf("sudo cp %s.new %s && sudo cp %s.new %s", svc, svc, conf, conf))
if _, err := runner.RunCmd(startCmd); err != nil {
return errors.Wrap(err, "starting kubelet")
}

if err := sm.Enable("kubelet"); err != nil {
return err
}
return sm.Start("kubelet")
}

Expand Down
3 changes: 0 additions & 3 deletions pkg/minikube/cluster/pause.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@ func unpause(cr cruntime.Manager, r command.Runner, namespaces []string) ([]stri
}

sm := sysinit.New(r)
if err := sm.Enable("kubelet"); err != nil {
return ids, errors.Wrap(err, "kubelet enable")
}

if err := sm.Start("kubelet"); err != nil {
return ids, errors.Wrap(err, "kubelet start")
Expand Down
4 changes: 4 additions & 0 deletions pkg/minikube/sysinit/systemd.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ limitations under the License.
package sysinit

import (
"errors"
"os/exec"

"k8s.io/minikube/pkg/minikube/assets"
Expand Down Expand Up @@ -53,6 +54,9 @@ func (s *Systemd) Disable(svc string) error {

// Enable enables a service
func (s *Systemd) Enable(svc string) error {
if svc == "kubelet" {
return errors.New("please don't enable kubelet as it creates a race condition; if it starts on systemd boot it will pick up /etc/hosts before we have time to configure /etc/hosts")
}
_, err := s.r.RunCmd(exec.Command("sudo", "systemctl", "enable", svc))
return err
}
Expand Down
57 changes: 57 additions & 0 deletions pkg/minikube/sysinit/systemd_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
Copyright 2020 The Kubernetes Authors All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Package sysinit provides an abstraction over init systems like systemctl
package sysinit

import (
"testing"

"k8s.io/minikube/pkg/minikube/command"
)

func TestEnable(t *testing.T) {

tests := []struct {
service string
shouldErr bool
}{
{
service: "docker",
}, {
service: "kubelet",
shouldErr: true,
},
}
cr := command.NewFakeCommandRunner()
cr.SetCommandToOutput(map[string]string{
"sudo systemctl enable docker": "",
})
sd := &Systemd{
r: cr,
}
for _, test := range tests {
t.Run(test.service, func(t *testing.T) {
err := sd.Enable(test.service)
if err == nil && test.shouldErr {
t.Fatalf("expected %s service to error, but it did not", test.service)
}
if err != nil && !test.shouldErr {
t.Fatalf("expected %s service to pass, but it did not", test.service)
}
})
}
}
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",
}},
{"docker", constants.DefaultKubernetesVersion, []string{
priyawadhwa marked this conversation as resolved.
Show resolved Hide resolved
"--container-runtime=docker",
}},
{"embed-certs", constants.DefaultKubernetesVersion, []string{
"--embed-certs",
}},
Expand Down