Skip to content

Commit 6026376

Browse files
committed
Add comprehensive beginner-friendly documentation package
1 parent 472c375 commit 6026376

File tree

10 files changed

+3229
-0
lines changed

10 files changed

+3229
-0
lines changed

docs/ARCHITECTURE.md

Lines changed: 407 additions & 0 deletions
Large diffs are not rendered by default.

docs/CODEBASE_WALKTHROUGH.md

Lines changed: 388 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,388 @@
1+
# Codebase Walkthrough
2+
3+
## Repository Structure
4+
5+
The CI-Tools repository follows a standard Go project layout with clear separation of concerns:
6+
7+
```
8+
ci-tools/
9+
├── cmd/ # Command-line tools and applications
10+
├── pkg/ # Shared libraries and packages
11+
├── test/ # Test files and test data
12+
├── hack/ # Build scripts and utilities
13+
├── images/ # Container image definitions
14+
├── vendor/ # Vendored dependencies
15+
├── docs/ # Documentation (this directory)
16+
├── Makefile # Build automation
17+
├── go.mod # Go module definition
18+
├── go.sum # Go module checksums
19+
├── README.md # Main README
20+
├── CONTRIBUTING.md # Contribution guidelines
21+
└── OWNERS # Code owners file
22+
```
23+
24+
## Directory Details
25+
26+
### `/cmd` - Command-Line Tools
27+
28+
This directory contains all executable tools. Each subdirectory represents a standalone command-line application.
29+
30+
#### Key Tools by Category
31+
32+
**Core CI Tools:**
33+
- `ci-operator/` - Main CI orchestration engine
34+
- `ci-operator-prowgen/` - Generates Prow jobs from ci-operator configs
35+
- `ci-operator-checkconfig/` - Validates ci-operator configurations
36+
- `ci-operator-configresolver/` - Resolves ci-operator config references
37+
38+
**Configuration Management:**
39+
- `config-brancher/` - Propagates configs to release branches
40+
- `autoconfigbrancher/` - Orchestrates multiple config tools
41+
- `determinize-ci-operator/` - Normalizes CI configs
42+
- `ci-operator-yaml-creator/` - Creates CI configs from templates
43+
44+
**Image Management:**
45+
- `registry-replacer/` - Replaces registry references
46+
- `ci-images-mirror/` - Mirrors images between registries
47+
- `promoted-image-governor/` - Manages image promotion
48+
- `clusterimageset-updater/` - Updates cluster image sets
49+
50+
**Secret Management:**
51+
- `ci-secret-generator/` - Generates secrets from templates
52+
- `ci-secret-bootstrap/` - Bootstraps secrets for repos
53+
- `gsm-secret-sync/` - Syncs secrets from Google Secret Manager
54+
- `vault-secret-collection-manager/` - Web UI for Vault secrets
55+
56+
**Cluster Management:**
57+
- `cluster-init/` - Initializes test clusters
58+
- `dptp-controller-manager/` - Main Kubernetes controller manager
59+
- `cluster-display/` - Displays cluster information
60+
61+
**Job Management:**
62+
- `prow-job-dispatcher/` - Dispatches jobs to clusters
63+
- `job-run-aggregator/` - Aggregates job run data
64+
- `result-aggregator/` - Aggregates test results
65+
- `retester/` - Retests failed jobs
66+
67+
**Developer Tools:**
68+
- `repo-init/` - Web UI/API for repo initialization
69+
- `prcreator/` - Creates pull requests
70+
- `backport-verifier/` - Verifies backports
71+
- `blocking-issue-creator/` - Creates blocking issues
72+
73+
**Analytics & Monitoring:**
74+
- `pod-scaler/` - Analyzes and recommends resource usage
75+
- `lensserver/` - Provides CI insights
76+
- `job-run-aggregator/` - Job performance analysis
77+
78+
#### Tool Structure Pattern
79+
80+
Each tool typically follows this structure:
81+
82+
```
83+
cmd/tool-name/
84+
├── main.go # Entry point
85+
├── README.md # Tool-specific documentation
86+
├── testdata/ # Test data (if applicable)
87+
└── ... # Additional tool-specific files
88+
```
89+
90+
### `/pkg` - Shared Packages
91+
92+
This directory contains reusable Go packages used across multiple tools.
93+
94+
#### Key Packages
95+
96+
**Core API:**
97+
- `pkg/api/` - Core data structures and types
98+
- `config.go` - CI operator configuration types
99+
- `types.go` - Common type definitions
100+
- `graph.go` - Dependency graph implementation
101+
- `promotion.go` - Image promotion logic
102+
103+
**Configuration:**
104+
- `pkg/config/` - Configuration loading and management
105+
- `pkg/defaults/` - Default value handling
106+
- `pkg/validation/` - Configuration validation
107+
108+
**CI Operator Components:**
109+
- `pkg/steps/` - Step execution framework
110+
- `pkg/registry/` - Step registry management
111+
- `pkg/prowgen/` - Prow job generation
112+
- `pkg/rehearse/` - Job rehearsal logic
113+
114+
**Kubernetes Integration:**
115+
- `pkg/kubernetes/` - Kubernetes client utilities
116+
- `pkg/controller/` - Controller implementations
117+
- `pkg/dispatcher/` - Job dispatching logic
118+
119+
**Utilities:**
120+
- `pkg/util/` - General utilities
121+
- `pkg/junit/` - JUnit XML handling
122+
- `pkg/github/` - GitHub API integration
123+
- `pkg/jira/` - Jira integration
124+
- `pkg/slack/` - Slack integration
125+
126+
**Specialized:**
127+
- `pkg/jobrunaggregator/` - Job run analysis
128+
- `pkg/pod-scaler/` - Resource scaling logic
129+
- `pkg/clusterinit/` - Cluster initialization
130+
- `pkg/gsm-secrets/` - Google Secret Manager integration
131+
132+
### `/test` - Test Files
133+
134+
Contains integration tests, end-to-end tests, and test data:
135+
136+
- `test/integration/` - Integration test suites
137+
- `test/e2e/` - End-to-end tests
138+
- Test data files for various tools
139+
140+
### `/hack` - Build Scripts
141+
142+
Utility scripts for development and CI:
143+
144+
- `hack/install.sh` - Installation script
145+
- `hack/test-go.sh` - Go test runner
146+
- `hack/lint.sh` - Linting script
147+
- `hack/update-codegen.sh` - Code generation
148+
- `hack/build-and-push.sh` - Image build script
149+
150+
### `/images` - Container Images
151+
152+
Container image definitions for various tools (67 files).
153+
154+
## Key Files and Modules
155+
156+
### Main Entry Points
157+
158+
**CI Operator (`cmd/ci-operator/main.go`):**
159+
- Main orchestration engine
160+
- Parses YAML configurations
161+
- Builds dependency graphs
162+
- Executes build and test steps
163+
- Handles image promotion
164+
165+
**Controller Manager (`cmd/dptp-controller-manager/main.go`):**
166+
- Runs multiple Kubernetes controllers
167+
- Manages CI resources
168+
- Handles reconciliation loops
169+
170+
### Core Components
171+
172+
**API Package (`pkg/api/`):**
173+
- `config.go` - CI operator configuration structures
174+
- `graph.go` - Dependency graph for build steps
175+
- `types.go` - Common type definitions
176+
- `promotion.go` - Image promotion logic
177+
178+
**Steps Package (`pkg/steps/`):**
179+
- Step execution framework
180+
- Individual step implementations (build, test, template, etc.)
181+
- Step registry for reusable steps
182+
183+
**Prowgen Package (`pkg/prowgen/`):**
184+
- Converts ci-operator configs to Prow job configs
185+
- Handles job naming and organization
186+
- Manages job dependencies
187+
188+
## Component Interactions
189+
190+
### How CI Operator Works
191+
192+
1. **Configuration Loading** (`pkg/config/load.go`):
193+
- Loads YAML configuration
194+
- Resolves references and includes
195+
- Validates configuration
196+
197+
2. **Graph Building** (`pkg/api/graph.go`):
198+
- Builds dependency graph from config
199+
- Determines execution order
200+
- Identifies parallel execution opportunities
201+
202+
3. **Step Execution** (`pkg/steps/`):
203+
- Executes steps in dependency order
204+
- Manages Kubernetes resources
205+
- Collects artifacts
206+
- Handles errors and retries
207+
208+
4. **Image Promotion** (`pkg/promotion/`):
209+
- Tags images to release streams
210+
- Updates ImageStreams
211+
- Handles promotion policies
212+
213+
### How Configuration Management Works
214+
215+
1. **Config Brancher** (`cmd/config-brancher/`):
216+
- Reads ci-operator configs from openshift/release
217+
- Identifies repos promoting to current release
218+
- Copies configs to future release branches
219+
- Disables promotion conflicts
220+
221+
2. **Prowgen** (`cmd/ci-operator-prowgen/`):
222+
- Reads ci-operator configs
223+
- Generates Prow job YAML files
224+
- Organizes jobs by org/repo/branch
225+
- Handles periodic, presubmit, postsubmit jobs
226+
227+
3. **Autoconfigbrancher** (`cmd/autoconfigbrancher/`):
228+
- Orchestrates multiple config tools
229+
- Runs tools in sequence
230+
- Creates PRs with changes
231+
- Auto-merges approved PRs
232+
233+
### How Controllers Work
234+
235+
1. **Controller Manager** (`cmd/dptp-controller-manager/`):
236+
- Initializes multiple controllers
237+
- Manages controller lifecycle
238+
- Handles graceful shutdown
239+
240+
2. **Individual Controllers** (`pkg/controller/`):
241+
- Watch Kubernetes resources
242+
- Reconcile desired state
243+
- Handle errors and retries
244+
- Update resource status
245+
246+
## Key Classes and Functions
247+
248+
### CI Operator Core
249+
250+
**Main Function** (`cmd/ci-operator/main.go:main`):
251+
- Entry point for ci-operator
252+
- Parses flags and configuration
253+
- Initializes clients
254+
- Executes build workflow
255+
256+
**Run Function** (`cmd/ci-operator/main.go:run`):
257+
- Main execution logic
258+
- Builds dependency graph
259+
- Executes steps
260+
- Handles promotion
261+
262+
**Graph Building** (`pkg/api/graph.go`):
263+
- `BuildPartialGraph()` - Builds graph for specific targets
264+
- `TopologicalSort()` - Sorts nodes by dependencies
265+
- `ResolveMultiArch()` - Resolves multi-arch requirements
266+
267+
**Step Execution** (`pkg/steps/run.go`):
268+
- `Run()` - Executes step graph
269+
- `executeStep()` - Executes individual step
270+
- `collectArtifacts()` - Collects step artifacts
271+
272+
### Configuration Management
273+
274+
**Config Loading** (`pkg/config/load.go`):
275+
- `LoadConfig()` - Loads CI operator config
276+
- `LoadConfigByFilename()` - Loads specific config file
277+
- `ResolveConfig()` - Resolves config references
278+
279+
**Prowgen** (`pkg/prowgen/jobconfig.go`):
280+
- `GenerateJobs()` - Generates Prow jobs from config
281+
- `GeneratePresubmits()` - Generates presubmit jobs
282+
- `GeneratePostsubmits()` - Generates postsubmit jobs
283+
- `GeneratePeriodics()` - Generates periodic jobs
284+
285+
### Controller Pattern
286+
287+
**Reconciler Interface** (`pkg/controller/util/reconciler.go`):
288+
- `Reconcile()` - Main reconciliation function
289+
- Standard interface for all controllers
290+
291+
**Promotion Reconciler** (`pkg/controller/promotionreconciler/`):
292+
- Watches ImageStreams
293+
- Promotes images based on policies
294+
- Updates release streams
295+
296+
**Ephemeral Cluster Controller** (`pkg/controller/ephemeralcluster/`):
297+
- Manages ephemeral test clusters
298+
- Provisions clusters on demand
299+
- Cleans up expired clusters
300+
301+
## API Surface
302+
303+
### CI Operator API
304+
305+
**Configuration Structure** (`pkg/api/config.go`):
306+
```go
307+
type ReleaseBuildConfiguration struct {
308+
// Input configuration
309+
InputConfiguration
310+
311+
// Build configuration
312+
BuildRoot
313+
Images
314+
Tests
315+
316+
// Promotion configuration
317+
Promotion
318+
319+
// Release configuration
320+
ReleaseTagConfiguration
321+
}
322+
```
323+
324+
**Step Interface** (`pkg/steps/step.go`):
325+
```go
326+
type Step interface {
327+
Inputs() []api.InputDefinition
328+
Validate() error
329+
Run(ctx context.Context) error
330+
Requires() []api.StepLink
331+
Creates() []api.StepLink
332+
Provides() (api.ParameterMap, error)
333+
}
334+
```
335+
336+
### Controller API
337+
338+
**Reconciler Interface**:
339+
```go
340+
type Reconciler interface {
341+
Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error)
342+
}
343+
```
344+
345+
## Data Flow
346+
347+
1. **Configuration Flow:**
348+
- YAML files in openshift/release
349+
- Loaded by config tools
350+
- Processed and validated
351+
- Generated into Prow jobs
352+
- Applied to Prow
353+
354+
2. **Execution Flow:**
355+
- Prow triggers job
356+
- CI Operator loads config
357+
- Builds dependency graph
358+
- Executes steps
359+
- Promotes images
360+
- Reports results
361+
362+
3. **Image Flow:**
363+
- Built in cluster registry
364+
- Tagged to local ImageStream
365+
- Promoted to release stream
366+
- Mirrored to external registry
367+
368+
## Testing Structure
369+
370+
- **Unit Tests**: `*_test.go` files alongside source
371+
- **Integration Tests**: `test/integration/` directory
372+
- **E2E Tests**: `test/e2e/` directory
373+
- **Test Data**: `testdata/` directories in tool packages
374+
375+
## Build System
376+
377+
- **Makefile**: Main build automation
378+
- **Go Modules**: Dependency management
379+
- **Docker**: Container image builds
380+
- **CI/CD**: Automated testing and deployment
381+
382+
## Extension Points
383+
384+
1. **Custom Steps**: Add to `pkg/steps/`
385+
2. **Custom Controllers**: Add to `pkg/controller/`
386+
3. **Custom Tools**: Add to `cmd/`
387+
4. **Custom Validators**: Add to `pkg/validation/`
388+

0 commit comments

Comments
 (0)