ROX-30732: Do not use globals in fake workloads#16629
Conversation
|
Skipping CI for Draft Pull Request. |
|
This change is part of the following stack: Change managed by git-spice. |
|
Images are ready for the commit at 6c08ff8. To use with deploy scripts, first |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #16629 +/- ##
==========================================
- Coverage 48.62% 48.61% -0.02%
==========================================
Files 2664 2665 +1
Lines 199298 199338 +40
==========================================
- Hits 96914 96907 -7
- Misses 94792 94837 +45
- Partials 7592 7594 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
502b8cf to
6c08ff8
Compare
|
Please run at least a short scale test and check a few tables, API results, or the UI. |
6c08ff8 to
b75539a
Compare
|
Images are ready for the commit at 5c376e9. To use with deploy scripts, first |
This comment was marked as off-topic.
This comment was marked as off-topic.
Changed: func (w *WorkloadManager) getServices(workload ServiceWorkload, ids []string) // was: (..., lblPool *labelsPoolPerNamespace) func (w *WorkloadManager) getNetworkPolicy(workload NetworkPolicyWorkload, id string) // was: (..., lblPool *labelsPoolPerNamespace) func (w *WorkloadManager) getDeployment(workload DeploymentWorkload, idx int, deploymentIDs, replicaSetIDs, podIDs []string) // was: (..., lblPool *labelsPoolPerNamespace) Kept: func getClusterIP(id string, lblPool *labelsPoolPerNamespace) func getNodePort(id string, lblPool *labelsPoolPerNamespace) func getLoadBalancer(id string, lblPool *labelsPoolPerNamespace) func getPod(replicaSet *appsv1.ReplicaSet, id string, ipPool *pool, containerPool *pool) func populatePodContainerStatuses(pod *corev1.Pod, containerPool *pool) func generateAndAddIPToPool(ipPool *pool) string
b75539a to
7e33a34
Compare




Description
Refactored the fake workload package to eliminate global variables and implement dependency injection for better testability and maintainability.
Key Changes:
labelsPool,processPool,ipPool,externalIpPool,containerPool,endpointPool, andregisteredHostConnectionsfrom global variables intoWorkloadManagerinstance fieldsWorkloadManagerConfigwith builder pattern (With*methods) to configure pools during constructionflows.goto newpools.gofile, reducingflows.gofrom 370→215 linespool.remove()method that was incorrectly accessing other global poolsWhy: Global mutable state makes testing difficult, creates hidden dependencies between components, and violates Go best practices. This refactoring enables better unit testing, reduces coupling, and follows established dependency injection patterns used elsewhere in the codebase.
All functionality remains unchanged - this is purely an architectural improvement with no behavioral changes.
User-facing documentation
Testing and quality
Automated testing
How I validated my change