Fix runners to do their best to gracefully stop on pod eviction (#1759)

Ref #1535
Ref #1581

Signed-off-by: Yusuke Kuoka <ykuoka@gmail.com>
This commit is contained in:
Yusuke Kuoka
2022-11-01 20:30:10 +09:00
committed by GitHub
parent 332548093a
commit c74ad6195f
30 changed files with 757 additions and 301 deletions

View File

@@ -6,6 +6,7 @@ import (
"fmt"
"os"
"os/exec"
"strings"
"time"
"github.com/actions-runner-controller/actions-runner-controller/testing/runtime"
@@ -112,6 +113,35 @@ func (k *Kubectl) WaitUntilDeployAvailable(ctx context.Context, name string, cfg
return nil
}
func (k *Kubectl) FindPods(ctx context.Context, label string, cfg KubectlConfig) ([]string, error) {
args := []string{"po", "-l", label, "-o", `jsonpath={range .items[*]}{.metadata.name}{"\n"}`}
out, err := k.CombinedOutput(k.kubectlCmd(ctx, "get", args, cfg))
if err != nil {
return nil, err
}
var pods []string
for _, l := range strings.Split(out, "\n") {
if l != "" {
pods = append(pods, l)
}
}
return pods, nil
}
func (k *Kubectl) DeletePods(ctx context.Context, names []string, cfg KubectlConfig) error {
args := []string{"po"}
args = append(args, names...)
if _, err := k.CombinedOutput(k.kubectlCmd(ctx, "delete", args, cfg)); err != nil {
return err
}
return nil
}
func (k *Kubectl) kubectlCmd(ctx context.Context, c string, args []string, cfg KubectlConfig) *exec.Cmd {
args = append([]string{c}, args...)