Repository navigation
refactor!: remove duplicated and unused code - #95
Conversation
- POST and PUT /services share one function
- GET /services/types computes the distinct types in MongoDB and
returns them sorted by group, artifact and version (the order used
to change between calls)
- GET /services/{serviceId} uses a projection instead of deleting `_id`
- Remove unused code: `ValidationError`, `RegisterService.was_replaced`,
the `meta_version` config and `MetaVersionConfig`, and the config
file check in `app.py` (FOCA raises an `OSError` itself)
- Use fully qualified module paths in `app.py` and `config.yaml`, so
that the app runs as an installed package; the image starts it with
`python -m cloud_registry.app`
- `get_custom_config()` checks the type of the custom config, which is
now imported under its own module path
BREAKING CHANGE: the `custom.endpoints.services.meta_version` config key
is removed; custom configs that still set it are rejected.
Closes #74
Co-Authored-By: Claude Opus 5.5 <[email protected]>
- POST /service-info uses the same JSON object check as POST and PUT /services - Test the sort order of service types by group and version too - Test the missing config error by its path - Explain why the custom config type check needs the full model path Co-Authored-By: Claude Opus 5.5 <[email protected]>
The configmap Job generates the app config only at installation, so a new config format (FOCA 0.14, no `meta_version`, module paths) needs the Job to run again before the app restarts. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Helm resets the generated app config on every upgrade and cannot update the configmap Job when the image changes, so the Job must be deleted before every upgrade, not only for config format changes. Also name `custom_config_model` in the custom config type error. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideThe PR removes duplicated endpoint logic and unused configuration/state, replaces service-type computation with deterministic MongoDB aggregation, and standardizes package-qualified startup and configuration loading. Tests cover stable type ordering and configuration error reporting, while deployment documentation reflects the required Helm upgrade procedure. Sequence diagram for shared service registration endpointssequenceDiagram
participant Client
participant API as Registry API
participant RegisterService
participant MongoDB
Client->>API: POST /services
API->>API: _register_service()
API->>API: _get_request_object()
API->>RegisterService: RegisterService(data, id=None)
RegisterService->>MongoDB: register_metadata()
API-->>Client: service id
Client->>API: PUT /services/{serviceId}
API->>API: _register_service(service_id)
API->>API: _get_request_object()
API->>RegisterService: RegisterService(data, id=serviceId)
RegisterService->>MongoDB: register_metadata()
API-->>Client: service id
Client->>API: POST /service-info
API->>API: _get_request_object()
API->>RegisterService: RegisterServiceInfo.set_service_info_from_app_context(data)
API-->>Client: 201 response
Flow diagram for deterministic service type listingflowchart LR
Request[GET /services/types] --> Aggregate[MongoDB aggregate]
Aggregate --> Group[$group by type.group, artifact, version]
Group --> Sort[$sort by group, artifact, version]
Sort --> Response[Return distinct sorted types]
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #95 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 7 7
Lines 225 204 -21
=========================================
- Hits 225 204 -21 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="deployment/README.md" line_range="30" />
<code_context>
+ `deployment` folder:
```
+kubectl delete job configmap-job-<appName> -n namespace
helm upgrade cloud-registry . -n namespace
+kubectl wait --for=condition=complete --timeout=5m job/configmap-job-<appName> -n namespace
```
</code_context>
<issue_to_address>
**Upgrade can restart app with empty config**
When an upgrade changes the image or otherwise triggers a Deployment rollout before the config Job has patched `app-config`, helm rolls out the changed Deployment while the ConfigMap still contains its placeholder, so FOCA rejects the mounted config and the app pods fail startup until the Job patches the ConfigMap and deletes them. The upgrade therefore causes an outage during the configuration step.
Make the config Job complete before the Deployment rolls out, for example by using an appropriately ordered Helm hook or a staged upgrade procedure that waits for the Job before updating the Deployment.
</issue_to_address>
### Comment 2
<location path="deployment/README.md" line_range="31" />
<code_context>
```
+kubectl delete job configmap-job-<appName> -n namespace
helm upgrade cloud-registry . -n namespace
+kubectl wait --for=condition=complete --timeout=5m job/configmap-job-<appName> -n namespace
```
`namespace` is the name of the namespace where the cluster was installed.
</code_context>
<issue_to_address>
**Upgrade reports success with stale config**
When the Kubernetes API rejects or fails to apply the ConfigMap PATCH during an upgrade, `update-config-map.sh` does not check the ConfigMap PATCH result, so it continues to delete app pods and exits successfully even when the patch fails. The Job then completes and this wait succeeds while `app-config` still contains Helm’s placeholder, leaving the restarted pods unable to load configuration.
Make the script fail when the PATCH is unsuccessful and verify the ConfigMap update before reporting Job success.
</issue_to_address>Sourcery assessment
Approval pending. 2 findings to address first.
Blocking findings: deployment/README.md:30, deployment/README.md:31
Summary
Remove duplicated and unused code (closes #74). #94 already added the collection helper (
cloud_registry/utils.py), %-style logging andmodel_dump()./servicesand POST/service-infoshare the request body check. POST and PUT also share the registration (_register_service)./services/typescomputes the distinct types in MongoDB ($groupand$sort). It returns them sorted by group, artifact and version; before, the order changed between calls. This also removes thegetServices.__wrapped__call and itstype: ignore./services/{serviceId}uses a projection instead of deleting_id.ValidationErrorRegisterService.was_replacedMetaVersionConfigand themeta_versionconfig keyapp.py(FOCA raises anOSErrornaming the file)cloud_registry.service_models.custom_config.CustomConfigx-openapi-router-controller: cloud_registry.ga4gh.registry.serverx-bearerInfoFunc: foca.security.auth.validate_token, the same function thatapp.pyre-exportedpython -m cloud_registry.app; Compose and Helm use the image's command. The tests no longer addcloud_registry/tosys.path.get_custom_config()checks the type of the custom config instead of casting it.deployment/README.md: a corrected upgrade procedure (see "Breaking changes").Breaking changes
custom.endpoints.services.meta_versionis removed. FOCA config models forbid unknown keys, so custom configs that still set it are rejected at startup. The key was never read.cloud_registry/.app-configConfigMap is generated once, by a plain Job, from the config in the image. Helm resets it to its empty placeholder on everyhelm upgrade, and a changed image makes the Job update fail. The README now says to delete the Job before every upgrade and wait for it. This applies after feat!: upgrade to FOCA 0.14.0 #92 (FOCA 0.14) already, which changed the config format too. Running the Job as a Helm hook belongs to Helm chart: configure app via values and FOCA overlays #67.Verification
pytest: 75 passed (Python 3.10, FOCA 0.14.0). New tests:null, mixed key order. The results are the same as before for data stored through the API; extra keys insidetypeare rejected by the spec.meta_version, then module paths) and the new one (starts).foca.security.auth.validate_tokenis the same function as before.Not verified: the Helm procedure on a cluster: there is no cluster here. It is derived from the chart,
update-config-map.shand Helm 3's three-way merge.Notes
custom_config_modelstring betweenapp.pyand the test fixture. The fixture spelling it out also tests the path.🤖 Generated with Claude Code
Summary by Sourcery
Refactor duplicated service handling and remove obsolete configuration and runtime code while standardizing application startup and deployment configuration.
Bug Fixes:
Enhancements:
Build:
Deployment:
Documentation:
Tests: