remediation

package
v0.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 22, 2026 License: MIT Imports: 23 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package remediation is the remediation-controller's engine — three reconcilers over the Finding/Remediation kinds:

The spawner is the queue-admission writer: it turns approvals and revivals into Queued findings and materializes one immutable, Pending Remediation child per attempt, stamped with its scheduling priority (internal/priority). The remediation reconciler grants bounded slots to pending remediations in priority order (internal/schedule), launches the coding agent in an ephemeral Kubernetes Job, and applies the result when the Job completes: on success it replays the agent's changeset through the forge write seam (internal/forge + internal/ghpush — the only holder of a forge write credential) and opens the pull request; on failure it re-queues or exhausts the finding. Merging stays human; the merge webhook (integration-controller) completes the finding.

The binary also hosts internal/controller/rollup — the all-time statistics aggregation and the finding TTL.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CRRunner

type CRRunner interface {
	Create(ctx context.Context, spec jobs.Spec) (string, error)
	Result(ctx context.Context, jobName string) ([]envelope.Event, error)
	Status(ctx context.Context, jobName string) (jobs.Status, error)
	Delete(ctx context.Context, jobName string) error
}

CRRunner is the slice of the jobs client the CRD-native remediation engine needs (distinct name: the legacy Runner interface lives in controller.go until the cutover).

type ForgeWriter

type ForgeWriter interface {
	// Push replays the changeset as branch on the repository.
	Push(ctx context.Context, namespace, repoURL, branch string, cs *envelope.Changeset) error
	// EnsurePR opens (or finds, idempotently by head branch) the pull
	// request for branch.
	EnsurePR(ctx context.Context, namespace, repoURL, branch, title, body string) (number int64, url string, err error)
}

ForgeWriter performs the two forge writes remediation owns: the branch push (Git Data API, scoped write token) and the pull request. It wraps internal/forge + internal/ghpush; tests substitute a fake.

func NewForgeWriter

func NewForgeWriter(forges *forge.Store) ForgeWriter

NewForgeWriter builds the production ForgeWriter over the shared forge store.

type RemediationReconciler

type RemediationReconciler struct {
	client.Client
	// Runner creates and observes agent Jobs.
	Runner CRRunner
	// Forge performs the branch push and PR creation.
	Forge ForgeWriter
	// Namespace the CRs live in.
	Namespace string
	// MaxConcurrent bounds simultaneously running remediations (default 1).
	MaxConcurrent int
	// MaxAttempts bounds remediation attempts per finding.
	MaxAttempts int32
	// Aging lifts long-waiting remediations.
	Aging schedule.AgingPolicy
	// Now is the clock seam; nil means time.Now.
	Now func() time.Time
	// Log receives diagnostics; nil discards.
	Log *slog.Logger
}

RemediationReconciler grants bounded slots to pending remediations in priority order, launches the agent Job, and applies results: push + PR on success, retry or exhaustion on failure.

func (*RemediationReconciler) Reconcile

func (r *RemediationReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error)

Reconcile handles the singleton scheduler request and per-object runs.

func (*RemediationReconciler) SetupWithManager

func (r *RemediationReconciler) SetupWithManager(mgr ctrl.Manager) error

SetupWithManager wires the reconciler and its scheduler fan-in.

type SpawnerReconciler

type SpawnerReconciler struct {
	client.Client
	// Namespace the CRs live in.
	Namespace string
	// Weights tune the scheduling-priority computation.
	Weights priority.Weights
	// Now is the clock seam; nil means time.Now.
	Now func() time.Time
	// Log receives diagnostics; nil discards.
	Log *slog.Logger
}

SpawnerReconciler is the queue-admission writer: it turns approvals and revivals into Queued findings (edges 10 and 18) and materializes one Pending Remediation per attempt for every Queued finding, stamped with its scheduling priority.

func (*SpawnerReconciler) Reconcile

func (r *SpawnerReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error)

Reconcile advances one finding through queue admission.

func (*SpawnerReconciler) SetupWithManager

func (r *SpawnerReconciler) SetupWithManager(mgr ctrl.Manager) error

SetupWithManager wires the spawner.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL