Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions api/v1alpha2/runscollector_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ type RunsCollectorStatus struct {

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:printcolumn:name="Pool ID",type=string,JSONPath=`.status.agentPool.ID`
//+kubebuilder:printcolumn:name="Pool Name",type=string,JSONPath=`.status.agentPool.Name`
//+kubebuilder:printcolumn:name="Pool ID",type=string,JSONPath=`.status.agentPool.id`
//+kubebuilder:printcolumn:name="Pool Name",type=string,JSONPath=`.status.agentPool.name`
//+kubebuilder:metadata:labels="app.terraform.io/crd-schema-version=v25.11.0"

// Runs Collector scraptes HCP Terraform Run statuses from a given Agent Pool and exposes them as Prometheus-compatible metrics.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ spec:
scope: Namespaced
versions:
- additionalPrinterColumns:
- jsonPath: .status.agentPool.ID
- jsonPath: .status.agentPool.id
name: Pool ID
type: string
- jsonPath: .status.agentPool.Name
- jsonPath: .status.agentPool.name
name: Pool Name
type: string
name: v1alpha2
Expand Down
4 changes: 2 additions & 2 deletions config/crd/bases/app.terraform.io_runscollectors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ spec:
scope: Namespaced
versions:
- additionalPrinterColumns:
- jsonPath: .status.agentPool.ID
- jsonPath: .status.agentPool.id
name: Pool ID
type: string
- jsonPath: .status.agentPool.Name
- jsonPath: .status.agentPool.name
name: Pool Name
type: string
name: v1alpha2
Expand Down
1 change: 1 addition & 0 deletions internal/controller/predicates.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func deletionTimestampPredicate(o client.Object) bool {
agentTokenFinalizer,
moduleFinalizer,
projectFinalizer,
runsCollectorFinalizer,
workspaceFinalizer,
}

Expand Down
20 changes: 20 additions & 0 deletions internal/controller/runscollector_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,18 @@ func (r *RunsCollectorReconciler) SetupWithManager(mgr ctrl.Manager) error {
Complete(r)
}

func (r *RunsCollectorReconciler) removeFinalizer(ctx context.Context, rc *runsCollectorInstance) error {
controllerutil.RemoveFinalizer(&rc.instance, runsCollectorFinalizer)

err := r.Update(ctx, &rc.instance)
if err != nil {
rc.log.Error(err, "Reconcile Runs Collector", "msg", fmt.Sprintf("failed to remove finalizer %s", runsCollectorFinalizer))
r.Recorder.Eventf(&rc.instance, corev1.EventTypeWarning, "RemoveRunsCollector", "Failed to remove finalizer %s", runsCollectorFinalizer)
}

return err
}

func (r *RunsCollectorReconciler) getAgentPoolIDByName(ctx context.Context, rc *runsCollectorInstance) (*tfc.AgentPool, error) {
name := rc.instance.Spec.AgentPool.Name

Expand Down Expand Up @@ -254,6 +266,14 @@ func (r *RunsCollectorReconciler) updateStatusAgentPool(ctx context.Context, rc
}

func (r *RunsCollectorReconciler) reconcileRuns(ctx context.Context, rc *runsCollectorInstance) error {
// TODO:
// - Think if we need to reset all metrics to 0 when remove finalizer.
if isDeletionCandidate(&rc.instance, runsCollectorFinalizer) {
rc.log.Info("Reconcile Runs Collector", "msg", "object marked as deleted, need to remove finalizer")
r.Recorder.Event(&rc.instance, corev1.EventTypeNormal, "ReconcileRunsCollector", "Object marked as deleted, need to remove finalizer")
return r.removeFinalizer(ctx, rc)
}

runs := map[tfc.RunStatus]float64{}
var runsTotal float64
// TODO:
Expand Down
Loading