Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions acceptance/testdata/repo.runnerset.hra.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ spec:
# RunnerSet doesn't support scale from/to zero yet
minReplicas: 1
maxReplicas: 5
# This should be less than 600(seconds, the default) for faster testing
scaleDownDelaySecondsAfterScaleOut: 60
metrics:
- type: PercentageRunnersBusy
scaleUpThreshold: '0.75'
Expand Down
4 changes: 4 additions & 0 deletions acceptance/testdata/repo.runnerset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ spec:
serviceName: example-runnerset

#replicas: 1

# From my limited testing, `ephemeral: true` is more reliable.
# Seomtimes, updating already deployed runners from `ephemeral: false` to `ephemeral: true` seems to
# result in queued jobs hanging forever.
ephemeral: false

repository: ${TEST_REPO}
Expand Down
6 changes: 5 additions & 1 deletion controllers/pod_runner_token_injector.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ import (
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

const (
AnnotationKeyTokenExpirationDate = "actions-runner-controller/token-expires-at"
)

// +kubebuilder:webhook:path=/mutate-runner-set-pod,mutating=true,failurePolicy=ignore,groups="",resources=pods,verbs=create,versions=v1,name=mutate-runner-pod.webhook.actions.summerwind.dev,sideEffects=None,admissionReviewVersions=v1beta1

type PodRunnerTokenInjector struct {
Expand Down Expand Up @@ -72,7 +76,7 @@ func (t *PodRunnerTokenInjector) Handle(ctx context.Context, req admission.Reque

updated := mutatePod(&pod, *rt.Token)

updated.Annotations["actions-runner-controller/token-expires-at"] = ts
updated.Annotations[AnnotationKeyTokenExpirationDate] = ts

if pod.Spec.RestartPolicy != corev1.RestartPolicyOnFailure {
updated.Spec.RestartPolicy = corev1.RestartPolicyOnFailure
Expand Down
18 changes: 11 additions & 7 deletions controllers/runner_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ const (

// This is an annotation internal to actions-runner-controller and can change in backward-incompatible ways
annotationKeyRegistrationOnly = "actions-runner-controller/registration-only"

EnvVarOrg = "RUNNER_ORG"
EnvVarRepo = "RUNNER_REPO"
EnvVarEnterprise = "RUNNER_ENTERPRISE"
)

// RunnerReconciler reconciles a Runner object
Expand Down Expand Up @@ -89,7 +93,7 @@ func (r *RunnerReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
}

if runner.ObjectMeta.DeletionTimestamp.IsZero() {
finalizers, added := addFinalizer(runner.ObjectMeta.Finalizers)
finalizers, added := addFinalizer(runner.ObjectMeta.Finalizers, finalizerName)

if added {
newRunner := runner.DeepCopy()
Expand All @@ -103,7 +107,7 @@ func (r *RunnerReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
return ctrl.Result{}, nil
}
} else {
finalizers, removed := removeFinalizer(runner.ObjectMeta.Finalizers)
finalizers, removed := removeFinalizer(runner.ObjectMeta.Finalizers, finalizerName)

if removed {
if len(runner.Status.Registration.Token) > 0 {
Expand Down Expand Up @@ -741,15 +745,15 @@ func newRunnerPod(template corev1.Pod, runnerSpec v1alpha1.RunnerConfig, default

env := []corev1.EnvVar{
{
Name: "RUNNER_ORG",
Name: EnvVarOrg,
Value: runnerSpec.Organization,
},
{
Name: "RUNNER_REPO",
Name: EnvVarRepo,
Value: runnerSpec.Repository,
},
{
Name: "RUNNER_ENTERPRISE",
Name: EnvVarEnterprise,
Value: runnerSpec.Enterprise,
},
{
Expand Down Expand Up @@ -1029,7 +1033,7 @@ func (r *RunnerReconciler) SetupWithManager(mgr ctrl.Manager) error {
Complete(r)
}

func addFinalizer(finalizers []string) ([]string, bool) {
func addFinalizer(finalizers []string, finalizerName string) ([]string, bool) {
exists := false
for _, name := range finalizers {
if name == finalizerName {
Expand All @@ -1044,7 +1048,7 @@ func addFinalizer(finalizers []string) ([]string, bool) {
return append(finalizers, finalizerName), true
}

func removeFinalizer(finalizers []string) ([]string, bool) {
func removeFinalizer(finalizers []string, finalizerName string) ([]string, bool) {
removed := false
result := []string{}

Expand Down
Loading