diff --git a/controllers/constants.go b/controllers/constants.go index 5b67026b..510fa911 100644 --- a/controllers/constants.go +++ b/controllers/constants.go @@ -61,4 +61,7 @@ const ( // // See https://github.com/actions-runner-controller/actions-runner-controller/pull/1180 DefaultRunnerPodRecreationDelayAfterWebhookScale = 10 * time.Minute + + EnvVarRunnerName = "RUNNER_NAME" + EnvVarRunnerToken = "RUNNER_TOKEN" ) diff --git a/controllers/runner_controller.go b/controllers/runner_controller.go index 19ee36aa..5811494b 100644 --- a/controllers/runner_controller.go +++ b/controllers/runner_controller.go @@ -453,19 +453,12 @@ func (r *RunnerReconciler) newPod(runner v1alpha1.Runner) (corev1.Pod, error) { func mutatePod(pod *corev1.Pod, token string) *corev1.Pod { updated := pod.DeepCopy() - for i := range pod.Spec.Containers { - if pod.Spec.Containers[i].Name == "runner" { - updated.Spec.Containers[i].Env = append(updated.Spec.Containers[i].Env, - corev1.EnvVar{ - Name: "RUNNER_NAME", - Value: pod.ObjectMeta.Name, - }, - corev1.EnvVar{ - Name: "RUNNER_TOKEN", - Value: token, - }, - ) - } + if getRunnerEnv(pod, EnvVarRunnerName) == "" { + setRunnerEnv(updated, EnvVarRunnerName, pod.ObjectMeta.Name) + } + + if getRunnerEnv(pod, EnvVarRunnerToken) == "" { + setRunnerEnv(updated, EnvVarRunnerToken, token) } return updated diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index 7bbab05d..c2994d23 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -186,7 +186,7 @@ type env struct { runnerLabel, githubToken, testRepo, testOrg, testOrgRepo string githubTokenWebhook string testEnterprise string - featureFlagEphemeral bool + featureFlagEphemeral *bool scaleDownDelaySecondsAfterScaleOut int64 minReplicas int64 dockerdWithinRunnerContainer bool @@ -220,8 +220,11 @@ func initTestEnv(t *testing.T) *env { e.testOrgRepo = testing.Getenv(t, "TEST_ORG_REPO", "") e.testEnterprise = testing.Getenv(t, "TEST_ENTERPRISE") e.testJobs = createTestJobs(id, testResultCMNamePrefix, 100) - ephemeral, _ := strconv.ParseBool(testing.Getenv(t, "TEST_FEATURE_FLAG_EPHEMERAL", "")) - e.featureFlagEphemeral = ephemeral + + if ephemeral, err := strconv.ParseBool(testing.Getenv(t, "TEST_FEATURE_FLAG_EPHEMERAL", "")); err == nil { + e.featureFlagEphemeral = &ephemeral + } + e.scaleDownDelaySecondsAfterScaleOut, _ = strconv.ParseInt(testing.Getenv(t, "TEST_RUNNER_SCALE_DOWN_DELAY_SECONDS_AFTER_SCALE_OUT", "10"), 10, 32) e.minReplicas, _ = strconv.ParseInt(testing.Getenv(t, "TEST_RUNNER_MIN_REPLICAS", "1"), 10, 32) @@ -285,13 +288,16 @@ func (e *env) installActionsRunnerController(t *testing.T) { "WEBHOOK_GITHUB_TOKEN=" + e.githubTokenWebhook, "RUNNER_LABEL=" + e.runnerLabel, "TEST_ID=" + e.testID, - fmt.Sprintf("RUNNER_FEATURE_FLAG_EPHEMERAL=%v", e.featureFlagEphemeral), fmt.Sprintf("RUNNER_SCALE_DOWN_DELAY_SECONDS_AFTER_SCALE_OUT=%d", e.scaleDownDelaySecondsAfterScaleOut), fmt.Sprintf("REPO_RUNNER_MIN_REPLICAS=%d", e.minReplicas), fmt.Sprintf("ORG_RUNNER_MIN_REPLICAS=%d", e.minReplicas), fmt.Sprintf("ENTERPRISE_RUNNER_MIN_REPLICAS=%d", e.minReplicas), } + if e.featureFlagEphemeral != nil { + varEnv = append(varEnv, fmt.Sprintf("RUNNER_FEATURE_FLAG_EPHEMERAL=%v", *e.featureFlagEphemeral)) + } + if e.useApp { varEnv = append(varEnv, "ACCEPTANCE_TEST_SECRET_TYPE=app",