tiketit ja featuret vaihe 1
This commit is contained in:
@@ -0,0 +1,130 @@
|
||||
# Ticket 0010: `report-service/` — retention CronJob
|
||||
|
||||
**Vaihe:** 10/12
|
||||
**Status:** pending
|
||||
**Feature branch:** `feature/0010-report-service-retention-cronjob`
|
||||
**TDD required:** Yes
|
||||
**Feature file required:** No
|
||||
|
||||
**Required context:**
|
||||
- `docs/test-plan/tdd-guide.md`
|
||||
- Skills: `tdd`, `implementation`, `clean-code`, `bash-script`
|
||||
|
||||
---
|
||||
|
||||
## TDD — Red-Green-Refactor
|
||||
|
||||
### Red
|
||||
Kirjoita `tests/retention-cleanup.bats` mock-MinIO:a ja mock-Gitea API:a vasten:
|
||||
- `retention-cleanup.sh --dry-run` listaa poistettavat objektit
|
||||
- Yli 90 vrk vanha feature-build → merkitään poistettavaksi
|
||||
- Tagattu commit → ei merkitä poistettavaksi
|
||||
- `keepMin`: 3 uusinta säilyy branchista
|
||||
- ConfigMap-pohjainen retention: `retention.yaml` luetaan oikein
|
||||
|
||||
```bash
|
||||
bats tests/retention-cleanup.bats
|
||||
# FAIL
|
||||
```
|
||||
|
||||
### Green
|
||||
Toteuta `report-service/retention-cleanup.sh` + `CronJob.yaml` + `ConfigMap.yaml`.
|
||||
|
||||
```bash
|
||||
bats tests/retention-cleanup.bats
|
||||
# PASS
|
||||
```
|
||||
|
||||
### Refactor
|
||||
Parametrisoi retention-säännöt, paranna lokitusta.
|
||||
|
||||
## DoD
|
||||
- [ ] `tests/retention-cleanup.bats` — kaikki testit läpi
|
||||
- [ ] `report-service/retention-cleanup.sh` toimii --dry-run-tilassa
|
||||
- [ ] `report-service/CronJob.yaml` — schedule `0 3 * * *`
|
||||
- [ ] `report-service/ConfigMap.yaml` — retention.yaml oikea muoto
|
||||
- [ ] Aika-, branch-, tagi- ja keepMin-säännöt toimivat
|
||||
|
||||
---
|
||||
|
||||
## Toiminto
|
||||
|
||||
Kubernetes CronJob, joka ajaa siivousskriptin päivittäin. Skripti lukee ConfigMap-pohjaisen retention policyn ja poistaa vanhentuneet raportit MinIO:sta.
|
||||
|
||||
## Artefaktit
|
||||
|
||||
### `report-service/retention-cleanup.sh`
|
||||
|
||||
Skripti joka:
|
||||
1. Listaa kaikki bucketin objektit (`mc ls --recursive`)
|
||||
2. Parsii polusta `repo_slug` ja `commit_short`
|
||||
3. Hakee Gitea API:sta commitin metadata (`GET /api/v1/repos/{owner}/{repo}/commits/{sha}` → branch, onko tagattu)
|
||||
4. Soveltaa ConfigMapin retention-sääntöjä
|
||||
5. Poistaa vanhentuneet (`mc rm`)
|
||||
|
||||
### ConfigMap
|
||||
|
||||
```yaml
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: minio-report-retention
|
||||
data:
|
||||
retention.yaml: |
|
||||
rules:
|
||||
- branch: "master"
|
||||
maxAgeDays: 365
|
||||
keepMin: 20
|
||||
- branch: "feature/*"
|
||||
maxAgeDays: 90
|
||||
keepMin: 5
|
||||
- tagged: true
|
||||
maxAgeDays: -1 # ei koskaan
|
||||
keepMin: -1
|
||||
- default:
|
||||
maxAgeDays: 90
|
||||
keepMin: 3
|
||||
```
|
||||
|
||||
### CronJob
|
||||
|
||||
```yaml
|
||||
apiVersion: batch/v1
|
||||
kind: CronJob
|
||||
metadata:
|
||||
name: minio-report-cleanup
|
||||
spec:
|
||||
schedule: "0 3 * * *" # kerran päivässä klo 03:00
|
||||
jobTemplate:
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: cleanup
|
||||
image: minio/mc:latest
|
||||
command: ["/scripts/retention-cleanup.sh"]
|
||||
volumeMounts:
|
||||
- name: config
|
||||
mountPath: /etc/retention
|
||||
- name: script
|
||||
mountPath: /scripts
|
||||
volumes:
|
||||
- name: config
|
||||
configMap:
|
||||
name: minio-report-retention
|
||||
- name: script
|
||||
configMap:
|
||||
name: minio-cleanup-script
|
||||
```
|
||||
|
||||
## Verifiointi
|
||||
|
||||
1. Aja `retention-cleanup.sh` --dry-run → listaa poistettavat objektit
|
||||
2. Tarkista: yli 90 vrk vanha feature-build → merkitään poistettavaksi
|
||||
3. Tarkista: tagattu commit → ei merkitä poistettavaksi
|
||||
4. Tarkista: `keepMin`-säännön tuorein 3 säilyy
|
||||
|
||||
## Viitteet
|
||||
|
||||
- `docs/report-hosting.md` — Retention policy
|
||||
- `docs/architecture.md` — `report-service/`-moduuli
|
||||
Reference in New Issue
Block a user