Skip to content

Commit 7ca1d9f

Browse files
authored
Fix the early agent termination issue (#610)
1 parent b320735 commit 7ca1d9f

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
kind: BUG FIXES
2+
body: Fix an issue where the agent can be terminated while it still has an active run during the post-plan or post-apply stage, such as, but not limited to, Sentinel policy evaluation.
3+
time: 2025-05-27T09:27:19.677453+02:00
4+
custom:
5+
PR: "610"

internal/controller/agentpool_controller_autoscaling.go

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,6 @@ import (
1818
appv1alpha2 "github.com/hashicorp/hcp-terraform-operator/api/v1alpha2"
1919
)
2020

21-
var (
22-
runStatuses = strings.Join([]string{
23-
string(tfc.RunPlanQueued),
24-
string(tfc.RunApplyQueued),
25-
string(tfc.RunApplying),
26-
string(tfc.RunPlanning),
27-
}, ",")
28-
)
29-
3021
// matchWildcardName checks if a given string matches a specified wildcard pattern.
3122
// The wildcard pattern can contain '*' at the beginning and/or end to match any sequence of characters.
3223
// If the pattern contains '*' at both ends, the function checks if the substring exists within the string.
@@ -66,7 +57,7 @@ func pendingWorkspaceRuns(ctx context.Context, ap *agentPoolInstance) (int32, er
6657
runs := map[string]struct{}{}
6758
listOpts := &tfc.RunListForOrganizationOptions{
6859
AgentPoolNames: ap.instance.Spec.Name,
69-
Status: runStatuses,
60+
StatusGroup: "non_final",
7061
ListOptions: tfc.ListOptions{
7162
PageSize: maxPageSize,
7263
PageNumber: 1,
@@ -97,7 +88,12 @@ func computeRequiredAgents(ctx context.Context, ap *agentPoolInstance) (int32, e
9788
workspaceIDs := map[string]struct{}{}
9889

9990
listOpts := &tfc.WorkspaceListOptions{
100-
CurrentRunStatus: runStatuses,
91+
CurrentRunStatus: strings.Join([]string{
92+
string(tfc.RunPlanQueued),
93+
string(tfc.RunApplyQueued),
94+
string(tfc.RunApplying),
95+
string(tfc.RunPlanning),
96+
}, ","),
10197
ListOptions: tfc.ListOptions{
10298
PageSize: maxPageSize,
10399
PageNumber: 1,

0 commit comments

Comments
 (0)