e2e,acceptance: Cover enterprise runners (#1124)

Adds various code and changes I have used while testing #1062
This commit is contained in:
Yusuke Kuoka
2022-02-17 09:16:28 +09:00
committed by GitHub
parent 5b92c412a4
commit ba4bd7c0db
10 changed files with 198 additions and 15 deletions

63
test/e2e/cmd/main.go Normal file
View File

@@ -0,0 +1,63 @@
package main
import (
"bufio"
"bytes"
"fmt"
"log"
"os"
"os/exec"
"strings"
)
func main() {
if err := run(); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
}
func run() error {
var configMapNames []string
output, err := output()
if err != nil {
log.Printf("Command failed with output: %s", string(output))
return err
}
s := bufio.NewScanner(bytes.NewBuffer(output))
for s.Scan() {
if t := s.Text(); strings.Contains(t, "test-info") || strings.Contains(t, "test-result-") {
configMapNames = append(configMapNames, s.Text())
}
}
for _, n := range configMapNames {
println(n)
if output, err := delete(n); err != nil {
log.Printf("Command failed with output: %s", string(output))
return err
}
}
return nil
}
func output() ([]byte, error) {
cmd := exec.Command("kubectl", "get", "cm", "-o", `jsonpath={range .items[*]}{.metadata.name}{"\n"}{end}`)
data, err := cmd.CombinedOutput()
return data, err
}
func delete(cmName string) ([]byte, error) {
cmd := exec.Command("kubectl", "delete", "cm", cmName)
return cmd.CombinedOutput()
}
func deleteControllerManagerSecret() ([]byte, error) {
cmd := exec.Command("kubectl", "-n", "actions-runner-system", "delete", "secret", "controller-manager")
return cmd.CombinedOutput()
}

View File

@@ -4,6 +4,7 @@ import (
"context"
"fmt"
"path/filepath"
"strconv"
"time"
"github.com/actions-runner-controller/actions-runner-controller/testing"
@@ -166,7 +167,11 @@ type env struct {
useRunnerSet bool
testID string
repoToCommit string
runnerLabel, githubToken, testRepo, testOrg, testOrgRepo string
githubTokenWebhook string
testEnterprise string
featureFlagEphemeral bool
testJobs []job
}
@@ -186,10 +191,15 @@ func initTestEnv(t *testing.T) *env {
e.testID = testID
e.runnerLabel = "test-" + id
e.githubToken = testing.Getenv(t, "GITHUB_TOKEN")
e.testRepo = testing.Getenv(t, "TEST_REPO")
e.testOrg = testing.Getenv(t, "TEST_ORG")
e.testOrgRepo = testing.Getenv(t, "TEST_ORG_REPO")
e.testJobs = createTestJobs(id, testResultCMNamePrefix, 2)
e.githubTokenWebhook = testing.Getenv(t, "WEBHOOK_GITHUB_TOKEN")
e.repoToCommit = testing.Getenv(t, "TEST_COMMIT_REPO")
e.testRepo = testing.Getenv(t, "TEST_REPO", "")
e.testOrg = testing.Getenv(t, "TEST_ORG", "")
e.testOrgRepo = testing.Getenv(t, "TEST_ORG_REPO", "")
e.testEnterprise = testing.Getenv(t, "TEST_ENTERPRISE")
e.testJobs = createTestJobs(id, testResultCMNamePrefix, 10)
ephemeral, _ := strconv.ParseBool(testing.Getenv(t, "TEST_FEATURE_FLAG_EPHEMERAL"))
e.featureFlagEphemeral = ephemeral
return e
}
@@ -237,11 +247,14 @@ func (e *env) installActionsRunnerController(t *testing.T) {
}
varEnv := []string{
"TEST_ENTERPRISE=" + e.testEnterprise,
"TEST_REPO=" + e.testRepo,
"TEST_ORG=" + e.testOrg,
"TEST_ORG_REPO=" + e.testOrgRepo,
"GITHUB_TOKEN=" + e.githubToken,
"WEBHOOK_GITHUB_TOKEN=" + e.githubTokenWebhook,
"RUNNER_LABEL=" + e.runnerLabel,
fmt.Sprintf("RUNNER_FEATURE_FLAG_EPHEMERAL=%v", e.featureFlagEphemeral),
}
scriptEnv = append(scriptEnv, varEnv...)
@@ -260,7 +273,7 @@ func (e *env) createControllerNamespaceAndServiceAccount(t *testing.T) {
func (e *env) installActionsWorkflow(t *testing.T) {
t.Helper()
installActionsWorkflow(t, e.testID, e.runnerLabel, testResultCMNamePrefix, e.testRepo, e.testJobs)
installActionsWorkflow(t, e.testID, e.runnerLabel, testResultCMNamePrefix, e.repoToCommit, e.testJobs)
}
func (e *env) verifyActionsWorkflowRun(t *testing.T) {
@@ -287,6 +300,8 @@ func createTestJobs(id, testResultCMNamePrefix string, numJobs int) []job {
return testJobs
}
const Branch = "main"
func installActionsWorkflow(t *testing.T, testID, runnerLabel, testResultCMNamePrefix, testRepo string, testJobs []job) {
t.Helper()
@@ -298,7 +313,7 @@ func installActionsWorkflow(t *testing.T, testID, runnerLabel, testResultCMNameP
Name: wfName,
On: testing.On{
Push: &testing.Push{
Branches: []string{"master"},
Branches: []string{Branch},
},
},
Jobs: map[string]testing.Job{},
@@ -346,6 +361,7 @@ kubectl create cm %s$id --from-literal=status=ok
".github/workflows/workflow.yaml": wfContent,
"test.sh": script,
},
Branch: Branch,
}
if err := g.Sync(ctx); err != nil {