Documentation
¶
Overview ¶
Package pullrequesttracker provides the Kubernetes controller for PullRequestTracker resources. This controller reconciles PullRequestTracker CRDs with GitHub PR state and manages the PR lifecycle (discovery, qualification, merge) through bidirectional synchronization.
The controller implements the hexagonal architecture pattern:
- Domain logic is in internal/domain/pr
- GitHub integration is via ports (GitHubClient interface)
- Label management is via LabelManager port
- State is persisted in Kubernetes CRDs
Reconciliation logic:
- Sync state FROM GitHub labels TO CRD status
- Update CRD conditions based on current state
- Handle state transitions and validation
- Sync state TO GitHub labels when needed (bidirectional)
The controller maintains backward compatibility with the existing prpipeline while adding Kubernetes-native state management capabilities.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GitHubClient ¶
type GitHubClient interface {
// GetPR retrieves a pull request from GitHub by number.
GetPR(ctx context.Context, repo github.Repository, number int) (*github.PullRequest, error)
// AddLabel adds a label to a pull request.
AddLabel(ctx context.Context, repo github.Repository, number int, label string) error
// RemoveLabel removes a label from a pull request.
RemoveLabel(ctx context.Context, repo github.Repository, number int, label string) error
}
GitHubClient defines the interface for GitHub operations needed by the controller. This interface abstracts GitHub API calls and allows for testing with mocks.
type LabelManager ¶
type LabelManager interface {
// GetCurrentState determines the current state from GitHub labels.
GetCurrentState(pr github.PullRequest) pr.State
// SyncToGitHub ensures GitHub labels match the desired state.
SyncToGitHub(ctx context.Context, pr github.PullRequest, state pr.State) error
}
LabelManager defines the interface for GitHub label state management. This abstracts label operations and state synchronization logic.
type Logger ¶
type Logger interface {
Info(msg string, keysAndValues ...interface{})
Error(err error, msg string, keysAndValues ...interface{})
V(level int) Logger
}
Logger defines the logging interface used by the controller.
type Reconciler ¶
type Reconciler struct {
client.Client
Scheme *runtime.Scheme
GitHubClient GitHubClient
LabelManager LabelManager
Logger Logger
}
Reconciler reconciles a PullRequestTracker object. It implements the controller-runtime reconcile.Reconciler interface.
func NewReconciler ¶
func NewReconciler( client client.Client, scheme *runtime.Scheme, githubClient GitHubClient, labelManager LabelManager, logger Logger, ) *Reconciler
NewReconciler creates a new PullRequestTracker reconciler.
Parameters:
- client: Kubernetes client for CRD operations
- scheme: Runtime scheme for type registration
- githubClient: GitHub API client interface
- labelManager: Label management interface
- logger: Logging interface
Returns a configured Reconciler ready for use with controller-runtime.
func (*Reconciler) Reconcile ¶
Reconcile implements the main reconciliation logic for PullRequestTracker resources. It is called by the controller-runtime framework whenever a PullRequestTracker resource is created, updated, or periodically re-queued.
Reconciliation steps:
- Fetch the PullRequestTracker resource
- Get current PR state from GitHub
- Sync GitHub state to CRD status
- Update CRD conditions based on state
- Handle conflicts (GitHub is source of truth)
- Update CRD status in Kubernetes
Returns:
- Result: Controls re-queuing behavior
- Error: Causes exponential backoff retry if non-nil
func (*Reconciler) SetupWithManager ¶
func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error
SetupWithManager sets up the controller with the Manager. This configures the controller to watch PullRequestTracker resources and sets up any required RBAC permissions.