提交 6c702e1d 编写于 作者: M Medya Gh

add timeout for kubeadm init

上级 d19754b2
......@@ -16,7 +16,13 @@ limitations under the License.
package kubeadm
import "errors"
import (
"errors"
"fmt"
)
// max minutes wait for kubeadm init
const initTimeOutMinutes = 1
// FailFastError type is an error that could not be solved by trying again
type FailFastError struct {
......@@ -30,3 +36,6 @@ func (f *FailFastError) Error() string {
// ErrNoExecLinux is thrown on linux when the kubeadm binaries are mounted in a noexec volume on Linux as seen in https://github.com/kubernetes/minikube/issues/8327#issuecomment-651288459
// this error could be seen on docker/podman or none driver.
var ErrNoExecLinux = &FailFastError{errors.New("mounted kubeadm binary is not executable")}
// ErrInitTimedout is thrown if kubeadm init takes longer than max time allowed
var ErrInitTimedout = fmt.Errorf("kubeadm init timed out in %d minutes", initTimeOutMinutes)
......@@ -224,9 +224,15 @@ func (k *Bootstrapper) init(cfg config.ClusterConfig) error {
}
conf := bsutil.KubeadmYamlPath
c := exec.Command("/bin/bash", "-c", fmt.Sprintf("%s init --config %s %s --ignore-preflight-errors=%s",
ctx, cancel := context.WithTimeout(context.Background(), initTimeOutMinutes*time.Second)
defer cancel()
c := exec.CommandContext(ctx, "/bin/bash", "-c", fmt.Sprintf("%s init --config %s %s --ignore-preflight-errors=%s",
bsutil.InvokeKubeadm(cfg.KubernetesConfig.KubernetesVersion), conf, extraFlags, strings.Join(ignore, ",")))
if _, err := k.c.RunCmd(c); err != nil {
if ctx.Err() == context.DeadlineExceeded {
return ErrInitTimedout
}
if strings.Contains(err.Error(), "'kubeadm': Permission denied") {
return ErrNoExecLinux
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册