Skip to content

Commit 9a0a985

Browse files
committed
updated package docs
Signed-off-by: Daniele Martinoli <[email protected]>
1 parent b9e0a6f commit 9a0a985

File tree

3 files changed

+96
-25
lines changed

3 files changed

+96
-25
lines changed

pkg/git/doc.go

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010
// # Client Interface
1111
//
1212
// The Client interface defines the core Git operations:
13-
// - Clone: Clone public repositories
14-
// - Pull: Update existing repositories (planned for future implementation)
13+
// - Clone: Clone public repositories to in-memory filesystem
1514
// - GetFileContent: Retrieve specific files from repositories
16-
// - GetCommitHash: Get current commit hash for change detection
17-
// - Cleanup: Remove local repository directories
15+
// - Cleanup: Clean up in-memory repository resources
16+
//
17+
// Repository information including commit hashes is tracked via the
18+
// RepositoryInfo struct which is populated during clone operations.
1819
//
1920
// # Example Usage
2021
//
@@ -39,23 +40,32 @@
3940
// # Security Considerations
4041
//
4142
// This package is designed to be used within a Kubernetes operator environment
42-
// where Git repositories contain MCP server registry data. Future versions will
43-
// include security hardening such as:
43+
// where Git repositories contain MCP server registry data. Security features include:
44+
// - In-memory filesystem operations (no disk access)
45+
// - Size limits on cloned repositories (max files and total size)
46+
// - Shallow clones by default for efficiency
47+
//
48+
// Future security hardening may include:
4449
// - Repository URL validation to prevent SSRF attacks
45-
// - Sandboxed Git operations
46-
// - Secure credential management via Kubernetes secrets
50+
// - Additional resource limits and timeouts
51+
// - Secure credential management via Kubernetes secrets for private repos
52+
//
53+
// # Implementation Details
4754
//
48-
// # Implementation Status
55+
// Current implementation uses:
56+
// - In-memory filesystems (go-billy memfs) for all Git operations
57+
// - LimitedFs wrapper to enforce size constraints (10k files, 100MB total)
58+
// - Shallow clones (depth=1) for branch/tag checkouts
59+
// - Full clones only when specific commits are requested
60+
// - Explicit memory cleanup via Cleanup() method with GC hints
4961
//
50-
// Current implementation supports:
62+
// Supported features:
5163
// - Public repository access via HTTPS
5264
// - Branch, tag, and commit checkout
53-
// - File content retrieval
54-
// - Temporary directory management
65+
// - File content retrieval from any path in the repository
5566
//
5667
// Planned features:
5768
// - Authentication for private repositories
58-
// - Repository caching for performance
5969
// - Webhook support for immediate sync triggers
6070
// - Git LFS support for large files
6171
package git

pkg/sources/doc.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@
1515
// Current implementations:
1616
// - ConfigMapSourceHandler: Retrieves registry data from Kubernetes ConfigMaps
1717
// Supports both ToolHive and Upstream registry formats with format validation
18+
// - GitSourceHandler: Retrieves registry data from Git repositories
19+
// Supports public repos via HTTPS with branch/tag/commit checkout
20+
// - APISourceHandler: Retrieves registry data from HTTP/HTTPS endpoints
21+
// Delegates to format-specific handlers (ToolHiveAPIHandler, UpstreamAPIHandler)
1822
// - ConfigMapStorageManager: Persists Registry data to Kubernetes ConfigMaps
1923
//
20-
// Future implementations may include:
21-
// - URLSourceHandler: HTTP/HTTPS endpoints
22-
// - GitSourceHandler: Git repositories
23-
// - RegistrySourceHandler: External registries
24-
//
2524
// The package provides a factory pattern for creating appropriate
2625
// source handlers based on the source type configuration, and uses
2726
// strongly-typed Registry instances throughout for type safety.

pkg/sync/doc.go

Lines changed: 69 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,82 @@
22
// for registry resources in the ToolHive Registry Server.
33
//
44
// This package implements a clean separation of concerns by extracting all
5-
// sync-related logic from the controller into dedicated interfaces:
5+
// sync-related logic from the controller into dedicated interfaces and types:
6+
//
7+
// # Core Interfaces
68
//
79
// - Manager: Main interface for orchestrating sync operations
810
// - DataChangeDetector: Detects changes in source data using hash comparison
911
// - AutomaticSyncChecker: Manages time-based automatic sync scheduling
1012
//
11-
// The package follows Go best practices by using interfaces for testability
12-
// and dependency injection, while providing concrete struct implementations
13-
// for actual functionality.
13+
// # Result Types
14+
//
15+
// - Result: Contains the outcome of successful sync operations (hash, server count)
16+
// - Error: Structured error type with Kubernetes condition information
17+
//
18+
// # Sync Decision Making
19+
//
20+
// The Manager.ShouldSync method evaluates multiple factors to determine if a sync
21+
// is needed, returning a decision (bool), reason (string), and next sync time:
22+
//
23+
// - Registry state (failed, not ready, complete)
24+
// - Filter configuration changes (via hash comparison)
25+
// - Source data changes (via hash comparison)
26+
// - Manual sync requests (via annotations)
27+
// - Automatic sync intervals (time-based policies)
28+
// - Requeue timing (minimum time between sync attempts)
29+
//
30+
// # Sync Reasons
31+
//
32+
// The package defines extensive reason constants to track why syncs occur or don't:
33+
//
34+
// - ReasonAlreadyInProgress: Sync already running
35+
// - ReasonRegistryNotReady: Initial sync or recovery from failure
36+
// - ReasonSourceDataChanged: Source data hash changed
37+
// - ReasonFilterChanged: Filter configuration modified
38+
// - ReasonManualWithChanges: Manual sync requested with detected changes
39+
// - ReasonManualNoChanges: Manual sync requested but no changes detected
40+
// - ReasonUpToDateWithPolicy: No sync needed, automatic policy active
41+
// - ReasonUpToDateNoPolicy: No sync needed, no automatic policy
42+
// - ReasonRequeueTimeNotElapsed: Too soon to retry after last attempt
43+
// - ReasonErrorCheckingChanges: Error during change detection
44+
//
45+
// # Kubernetes Status Integration
46+
//
47+
// The package defines condition types for Kubernetes status reporting:
48+
//
49+
// - ConditionSourceAvailable: Source is accessible
50+
// - ConditionDataValid: Registry data passes validation
51+
// - ConditionSyncSuccessful: Last sync operation succeeded
52+
// - ConditionAPIReady: Registry API is ready to serve requests
53+
//
54+
// The Error type includes condition information for automatic status updates:
55+
// - ConditionType: Which condition to update
56+
// - ConditionReason: Reason code for the condition
57+
// - Message: Human-readable error message
58+
//
59+
// # Timing Configuration
60+
//
61+
// Default timing constants control sync behavior:
62+
//
63+
// - DefaultSyncRequeueAfter: Minimum time between sync attempts (5 minutes)
64+
// This variable can be modified in tests for faster iteration
65+
//
66+
// # Key Features
1467
//
15-
// Key features:
1668
// - Hash-based change detection to avoid unnecessary syncs
17-
// - Manual sync support via annotations
69+
// - Filter change detection via hash comparison
70+
// - Manual sync support via Kubernetes annotations
1871
// - Automatic sync scheduling with configurable intervals
19-
// - Comprehensive error handling and status management
72+
// - Comprehensive error handling with structured Error types
73+
// - Detailed sync reason tracking for observability
2074
// - Clean integration with Kubernetes controller patterns
75+
// - Resource cleanup on Registry deletion
76+
//
77+
// # Implementation
78+
//
79+
// The package follows Go best practices by using interfaces for testability
80+
// and dependency injection, while providing concrete struct implementations
81+
// (DefaultSyncManager, DefaultDataChangeDetector, DefaultAutomaticSyncChecker)
82+
// for actual functionality.
2183
package sync

0 commit comments

Comments
 (0)