Skip to content

Commit 05c0b75

Browse files
authored
Add a new Runs Collector controller (#637)
1 parent 27f844f commit 05c0b75

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1288
-46
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
kind: FEATURES
2+
body: '`RunsCollector`: Introduce a new controller that scrapes HCP Terraform run statuses from a specified Agent Pool and exposes them as Prometheus-compatible metrics.'
3+
time: 2025-09-22T13:22:43.774802+02:00
4+
custom:
5+
PR: "637"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
kind: NOTES
2+
body: '`RunsCollector`: Add new Prometheus-compatible metrics `hcp_tf_runs` and `hcp_tf_runs_total` to collect pending runs by status and the total number of pending runs by status, respectively. These metrics are in the alpha stage and subject to change.'
3+
time: 2025-09-22T13:26:29.977557+02:00
4+
custom:
5+
PR: "637"

.github/workflows/helm-end-to-end-tfc.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ jobs:
8484
--set controllers.agentToken.workers=5 \
8585
--set controllers.module.workers=5 \
8686
--set controllers.project.workers=5 \
87+
--set controllers.runsCollector.workers=5 \
8788
--set controllers.workspace.workers=5
8889
8990
- name: Run end-to-end test suite

.github/workflows/helm-end-to-end-tfe.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ jobs:
8686
--set controllers.agentToken.workers=5 \
8787
--set controllers.module.workers=5 \
8888
--set controllers.project.workers=5 \
89+
--set controllers.runsCollector.workers=5 \
8990
--set controllers.workspace.workers=5
9091
9192
- name: Run end-to-end test suite

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# Every target has a BIN_NAME argument that must be provided via --build-arg=BIN_NAME=<name>
88
# when building.
99

10-
ARG GO_VERSION=1.24.3
10+
ARG GO_VERSION=1.25.1
1111

1212
# ===================================
1313
#

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ YQ = $(LOCALBIN)/yq-$(YQ_VERSION)
249249
KUSTOMIZE_VERSION ?= v5.3.0
250250
CONTROLLER_TOOLS_VERSION ?= v0.16.5
251251
ENVTEST_VERSION ?= release-0.19
252-
CRD_REF_DOCS_VERSION ?= v0.1.0
252+
CRD_REF_DOCS_VERSION ?= v0.2.0
253253
HELM_DOCS_VERSION ?= v1.14.2
254254
HASHICORP_COPYWRITE_VERSION ?= v0.19.0
255255
GOLANGCI_LINT_VERSION ?= v1.61.0

PROJECT

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,13 @@ resources:
5656
kind: AgentToken
5757
path: github.com/hashicorp/hcp-terraform-operator/api/v1alpha2
5858
version: v1alpha2
59+
- api:
60+
crdVersion: v1
61+
namespaced: true
62+
controller: true
63+
domain: terraform.io
64+
group: app
65+
kind: RunsCollector
66+
path: github.com/hashicorp/hcp-terraform-operator/api/v1alpha2
67+
version: v1alpha2
5968
version: "3"

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ The Operator can manage the following types of resources:
1919
- `AgentToken` manages [HCP Terraform Agent Tokens](https://developer.hashicorp.com/terraform/cloud-docs/users-teams-organizations/api-tokens#agent-api-tokens)
2020
- `Module` implements [API-driven Run Workflows](https://developer.hashicorp.com/terraform/cloud-docs/run/api)
2121
- `Project` manages [HCP Terraform Projects](https://developer.hashicorp.com/terraform/cloud-docs/workspaces/organize-workspaces-with-projects)
22+
- `Runs Collector` Runs scrapes HCP Terraform run statuses from a given Agent Pool and exposes them as Prometheus-compatible metrics. Learn more about [Runs](https://developer.hashicorp.com/terraform/cloud-docs/run/remote-operations).
2223
- `Workspace` manages [HCP Terraform Workspaces](https://developer.hashicorp.com/terraform/cloud-docs/workspaces)
2324

2425
## Getting started
@@ -60,6 +61,7 @@ Controllers usage guides:
6061
- [AgentToken](./docs/agenttoken.md)
6162
- [Module](./docs/module.md)
6263
- [Project](./docs/project.md)
64+
- [Runs Collector](./docs/runs_collector.md)
6365
- [Workspace](./docs/workspace.md)
6466

6567
Annotations and Labels used by HCP Terraform Operator can be found [here](./docs/annotations-and-labels.md).
@@ -115,6 +117,7 @@ If you encounter any issues with the Operator there are a number of ways how to
115117
$ kubectl get agenttoken <NAME>
116118
$ kubectl get module <NAME>
117119
$ kubectl get project <NAME>
120+
$ kubectl get runscollector <NAME>
118121
$ kubectl get workspace <NAME>
119122
```
120123

@@ -125,6 +128,7 @@ If you encounter any issues with the Operator there are a number of ways how to
125128
$ kubectl describe agenttoken <NAME>
126129
$ kubectl describe module <NAME>
127130
$ kubectl describe project <NAME>
131+
$ kubectl describe runscollector <NAME>
128132
$ kubectl describe workspace <NAME>
129133
```
130134

api/v1alpha2/project_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ type ProjectStatus struct {
193193

194194
// Project manages HCP Terraform Projects.
195195
// More information:
196-
// - https://developer.hashicorp.com/terraform/cloud-docs/projects/manage
196+
// - https://developer.hashicorp.com/terraform/cloud-docs/projects/manage
197197
type Project struct {
198198
metav1.TypeMeta `json:",inline"`
199199
metav1.ObjectMeta `json:"metadata,omitempty"`
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package v1alpha2
5+
6+
import (
7+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
8+
)
9+
10+
type RunsCollectorSpec struct {
11+
// Organization name where the Workspace will be created.
12+
// More information:
13+
// - https://developer.hashicorp.com/terraform/cloud-docs/users-teams-organizations/organizations
14+
//
15+
//+kubebuilder:validation:MinLength:=1
16+
Organization string `json:"organization"`
17+
// API Token to be used for API calls.
18+
Token Token `json:"token"`
19+
20+
// The Agent Pool name or ID from which the controller will collect runs.
21+
// More information:
22+
// - https://developer.hashicorp.com/terraform/cloud-docs/run/states
23+
AgentPool *AgentPoolRef `json:"agentPool"`
24+
}
25+
26+
type RunsCollectorStatus struct {
27+
// Real world state generation.
28+
ObservedGeneration int64 `json:"observedGeneration"`
29+
// The Agent Pool name or ID from which the controller will collect runs.
30+
AgentPool *AgentPoolRef `json:"agentPool,omitempty"`
31+
}
32+
33+
//+kubebuilder:object:root=true
34+
//+kubebuilder:subresource:status
35+
//+kubebuilder:printcolumn:name="Pool ID",type=string,JSONPath=`.status.pool.ID`
36+
//+kubebuilder:printcolumn:name="Pool Name",type=string,JSONPath=`.status.pool.Name`
37+
//+kubebuilder:metadata:labels="app.terraform.io/crd-schema-version=v25.9.0"
38+
39+
// Runs Collector scraptes HCP Terraform Run statuses from a given Agent Pool and exposes them as Prometheus-compatible metrics.
40+
// More information:
41+
// - https://developer.hashicorp.com/terraform/cloud-docs/run/remote-operations
42+
type RunsCollector struct {
43+
metav1.TypeMeta `json:",inline"`
44+
metav1.ObjectMeta `json:"metadata,omitempty"`
45+
46+
Spec RunsCollectorSpec `json:"spec"`
47+
Status RunsCollectorStatus `json:"status,omitempty"`
48+
}
49+
50+
// +kubebuilder:object:root=true
51+
52+
// RunsCollectorList contains a list of RunsCollector.
53+
type RunsCollectorList struct {
54+
metav1.TypeMeta `json:",inline"`
55+
metav1.ListMeta `json:"metadata,omitempty"`
56+
Items []RunsCollector `json:"items"`
57+
}
58+
59+
func init() {
60+
SchemeBuilder.Register(&RunsCollector{}, &RunsCollectorList{})
61+
}

0 commit comments

Comments
 (0)