Merge pull request #40 from pixiake/dev

task exits after timeout
This commit is contained in:
KubeSphere CI Bot 2020-05-23 17:08:34 +08:00 committed by GitHub
commit 128a7c9b1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 38 deletions

View File

@ -14,7 +14,7 @@ import (
const (
DefaultCon = 10
Timeout = 600
Timeout = 1800
)
// NodeTask is a task that is specifically tailored to run on a single node.
@ -66,7 +66,7 @@ func (mgr *Manager) RunTaskOnNodes(nodes []kubekeyapi.HostCfg, task NodeTask, pa
select {
case <-result:
case <-time.After(time.Second * Timeout):
fmt.Sprintf("getSSHClient error,SSH-Read-TimeOut,Timeout=%ds", Timeout)
mgr.Logger.Fatalf("Execute task timeout, Timeout=%ds", Timeout)
}
wg.Done()
<-ccons

View File

@ -6,7 +6,6 @@ import (
ssh2 "github.com/kubesphere/kubekey/pkg/util/ssh"
"github.com/pkg/errors"
"strings"
"time"
)
type Runner struct {
@ -18,8 +17,6 @@ type Runner struct {
Index int
}
type TemplateVariables map[string]interface{}
func (r *Runner) RunCmd(cmd string) (string, error) {
if r.Conn == nil {
return "", errors.New("Runner is not tied to an opened SSH connection")
@ -65,36 +62,3 @@ func (r *Runner) ScpFile(src, dst string) error {
}
return nil
}
// WaitForPod waits for the availability of the given Kubernetes element.
func (r *Runner) WaitForPod(namespace string, name string, timeout time.Duration) error {
cmd := fmt.Sprintf(`sudo kubectl --kubeconfig=/etc/kubernetes/admin.conf -n "%s" get pod "%s" -o jsonpath='{.status.phase}' --ignore-not-found`, namespace, name)
if !r.WaitForCondition(cmd, timeout, IsRunning) {
return errors.Errorf("Timed out while waiting for %s/%s to come up for %v", namespace, name, timeout)
}
return nil
}
type validatorFunc func(stdout string) bool
// IsRunning checks if the given output represents the "Running" status of a Kubernetes pod.
func IsRunning(stdout string) bool {
return strings.ToLower(stdout) == "running"
}
// WaitForCondition waits for something to be true.
func (r *Runner) WaitForCondition(cmd string, timeout time.Duration, validator validatorFunc) bool {
cutoff := time.Now().Add(timeout)
for time.Now().Before(cutoff) {
stdout, _ := r.RunCmd(cmd)
if validator(stdout) {
return true
}
time.Sleep(1 * time.Second)
}
return false
}