pullrequesttracker

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2026 License: GPL-3.0 Imports: 14 Imported by: 0

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:

  1. Sync state FROM GitHub labels TO CRD status
  2. Update CRD conditions based on current state
  3. Handle state transitions and validation
  4. 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

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

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:

  1. Fetch the PullRequestTracker resource
  2. Get current PR state from GitHub
  3. Sync GitHub state to CRD status
  4. Update CRD conditions based on state
  5. Handle conflicts (GitHub is source of truth)
  6. 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.

Jump to

Keyboard shortcuts

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