feat: add support for changing docker labels via application api
This PR adds support for changing docker labels when creating server or modifying its details
Reasons for implementation:
- Pelican already supports editing docker labels via filament
- Support for container labels is one of Pelican's killer features that allows to use containers created by wings with sidecars (traefik, calico, node exporters and log collectors) so labels just have to have an API support
📝 Walkthrough
Walkthrough
Adds optional docker_labels support end-to-end: new DockerLabel validation rule, request validation and docblocks updated to accept docker_labels, model validationRules extended, services conditionally propagate docker_labels, transformer includes docker_labels in output, and an integration test asserting persistence.
Changes
| Cohort / File(s) | Summary |
|---|---|
Request validation app/Http/Requests/Api/Application/Servers/StoreServerRequest.php, app/Http/Requests/Api/Application/Servers/UpdateServerDetailsRequest.php |
Introduced docker_labels as `sometimes |
Validation rule app/Rules/DockerLabel.php |
Added DockerLabel validation rule implementing Illuminate\Contracts\Validation\ValidationRule that iterates array_keys($value) and fails on keys that don't match the Docker label key regex. |
Model validation rules app/Models/Server.php |
Added validation entries: 'docker_labels' => ['array'] and 'docker_labels.*' => ['required', 'string'] to Server::$validationRules. |
Service layer app/Services/Servers/DetailsModificationService.php |
Accepts optional docker_labels in input, assembles an $attributes array, conditionally adds docker_labels when provided, then calls forceFill($attributes) to persist changes. |
API transformation app/Transformers/Api/Application/ServerTransformer.php |
Adds docker_labels to the container subobject in the transformed server output, using [] as a fallback when null. |
Integration test tests/Integration/Services/Servers/ServerCreationServiceTest.php |
Adds test_server_creation_accepts_docker_labels() asserting that docker_labels provided during server creation are persisted on the created Server. |
sequenceDiagram
autonumber
participant Client
participant HTTPReq as Request (Store/Update)
participant Validator as Validator + DockerLabel
participant Service as DetailsModificationService / CreationService
participant Model as Server Model
participant Transformer as ServerTransformer
participant Response
Client->>HTTPReq: send payload (may include docker_labels)
HTTPReq->>Validator: validate payload (docker_labels rules applied)
Validator-->>HTTPReq: validated data (docker_labels present if provided)
HTTPReq->>Service: pass validated data
Service->>Model: forceFill(attributes) (includes docker_labels when present) and save
Model-->>Service: persisted Server instance
Service->>Transformer: transform(Server)
Transformer-->>Response: include container.docker_labels (array or [])
Response-->>Client: HTTP response with docker_labels in payload
Pre-merge checks
✅ Passed checks (3 passed)
| Check name | Status | Explanation |
|---|---|---|
| Title check | ✅ Passed | The title accurately and concisely summarizes the main change: adding Docker label modification support via the application API. |
| Description check | ✅ Passed | The description clearly relates to the changeset by explaining the purpose of adding Docker label API support and providing business rationale. |
| Docstring Coverage | ✅ Passed | Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. |
📜 Recent review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between 321e9fe687e74d6de9bd642fbcb651017c013278 and 605b3e7b313e78e61c931570ee0a1667a7aad58d.
📒 Files selected for processing (2)
app/Http/Requests/Api/Application/Servers/StoreServerRequest.php(4 hunks)app/Models/Server.php(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- app/Http/Requests/Api/Application/Servers/StoreServerRequest.php
- app/Models/Server.php
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands and usage tips.
Thanks for your contribution great work so far ! I think we should enforce labels restrictions to make sure you don't brick the server.
Should we create a separate validator or simple inline regex would be enough?
Should we create a separate validator or simple inline regex would be enough?
simple regex is fine.
I'll post regex here while I read docs for laravel validator
^(?!(?:com\.docker\.|io\.docker\.|org\.dockerproject\.))(?=.*[a-z]$)[a-z](?:[a-z0-9]|(?<!\.)\.(?!\.)|(?<!-)-(?!-))*$
Regex101: https://regex101.com/r/FiYrwo/1 Validators:
(?!(?:com\.docker\.|io\.docker\.|org\.dockerproject\.))→ Thecom.docker.*,io.docker.*, andorg.dockerproject.*namespaces are reserved by Docker for internal use.(?=.*[a-z]$)→ Positive lookahead. Label keys should ... end with a lower-case letter ...[a-z]→ Label keys should begin ... with a lower-case letter ...(?:[a-z0-9]|(?<!\.)\.(?!\.)|(?<!-)-(?!-))*→ Non-capturing (+ performance),*- any amount of symbols as first and optional last symbols are validated by expressions before[a-z0-9]→ Label keys ... should only contain lower-case alphanumeric characters, ...(?<!\.)\.(?!\.)→ NLA + NLB for dots to check for consecutive dots (before or after current dot)(?<!-)-(?!-)→ NLA + NLB for hyphens to check for consecutive hyphens (before or after current hyphen)
I actually found out docker allows weird stuff like here: https://regex101.com/r/FiYrwo/2