diff --git a/controllers/horizontal_runner_autoscaler_webhook.go b/controllers/horizontal_runner_autoscaler_webhook.go index 1d5d2c145d..31e83320d4 100644 --- a/controllers/horizontal_runner_autoscaler_webhook.go +++ b/controllers/horizontal_runner_autoscaler_webhook.go @@ -668,16 +668,29 @@ HRA: if len(hra.Spec.ScaleUpTriggers) > 1 { autoscaler.Log.V(1).Info("Skipping this HRA as it has too many ScaleUpTriggers to be used in workflow_job based scaling", "hra", hra.Name) + continue + } + + if len(hra.Spec.ScaleUpTriggers) == 0 { + autoscaler.Log.V(1).Info("Skipping this HRA as it has no ScaleUpTriggers configured", "hra", hra.Name) + continue + } + + scaleUpTrigger := hra.Spec.ScaleUpTriggers[0] + + if scaleUpTrigger.GitHubEvent == nil { + autoscaler.Log.V(1).Info("Skipping this HRA as it has no `githubEvent` scale trigger configured", "hra", hra.Name) continue } - var duration metav1.Duration + if scaleUpTrigger.GitHubEvent.WorkflowJob == nil { + autoscaler.Log.V(1).Info("Skipping this HRA as it has no `githubEvent.workflowJob` scale trigger configured", "hra", hra.Name) - if len(hra.Spec.ScaleUpTriggers) > 0 { - duration = hra.Spec.ScaleUpTriggers[0].Duration + continue } + duration := scaleUpTrigger.Duration if duration.Duration <= 0 { // Try to release the reserved capacity after at least 10 minutes by default, // we won't end up in the reserved capacity remained forever in case GitHub somehow stopped sending us "completed" workflow_job events. diff --git a/controllers/horizontal_runner_autoscaler_webhook_test.go b/controllers/horizontal_runner_autoscaler_webhook_test.go index 7d31c854b0..54a3ea8480 100644 --- a/controllers/horizontal_runner_autoscaler_webhook_test.go +++ b/controllers/horizontal_runner_autoscaler_webhook_test.go @@ -138,6 +138,13 @@ func TestWebhookWorkflowJob(t *testing.T) { ScaleTargetRef: actionsv1alpha1.ScaleTargetRef{ Name: "test-name", }, + ScaleUpTriggers: []actionsv1alpha1.ScaleUpTrigger{ + { + GitHubEvent: &actionsv1alpha1.GitHubEventScaleUpTriggerSpec{ + WorkflowJob: &actionsv1alpha1.WorkflowJobSpec{}, + }, + }, + }, }, } @@ -177,6 +184,13 @@ func TestWebhookWorkflowJob(t *testing.T) { ScaleTargetRef: actionsv1alpha1.ScaleTargetRef{ Name: "test-name", }, + ScaleUpTriggers: []actionsv1alpha1.ScaleUpTrigger{ + { + GitHubEvent: &actionsv1alpha1.GitHubEventScaleUpTriggerSpec{ + WorkflowJob: &actionsv1alpha1.WorkflowJobSpec{}, + }, + }, + }, }, } @@ -217,6 +231,13 @@ func TestWebhookWorkflowJob(t *testing.T) { ScaleTargetRef: actionsv1alpha1.ScaleTargetRef{ Name: "test-name", }, + ScaleUpTriggers: []actionsv1alpha1.ScaleUpTrigger{ + { + GitHubEvent: &actionsv1alpha1.GitHubEventScaleUpTriggerSpec{ + WorkflowJob: &actionsv1alpha1.WorkflowJobSpec{}, + }, + }, + }, }, } @@ -277,6 +298,13 @@ func TestWebhookWorkflowJobWithSelfHostedLabel(t *testing.T) { ScaleTargetRef: actionsv1alpha1.ScaleTargetRef{ Name: "test-name", }, + ScaleUpTriggers: []actionsv1alpha1.ScaleUpTrigger{ + { + GitHubEvent: &actionsv1alpha1.GitHubEventScaleUpTriggerSpec{ + WorkflowJob: &actionsv1alpha1.WorkflowJobSpec{}, + }, + }, + }, }, } @@ -316,6 +344,13 @@ func TestWebhookWorkflowJobWithSelfHostedLabel(t *testing.T) { ScaleTargetRef: actionsv1alpha1.ScaleTargetRef{ Name: "test-name", }, + ScaleUpTriggers: []actionsv1alpha1.ScaleUpTrigger{ + { + GitHubEvent: &actionsv1alpha1.GitHubEventScaleUpTriggerSpec{ + WorkflowJob: &actionsv1alpha1.WorkflowJobSpec{}, + }, + }, + }, }, } @@ -356,6 +391,13 @@ func TestWebhookWorkflowJobWithSelfHostedLabel(t *testing.T) { ScaleTargetRef: actionsv1alpha1.ScaleTargetRef{ Name: "test-name", }, + ScaleUpTriggers: []actionsv1alpha1.ScaleUpTrigger{ + { + GitHubEvent: &actionsv1alpha1.GitHubEventScaleUpTriggerSpec{ + WorkflowJob: &actionsv1alpha1.WorkflowJobSpec{}, + }, + }, + }, }, } diff --git a/controllers/integration_test.go b/controllers/integration_test.go index f5c79fec09..1ff989c46d 100644 --- a/controllers/integration_test.go +++ b/controllers/integration_test.go @@ -1228,9 +1228,11 @@ var _ = Context("INTEGRATION: Inside of a new namespace", func() { ScaleDownDelaySecondsAfterScaleUp: intPtr(1), ScaleUpTriggers: []actionsv1alpha1.ScaleUpTrigger{ { - GitHubEvent: &actionsv1alpha1.GitHubEventScaleUpTriggerSpec{}, - Amount: 1, - Duration: metav1.Duration{Duration: time.Minute}, + GitHubEvent: &actionsv1alpha1.GitHubEventScaleUpTriggerSpec{ + WorkflowJob: &actionsv1alpha1.WorkflowJobSpec{}, + }, + Amount: 1, + Duration: metav1.Duration{Duration: time.Minute}, }, }, }, @@ -1310,9 +1312,11 @@ var _ = Context("INTEGRATION: Inside of a new namespace", func() { ScaleDownDelaySecondsAfterScaleUp: intPtr(1), ScaleUpTriggers: []actionsv1alpha1.ScaleUpTrigger{ { - GitHubEvent: &actionsv1alpha1.GitHubEventScaleUpTriggerSpec{}, - Amount: 1, - Duration: metav1.Duration{Duration: time.Minute}, + GitHubEvent: &actionsv1alpha1.GitHubEventScaleUpTriggerSpec{ + WorkflowJob: &actionsv1alpha1.WorkflowJobSpec{}, + }, + Amount: 1, + Duration: metav1.Duration{Duration: time.Minute}, }, }, },