Codebase Walkthrough
Codebase Walkthrough
Repository Structure
The Prow repository follows a standard Go project layout with clear separation of concerns:
prow/
├── cmd/ # Command-line tools and applications
├── pkg/ # Shared libraries and packages
├── config/ # Configuration examples
├── site/ # Documentation site
├── test/ # Test files and test data
├── hack/ # Build scripts and utilities
├── Makefile # Build automation
├── go.mod # Go module definition
├── go.sum # Go module checksums
├── README.md # Main README
├── CONTRIBUTING.md # Contribution guidelines
└── OWNERS # Code owners file
Directory Details
/cmd - Command-Line Tools
This directory contains all executable Prow components. Each subdirectory represents a standalone service or tool.
Core Components
Webhook and Event Handling:
hook/- Main webhook server that processes GitHub/Gerrit eventswebhook-server/- Webhook server with admission controlghproxy/- GitHub API proxy with cachinghmac/- HMAC signature validation
Job Management:
prow-controller-manager/- Main controller managerplank/- Creates and manages Pods for jobsscheduler/- Distributes jobs across clusterssinker/- Cleans up old ProwJobs and Podshorologium/- Triggers periodic jobs
Status and Reporting:
crier/- Reports job status to GitHub/Gerrit/Slackstatus-reconciler/- Reconciles GitHub commit statusdeck/- Web UI for viewing jobs and resultsexporter/- Exports metrics
Automation:
tide/- Automated PR mergingperibolos/- GitHub organization managementbranchprotector/- Branch protection management
Job Utilities:
clonerefs/- Clones git repositoriesinitupload/- Initializes job artifactsentrypoint/- Job entrypoint wrappersidecar/- Sidecar container for log uploadgcsupload/- Uploads artifacts to GCStot/- Test of tests (version management)
Developer Tools:
mkpj/- Create ProwJob YAMLmkpod/- Create Pod YAMLcheckconfig/- Validate Prow configurationconfig-bootstrapper/- Bootstrap Prow config
External Integrations:
gerrit/- Gerrit integrationjenkins-operator/- Jenkins operatorpipeline/- Tekton pipeline controllergangway/- OAuth servermoonraker/- Config server
External Plugins:
external-plugins/cherrypicker/- Cherry-pick pluginexternal-plugins/needs-rebase/- Rebase checkerexternal-plugins/refresh/- Refresh plugin
Component Structure Pattern
Each component typically follows this structure:
cmd/component-name/
├── main.go # Entry point
├── main_test.go # Tests
├── OWNERS # Code owners (if applicable)
└── ... # Component-specific files
/pkg - Shared Packages
This directory contains reusable Go packages used across multiple components.
Key Packages
Core API:
pkg/apis/prowjobs/- ProwJob Custom Resource definitionsv1/types.go- ProwJob typesv1/register.go- API registration
Configuration:
pkg/config/- Configuration loading and managementconfig.go- Main config structuresjobs.go- Job configurationtide.go- Tide configurationplugins.go- Plugin configuration
Core Components:
pkg/hook/- Webhook handling logicpkg/plank/- Pod creation and managementpkg/scheduler/- Job scheduling logicpkg/tide/- PR merging logicpkg/crier/- Status reportingpkg/sinker/- Cleanup logic
Plugin System:
pkg/plugins/- Plugin implementations- Individual plugin packages (approve, lgtm, etc.)
- Plugin framework
Git Integration:
pkg/github/- GitHub API clientpkg/gerrit/- Gerrit integrationpkg/git/- Git utilitiespkg/clonerefs/- Repository cloning
Job Utilities:
pkg/pod-utils/- Pod utility functionspkg/entrypoint/- Entrypoint logicpkg/initupload/- Init upload logicpkg/sidecar/- Sidecar logicpkg/gcsupload/- GCS upload logic
UI Components:
pkg/deck/- Deck UI backendpkg/spyglass/- Spyglass artifact viewer
Utilities:
pkg/util/- General utilitiespkg/pjutil/- ProwJob utilitiespkg/kube/- Kubernetes client utilitiespkg/flagutil/- Flag utilitiespkg/metrics/- Metrics collectionpkg/logrusutil/- Logging utilities
Specialized:
pkg/repoowners/- OWNERS file parsingpkg/labels/- Label managementpkg/markdown/- Markdown processingpkg/slack/- Slack integrationpkg/jira/- Jira integrationpkg/bugzilla/- Bugzilla integration
/config - Configuration Examples
Example Prow configurations:
prow/cluster/- Cluster configurations- Example job configs
- Plugin configs
/site - Documentation Site
Hugo-based documentation site:
- Static site generation
- Documentation content
- API documentation
/test - Test Files
test/integration/- Integration test suites- Test data files
/hack - Build Scripts
Utility scripts for development and CI:
hack/make-rules/- Makefile ruleshack/scripts/- Utility scriptshack/tools/- Development tools
Key Files and Modules
Main Entry Points
Hook (cmd/hook/main.go):
- Main webhook server
- Processes GitHub/Gerrit events
- Executes plugins
- Creates ProwJobs
Controller Manager (cmd/prow-controller-manager/main.go):
- Runs plank and scheduler controllers
- Manages ProwJob lifecycle
- Coordinates job execution
Plank (pkg/plank/):
- Creates Pods from ProwJobs
- Manages Pod lifecycle
- Updates ProwJob status
Tide (cmd/tide/main.go):
- Monitors PRs for merge eligibility
- Automatically merges PRs
- Manages merge pools
Core Components
ProwJob API (pkg/apis/prowjobs/v1/types.go):
type ProwJob struct {
Spec ProwJobSpec
Status ProwJobStatus
}
type ProwJobSpec struct {
Type ProwJobType // presubmit, postsubmit, periodic, batch
Job string
Refs Refs
PodSpec *corev1.PodSpec
// ...
}
Configuration (pkg/config/config.go):
Config- Main configuration structureJobConfig- Job configurationsTideConfig- Tide configurationPluginConfig- Plugin configuration
Plugin Interface (pkg/plugins/):
- Plugins implement specific interfaces
- Hook loads and executes plugins
- Plugins can create comments, labels, etc.
Component Interactions
How Hook Works
-
Webhook Reception (
cmd/hook/main.go):- Receives webhook from GitHub/Gerrit
- Validates HMAC signature
- Parses event payload
-
Plugin Execution (
pkg/hook/server.go):- Loads plugin configuration
- Executes relevant plugins
- Plugins can create ProwJobs
-
ProwJob Creation (
pkg/kube/):- Creates ProwJob CRD
- Controller picks up ProwJob
How Controller Manager Works
-
ProwJob Watching (
pkg/plank/):- Watches for new ProwJobs
- Determines if Pod should be created
-
Pod Creation (
pkg/plank/):- Creates Pod from ProwJob spec
- Manages Pod lifecycle
- Updates ProwJob status
-
Scheduling (
pkg/scheduler/):- Selects cluster for job
- Distributes load across clusters
How Tide Works
-
PR Monitoring (
pkg/tide/):- Queries GitHub for PRs
- Checks merge eligibility
-
Merge Eligibility (
pkg/tide/):- All tests pass
- Required approvals present
- No merge conflicts
- Branch protection satisfied
-
Merging (
pkg/tide/):- Merges PR when eligible
- Updates status
How Plugins Work
-
Plugin Loading (
pkg/hook/):- Loads plugin configuration
- Initializes plugins
-
Plugin Execution (
pkg/plugins/):- Hook calls plugin handlers
- Plugins process events
- Plugins can modify state
-
Plugin Actions:
- Create comments
- Add/remove labels
- Create ProwJobs
- Update status
Key Classes and Functions
Hook Core
Main Function (cmd/hook/main.go:main):
- Entry point for hook
- Sets up HTTP server
- Registers webhook handler
Server (pkg/hook/server.go):
ServeHTTP()- Handles webhook requestshandleWebhook()- Processes webhookhandlePluginEvent()- Executes plugins
Controller Core
Plank Controller (pkg/plank/):
syncProwJob()- Syncs ProwJob statecreatePod()- Creates Pod for jobupdateProwJob()- Updates ProwJob status
Scheduler Controller (pkg/scheduler/):
syncProwJob()- Schedules job to clusterselectCluster()- Selects target cluster
Tide Core
Tide Controller (pkg/tide/):
sync()- Syncs PR stateisMergeable()- Checks merge eligibilitymergePRs()- Merges eligible PRs
Plugin Framework
Plugin Interface:
type PluginClient interface {
// Plugin-specific methods
}
Common Plugins:
pkg/plugins/approve/- Approval pluginpkg/plugins/lgtm/- LGTM pluginpkg/plugins/trigger/- Job trigger plugin
API Surface
ProwJob API
ProwJob Resource:
type ProwJob struct {
metav1.TypeMeta
metav1.ObjectMeta
Spec ProwJobSpec
Status ProwJobStatus
}
Job Types:
Presubmit- Run on PRsPostsubmit- Run after mergePeriodic- Run on scheduleBatch- Run multiple jobs
Configuration API
Config Structure:
type Config struct {
ProwConfig ProwConfig
JobConfig JobConfig
Tide TideConfig
Plank PlankConfig
// ...
}
Data Flow
-
Webhook Flow:
- GitHub sends webhook
- Hook validates and processes
- Plugins execute
- ProwJob created
-
Job Execution Flow:
- Controller reconciles ProwJob
- Plank creates Pod
- Pod executes job
- Artifacts uploaded
- Status updated
-
Status Reporting Flow:
- Job completes
- Crier reads status
- Reports to GitHub/Slack
- Updates commit status
Testing Structure
- Unit Tests:
*_test.gofiles alongside source - Integration Tests:
test/integration/directory - Test Data:
testdata/directories in packages
Build System
- Makefile: Main build automation
- Go Modules: Dependency management
- Ko: Container image builds
- CI/CD: Automated testing and deployment
Extension Points
- Custom Plugins: Add to
pkg/plugins/ - Custom Controllers: Add to controller manager
- Custom Reporters: Add to
pkg/crier/reporters/ - Custom Job Types: Extend ProwJob spec
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.