mirror of
https://github.com/actions/actions-runner-controller.git
synced 2025-12-14 05:37:48 +00:00
Merge pull request #1212 from actions-runner-controller/fix-runnerdeploy-duplicate-envvars
Fix RunnerDeployment-managed runner pods to not get RUNNER_NAME and RUNNER_TOKEN injected twice
This commit is contained in:
@@ -61,4 +61,7 @@ const (
|
|||||||
//
|
//
|
||||||
// See https://github.com/actions-runner-controller/actions-runner-controller/pull/1180
|
// See https://github.com/actions-runner-controller/actions-runner-controller/pull/1180
|
||||||
DefaultRunnerPodRecreationDelayAfterWebhookScale = 10 * time.Minute
|
DefaultRunnerPodRecreationDelayAfterWebhookScale = 10 * time.Minute
|
||||||
|
|
||||||
|
EnvVarRunnerName = "RUNNER_NAME"
|
||||||
|
EnvVarRunnerToken = "RUNNER_TOKEN"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -453,19 +453,12 @@ func (r *RunnerReconciler) newPod(runner v1alpha1.Runner) (corev1.Pod, error) {
|
|||||||
func mutatePod(pod *corev1.Pod, token string) *corev1.Pod {
|
func mutatePod(pod *corev1.Pod, token string) *corev1.Pod {
|
||||||
updated := pod.DeepCopy()
|
updated := pod.DeepCopy()
|
||||||
|
|
||||||
for i := range pod.Spec.Containers {
|
if getRunnerEnv(pod, EnvVarRunnerName) == "" {
|
||||||
if pod.Spec.Containers[i].Name == "runner" {
|
setRunnerEnv(updated, EnvVarRunnerName, pod.ObjectMeta.Name)
|
||||||
updated.Spec.Containers[i].Env = append(updated.Spec.Containers[i].Env,
|
}
|
||||||
corev1.EnvVar{
|
|
||||||
Name: "RUNNER_NAME",
|
if getRunnerEnv(pod, EnvVarRunnerToken) == "" {
|
||||||
Value: pod.ObjectMeta.Name,
|
setRunnerEnv(updated, EnvVarRunnerToken, token)
|
||||||
},
|
|
||||||
corev1.EnvVar{
|
|
||||||
Name: "RUNNER_TOKEN",
|
|
||||||
Value: token,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return updated
|
return updated
|
||||||
|
|||||||
@@ -186,7 +186,7 @@ type env struct {
|
|||||||
runnerLabel, githubToken, testRepo, testOrg, testOrgRepo string
|
runnerLabel, githubToken, testRepo, testOrg, testOrgRepo string
|
||||||
githubTokenWebhook string
|
githubTokenWebhook string
|
||||||
testEnterprise string
|
testEnterprise string
|
||||||
featureFlagEphemeral bool
|
featureFlagEphemeral *bool
|
||||||
scaleDownDelaySecondsAfterScaleOut int64
|
scaleDownDelaySecondsAfterScaleOut int64
|
||||||
minReplicas int64
|
minReplicas int64
|
||||||
dockerdWithinRunnerContainer bool
|
dockerdWithinRunnerContainer bool
|
||||||
@@ -220,8 +220,11 @@ func initTestEnv(t *testing.T) *env {
|
|||||||
e.testOrgRepo = testing.Getenv(t, "TEST_ORG_REPO", "")
|
e.testOrgRepo = testing.Getenv(t, "TEST_ORG_REPO", "")
|
||||||
e.testEnterprise = testing.Getenv(t, "TEST_ENTERPRISE")
|
e.testEnterprise = testing.Getenv(t, "TEST_ENTERPRISE")
|
||||||
e.testJobs = createTestJobs(id, testResultCMNamePrefix, 100)
|
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.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)
|
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,
|
"WEBHOOK_GITHUB_TOKEN=" + e.githubTokenWebhook,
|
||||||
"RUNNER_LABEL=" + e.runnerLabel,
|
"RUNNER_LABEL=" + e.runnerLabel,
|
||||||
"TEST_ID=" + e.testID,
|
"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("RUNNER_SCALE_DOWN_DELAY_SECONDS_AFTER_SCALE_OUT=%d", e.scaleDownDelaySecondsAfterScaleOut),
|
||||||
fmt.Sprintf("REPO_RUNNER_MIN_REPLICAS=%d", e.minReplicas),
|
fmt.Sprintf("REPO_RUNNER_MIN_REPLICAS=%d", e.minReplicas),
|
||||||
fmt.Sprintf("ORG_RUNNER_MIN_REPLICAS=%d", e.minReplicas),
|
fmt.Sprintf("ORG_RUNNER_MIN_REPLICAS=%d", e.minReplicas),
|
||||||
fmt.Sprintf("ENTERPRISE_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 {
|
if e.useApp {
|
||||||
varEnv = append(varEnv,
|
varEnv = append(varEnv,
|
||||||
"ACCEPTANCE_TEST_SECRET_TYPE=app",
|
"ACCEPTANCE_TEST_SECRET_TYPE=app",
|
||||||
|
|||||||
Reference in New Issue
Block a user