Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
276bb1c
Fix ephemeral runner set status update
nikola-jokic Jun 12, 2026
390d6e2
Potential fix for pull request finding
nikola-jokic Jun 12, 2026
5f974df
Renam Url to URL
nikola-jokic Jun 15, 2026
ae9b446
wip
nikola-jokic Jun 15, 2026
34ef44e
wip
nikola-jokic Jun 15, 2026
7a59fea
Fix ephemeral runner set annotation propagation
nikola-jokic Jun 15, 2026
1f54447
fix min/max runners
nikola-jokic Jun 15, 2026
3b15137
wip
nikola-jokic Jun 16, 2026
10ae75d
wip
nikola-jokic Jun 17, 2026
d2e63d7
wip
nikola-jokic Jun 17, 2026
7803f19
fix equal annotations
nikola-jokic Jun 23, 2026
6d2a1cd
Use metrics to display runner statuses instead of status field for Ep…
nikola-jokic Jul 6, 2026
3de12ec
wip
nikola-jokic Jul 10, 2026
32a8d20
revert optional
nikola-jokic Jul 10, 2026
2148a62
wip
nikola-jokic Jul 10, 2026
3a6ce79
wip
nikola-jokic Jul 13, 2026
195f9a4
wip
nikola-jokic Jul 13, 2026
0243eb1
revert optional tags
nikola-jokic Jul 13, 2026
9ad6faa
Use metrics to display runner statuses instead of status field for Ep…
nikola-jokic Jul 6, 2026
7602700
Include resource cache for desired resources
nikola-jokic Jul 13, 2026
a47cae6
wip
nikola-jokic Jul 15, 2026
4670f01
remove if checks, testing should catch nil references
nikola-jokic Jul 15, 2026
36d8aae
Remove fingerprint from annotation
nikola-jokic Jul 16, 2026
b99bc5e
Merge branch 'master' into nikola-jokic/remove-annotation-fingerprint
nikola-jokic Jul 22, 2026
daca163
wip
nikola-jokic Jul 22, 2026
c08a114
fix
nikola-jokic Jul 22, 2026
73c8f52
revert charts
nikola-jokic Jul 23, 2026
3a67a4f
ok
nikola-jokic Jul 23, 2026
f2fbfe3
fix test
nikola-jokic Jul 23, 2026
ac28648
wip
nikola-jokic Jul 17, 2026
ab1c70d
Use lazy copy for annotations
nikola-jokic Jul 20, 2026
af55427
Add predicates to reduce reconciliations
nikola-jokic Jul 24, 2026
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
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,10 @@ type HistogramMetric struct {
type AutoscalingRunnerSetStatus struct {
// +optional
Phase AutoscalingRunnerSetPhase `json:"phase"`
// ObservedGeneration tracks the metadata.generation of this ARS at observation time,
// enabling detection of Pending phase when generation differs. Unset defaults to 0.
// +optional
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
}

type AutoscalingRunnerSetPhase string
Expand Down
16 changes: 16 additions & 0 deletions apis/actions.github.com/v1alpha1/ephemeralrunnerset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,28 @@ type EphemeralRunnerSetSpec struct {
// but does not apply to existing ephemeral runners.
// +optional
EphemeralRunnerMetadata *ResourceMeta `json:"ephemeralRunnerMetadata,omitempty"`
// ActionableRevision is a restart-safe applied marker that increments whenever
// Spec.EphemeralRunnerSpec changes, enabling detection of spec updates.
// Unset defaults to 0.
// +optional
ActionableRevision int64 `json:"actionableRevision,omitempty"`
}

// EphemeralRunnerSetStatus defines the observed state of EphemeralRunnerSet
type EphemeralRunnerSetStatus struct {
// +optional
Phase EphemeralRunnerSetPhase `json:"phase"`
// AppliedActionableRevision is a restart-safe applied marker tracking the last successfully
// applied ActionableRevision value. Advances only after spec cleanup succeeds.
// Unset defaults to 0.
// +optional
AppliedActionableRevision int64 `json:"appliedActionableRevision,omitempty"`
// FinishedRunnerCleanupPatchID records the listener patch ID for which finished
// ephemeral runners were cleaned up. Scale-up is suppressed for the same patch ID
// until the listener publishes a fresh desired-state patch.
// Unset defaults to 0.
// +optional
FinishedRunnerCleanupPatchID int `json:"finishedRunnerCleanupPatchID,omitempty"`
}

// EphemeralRunnerSetPhase is the phase of the ephemeral runner set resource
Expand Down
2 changes: 1 addition & 1 deletion apis/actions.github.com/v1alpha1/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package v1alpha1
import "strings"

func IsVersionAllowed(resourceVersion, buildVersion string) bool {
if buildVersion == "dev" || resourceVersion == buildVersion || strings.HasPrefix(buildVersion, "canary-") {
if resourceVersion == buildVersion || buildVersion == "dev" || strings.HasPrefix(buildVersion, "canary-") {
return true
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 39 additions & 11 deletions cmd/ghalistener/scaler/scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func (w *Scaler) applyDefaults() error {
// It takes a context and a jobInfo parameter which contains the details of the started job.
// This update marks the ephemeral runner so that the controller would have more context
// about the ephemeral runner that should not be deleted when scaling down.
// It also transitions the phase to Running if the runner is not in a terminal state.
// It returns an error if there is any issue with updating the job information.
func (w *Scaler) HandleJobStarted(ctx context.Context, jobInfo *scaleset.JobStarted) error {
w.logger.Info("Updating job info for the runner",
Expand All @@ -102,23 +103,50 @@ func (w *Scaler) HandleJobStarted(ctx context.Context, jobInfo *scaleset.JobStar

w.dirty = true

// Fetch current EphemeralRunner to check phase and deletion status
currentRunner := &v1alpha1.EphemeralRunner{}
err := w.clientset.RESTClient().
Get().
Prefix("apis", v1alpha1.GroupVersion.Group, v1alpha1.GroupVersion.Version).
Namespace(w.config.EphemeralRunnerSetNamespace).
Resource("EphemeralRunners").
Name(jobInfo.RunnerName).
Do(ctx).
Comment on lines +108 to +114
Into(currentRunner)
if err != nil {
if kerrors.IsNotFound(err) {
w.logger.Info("Ephemeral runner not found, skipping job info update", "runnerName", jobInfo.RunnerName)
return nil
}
return fmt.Errorf("failed to get ephemeral runner: %w", err)
}

original, err := json.Marshal(&v1alpha1.EphemeralRunner{})
if err != nil {
return fmt.Errorf("failed to marshal empty ephemeral runner: %w", err)
}

patch, err := json.Marshal(
&v1alpha1.EphemeralRunner{
Status: v1alpha1.EphemeralRunnerStatus{
JobRequestID: jobInfo.RunnerRequestID,
JobRepositoryName: fmt.Sprintf("%s/%s", jobInfo.OwnerName, jobInfo.RepositoryName),
JobID: jobInfo.JobID,
WorkflowRunID: jobInfo.WorkflowRunID,
JobWorkflowRef: jobInfo.JobWorkflowRef,
JobDisplayName: jobInfo.JobDisplayName,
},
// Build patch with job fields
patchRunner := &v1alpha1.EphemeralRunner{
Status: v1alpha1.EphemeralRunnerStatus{
JobRequestID: jobInfo.RunnerRequestID,
JobRepositoryName: fmt.Sprintf("%s/%s", jobInfo.OwnerName, jobInfo.RepositoryName),
JobID: jobInfo.JobID,
WorkflowRunID: jobInfo.WorkflowRunID,
JobWorkflowRef: jobInfo.JobWorkflowRef,
JobDisplayName: jobInfo.JobDisplayName,
},
)
}

// Only set Running phase if current phase is not terminal/failure and deletion is not in progress
if currentRunner.DeletionTimestamp == nil &&
currentRunner.Status.Phase != v1alpha1.EphemeralRunnerPhaseFailed &&
currentRunner.Status.Phase != v1alpha1.EphemeralRunnerPhaseSucceeded &&
currentRunner.Status.Phase != v1alpha1.EphemeralRunnerPhaseOutdated {
patchRunner.Status.Phase = v1alpha1.EphemeralRunnerPhaseRunning
}

patch, err := json.Marshal(patchRunner)
if err != nil {
return fmt.Errorf("failed to marshal ephemeral runner patch: %w", err)
}
Expand Down
146 changes: 146 additions & 0 deletions cmd/ghalistener/scaler/scaler_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,161 @@
package scaler

import (
"context"
"encoding/json"
"log/slog"
"math"
"net/http"
"net/http/httptest"
"testing"

"github.com/actions/actions-runner-controller/apis/actions.github.com/v1alpha1"
"github.com/actions/scaleset"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
)

var discardLogger = slog.New(slog.DiscardHandler)

func TestHandleJobStarted(t *testing.T) {
jobInfo := &scaleset.JobStarted{
RunnerName: "runner-1",
JobMessageBase: scaleset.JobMessageBase{
OwnerName: "actions",
RepositoryName: "actions-runner-controller",
JobID: "job-1",
WorkflowRunID: 456,
JobWorkflowRef: "actions/actions-runner-controller/.github/workflows/ci.yaml@refs/heads/main",
JobDisplayName: "build",
RunnerRequestID: 123,
},
}

t.Run("patches job fields and running phase together", func(t *testing.T) {
runner := newTestEphemeralRunner(jobInfo.RunnerName, "")
scaler, shutdown := newTestScaler(t, runner)
defer shutdown()

require.NoError(t, scaler.HandleJobStarted(context.Background(), jobInfo))

assertJobStartedStatus(t, runner, jobInfo)
assert.Equal(t, v1alpha1.EphemeralRunnerPhaseRunning, runner.Status.Phase)
})

t.Run("repeated assignment remains idempotent", func(t *testing.T) {
runner := newTestEphemeralRunner(jobInfo.RunnerName, v1alpha1.EphemeralRunnerPhaseRunning)
scaler, shutdown := newTestScaler(t, runner)
defer shutdown()

require.NoError(t, scaler.HandleJobStarted(context.Background(), jobInfo))
firstStatus := runner.Status
require.NoError(t, scaler.HandleJobStarted(context.Background(), jobInfo))

assert.Equal(t, firstStatus, runner.Status)
assertJobStartedStatus(t, runner, jobInfo)
assert.Equal(t, v1alpha1.EphemeralRunnerPhaseRunning, runner.Status.Phase)
})

for _, phase := range []v1alpha1.EphemeralRunnerPhase{
v1alpha1.EphemeralRunnerPhaseFailed,
v1alpha1.EphemeralRunnerPhaseSucceeded,
v1alpha1.EphemeralRunnerPhaseOutdated,
} {
t.Run("preserves "+string(phase)+" phase while patching job fields", func(t *testing.T) {
runner := newTestEphemeralRunner(jobInfo.RunnerName, phase)
scaler, shutdown := newTestScaler(t, runner)
defer shutdown()

require.NoError(t, scaler.HandleJobStarted(context.Background(), jobInfo))

assertJobStartedStatus(t, runner, jobInfo)
assert.Equal(t, phase, runner.Status.Phase)
})
}

t.Run("preserves deleting runner phase while patching job fields", func(t *testing.T) {
runner := newTestEphemeralRunner(jobInfo.RunnerName, v1alpha1.EphemeralRunnerPhasePending)
deletionTimestamp := metav1.Now()
runner.DeletionTimestamp = &deletionTimestamp
scaler, shutdown := newTestScaler(t, runner)
defer shutdown()

require.NoError(t, scaler.HandleJobStarted(context.Background(), jobInfo))

assertJobStartedStatus(t, runner, jobInfo)
assert.Equal(t, v1alpha1.EphemeralRunnerPhasePending, runner.Status.Phase)
})
}

func newTestEphemeralRunner(name string, phase v1alpha1.EphemeralRunnerPhase) *v1alpha1.EphemeralRunner {
return &v1alpha1.EphemeralRunner{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: "default",
},
Status: v1alpha1.EphemeralRunnerStatus{
Phase: phase,
},
}
}

func newTestScaler(t *testing.T, runner *v1alpha1.EphemeralRunner) (*Scaler, func()) {
t.Helper()

server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")

switch r.Method {
case http.MethodGet:
require.NoError(t, json.NewEncoder(w).Encode(runner))
case http.MethodPatch:
var patch v1alpha1.EphemeralRunner
require.NoError(t, json.NewDecoder(r.Body).Decode(&patch))

runner.Status.JobRequestID = patch.Status.JobRequestID
runner.Status.JobRepositoryName = patch.Status.JobRepositoryName
runner.Status.JobID = patch.Status.JobID
runner.Status.WorkflowRunID = patch.Status.WorkflowRunID
runner.Status.JobWorkflowRef = patch.Status.JobWorkflowRef
runner.Status.JobDisplayName = patch.Status.JobDisplayName
if patch.Status.Phase != "" {
runner.Status.Phase = patch.Status.Phase
}

require.NoError(t, json.NewEncoder(w).Encode(runner))
default:
http.Error(w, "unexpected method", http.StatusMethodNotAllowed)
}
}))

clientset, err := kubernetes.NewForConfig(&rest.Config{Host: server.URL})
require.NoError(t, err)

return &Scaler{
clientset: clientset,
config: Config{
EphemeralRunnerSetNamespace: runner.Namespace,
},
targetRunners: -1,
patchSeq: -1,
logger: discardLogger,
}, server.Close
}

func assertJobStartedStatus(t *testing.T, runner *v1alpha1.EphemeralRunner, jobInfo *scaleset.JobStarted) {
t.Helper()

assert.Equal(t, jobInfo.RunnerRequestID, runner.Status.JobRequestID)
assert.Equal(t, jobInfo.JobID, runner.Status.JobID)
assert.Equal(t, jobInfo.OwnerName+"/"+jobInfo.RepositoryName, runner.Status.JobRepositoryName)
assert.Equal(t, jobInfo.WorkflowRunID, runner.Status.WorkflowRunID)
assert.Equal(t, jobInfo.JobWorkflowRef, runner.Status.JobWorkflowRef)
assert.Equal(t, jobInfo.JobDisplayName, runner.Status.JobDisplayName)
}

func TestSetDesiredWorkerState_MinMaxDefaults(t *testing.T) {
newEmptyWorker := func() *Scaler {
return &Scaler{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading