Skip to content

Commit 517cbcf

Browse files
Remove unecessary interface
1 parent b851d24 commit 517cbcf

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

internal/controller/agentpool_controller_autoscaling.go

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

21-
type AgentPoolControllerAutoscaling interface {
22-
pendingWorkspaceRuns(ctx context.Context, ap *agentPoolInstance) (int32, error)
23-
}
24-
2521
// userInteractionRunStatuses contains run statuses that require user interaction.
2622
var userInteractionRunStatuses = map[tfc.RunStatus]struct{}{
2723
tfc.RunCostEstimated: {},
@@ -67,7 +63,7 @@ func matchWildcardName(wildcard string, str string) bool {
6763

6864
// pendingWorkspaceRuns returns the number pending runs for a given agent pool.
6965
// This function is compatible with HCP Terraform and TFE version v202409-1 and later.
70-
func (ap *agentPoolInstance) pendingWorkspaceRuns(ctx context.Context) (int32, error) {
66+
func pendingWorkspaceRuns(ctx context.Context, ap *agentPoolInstance) (int32, error) {
7167
runs := map[string]struct{}{}
7268
awaitingUserInteractionRuns := map[string]int{} // Track runs awaiting user interaction by status for future metrics
7369
listOpts := &tfc.RunListForOrganizationOptions{
@@ -113,7 +109,7 @@ func (ap *agentPoolInstance) pendingWorkspaceRuns(ctx context.Context) (int32, e
113109

114110
// computeRequiredAgents is a legacy algorithm that is used to compute the number of agents needed.
115111
// It is used when the TFE version is less than v202409-1.
116-
func (ap *agentPoolInstance) computeRequiredAgents(ctx context.Context) (int32, error) {
112+
func computeRequiredAgents(ctx context.Context, ap *agentPoolInstance) (int32, error) {
117113
required := 0
118114
// NOTE:
119115
// - Two maps are used here to simplify target workspace searching by ID, name, and wildcard.
@@ -252,7 +248,7 @@ func (r *AgentPoolReconciler) reconcileAgentAutoscaling(ctx context.Context, ap
252248

253249
requiredAgents, err := func() (int32, error) {
254250
if ap.tfClient.Client.IsCloud() {
255-
return ap.pendingWorkspaceRuns(ctx)
251+
return pendingWorkspaceRuns(ctx, ap)
256252
}
257253
tfeVersion := ap.tfClient.Client.RemoteTFEVersion()
258254
useRunsEndpoint, err := validateTFEVersion(tfeVersion)
@@ -266,10 +262,10 @@ func (r *AgentPoolReconciler) reconcileAgentAutoscaling(ctx context.Context, ap
266262
// It now allows retrieving a list of runs for the organization.
267263
if useRunsEndpoint {
268264
ap.log.Info("Reconcile Agent Autoscaling", "msg", fmt.Sprintf("Proceeding with the new algorithm based on the detected TFE version %s", tfeVersion))
269-
return ap.pendingWorkspaceRuns(ctx)
265+
return pendingWorkspaceRuns(ctx, ap)
270266
}
271267
ap.log.Info("Reconcile Agent Autoscaling", "msg", fmt.Sprintf("Proceeding with the legacy algorithm based to the detected TFE version %s", tfeVersion))
272-
return ap.computeRequiredAgents(ctx)
268+
return computeRequiredAgents(ctx, ap)
273269
}()
274270
if err != nil {
275271
ap.log.Error(err, "Reconcile Agent Autoscaling", "msg", "Failed to get agents needed")

internal/controller/agentpool_controller_autoscaling_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ func TestPendingWorkspaceRuns(t *testing.T) {
276276
log: logr.Logger{},
277277
}
278278

279-
count, err := ap.pendingWorkspaceRuns(context.Background())
279+
count, err := pendingWorkspaceRuns(context.Background(), ap)
280280
if tt.expectError {
281281
assert.Error(t, err)
282282
} else {

0 commit comments

Comments
 (0)