How pgarciaq/ros-ocp-backend works
1. What this service is
Resource Optimization for OpenShift is a Go backend that sits between OpenShift workload data, an internal PostgreSQL database, Kafka-based ingestion, and the external Kruize recommendation engine. It exposes an HTTP API for consumers and also runs background processors for report ingestion and recommendation polling.
2. Top-level application shape
The cmd/ package suggests a CLI-style bootstrap with separate entry points for the main API/service startup, DB setup, and aggregation-related commands. The runtime is a single Go service composed of API handlers plus background jobs rather than multiple independently deployed services.
3. Primary inbound paths
There are two main data entry points:
- HTTP API under internal/api, which likely serves request/response traffic for reports, recommendations, and metadata.
- Kafka consumer under internal/kafka, which suggests asynchronous ingestion of report messages or events.
The presence of report_processor and recommendation_poller indicates that some request flows are synchronous, while others are queued or polled in the background.
4. Core processing pipeline
Raw input is converted into internal models, validated, aggregated, and then persisted. The internal/services/report_processor.go, internal/utils/aggregator.go, and internal/utils/conversion.go files indicate a pipeline that turns report data into normalized workload/namespace metrics and recommendation records. This is the main transformation boundary in the system.
5. Domain model and persistence
The internal/model/ package defines the service’s core entities: accounts, clusters, workloads, metrics, recommendation sets, and historical recommendation sets, including namespace-scoped variants. The database schema is managed through SQL migrations, which create and evolve tables, indexes, partitions, and timestamp/constraint changes. PostgreSQL is the durable system of record.
6. Recommendation lifecycle
Recommendation data appears to be tracked both as current state and historical snapshots. The presence of recommendation_set, historical_recommendation_set, namespace_recommendation_set, and poller code implies a lifecycle where recommendations are fetched from Kruize, transformed into internal schema, stored, and periodically refreshed.
7. External Kruize integration
The internal/utils/kruize and internal/types/kruizePayload packages define the service boundary to Kruize’s API schema. This is an important integration point: the backend likely creates experiments, updates results, and lists recommendations in Kruize, then maps those payloads into its own model and database structures.
8. Security and authorization
The HTTP layer has middleware for identity and RBAC (internal/api/middleware/identity.go, rbac.go) and a query builder in internal/rbac/. This indicates request authorization is not just perimeter-based; access control is enforced per account/resource scope inside the application.
9. Operational cleanup and retention
The internal/services/housekeeper package contains cleaners for sources and table partitions. That implies the service manages its own data retention and cleanup, especially for partitioned workload-metrics tables and stale source records.
10. Feature flags and configuration
Configuration is centralized in internal/config, with feature flag support in internal/featureflags and an Unleash bootstrap file. This means behavior can be toggled at runtime, which is likely important for staged rollout of ingestion, namespace features, or recommendation behavior.
11. Deployment and platform context
The repo is Kubernetes/OpenShift-oriented: clowdapp.yaml, kruize-clowdapp.yaml, Dockerfile, Tekton pipelines, and GitHub Actions indicate cloud-native deployment and CI/CD. The service is designed to run in managed OpenShift environments with platform-provided config, secrets, and Kafka/DB bindings.
12. Observability and support artifacts
Grafana dashboards, OpenAPI spec, Postman collections, sample CSV/TAR inputs, and docs/examples show this repo is built around operational support and integration testing. These artifacts are useful when drawing the system diagram because they reflect the expected data formats and the monitoring boundary around the backend.
13. Likely architecture diagram boundaries
A clear diagram should show:
- Clients or internal producers calling the HTTP API
- Kafka delivering asynchronous report/event messages
- The Go application as the orchestration layer
- PostgreSQL as persistence
- Kruize as the external optimization engine
- OpenShift/Clowd as the runtime/platform dependency
The service’s main value is in translating raw workload/report data into persisted optimization state and serving it back through authenticated APIs.
Main entry points: report_processor.go Report processor · api HTTP API · migrations PostgreSQL · recommendation_poller.go Recommendation poller
Components 19
Go service
CLI bootstrap, HTTP API, background workers, and shared service logic.
- CLI bootstrap · Main command set for starting the service, DB setup, and aggregation-related flows.
cmd - HTTP API · Authenticated request/response surface for reports, recommendations, and metadata.
internal/api - Auth middleware · Identity and RBAC enforcement for API requests.
internal/api/middleware - Report processor · Background pipeline that ingests workload reports and normalizes them.
internal/services/report_processor.go - Recommendation poller · Background refresh loop for Kruize recommendation state.
internal/services/recommendation_poller.go - Housekeeper · Retention and cleanup for sources and partitioned tables.
internal/services/housekeeper - Service utils · Shared service-level helpers and metrics coordination.
internal/services
Domain model
Internal entities, transforms, and persistence-facing structures.
- Domain model · Accounts, clusters, workloads, metrics, and recommendation state objects.
internal/model - Conversion · Maps raw report and external payloads into internal structures.
internal/utils/conversion.go - Aggregator · Combines report data into normalized metrics and recommendation inputs.
internal/utils/aggregator.go - Kruize payloads · Request/response schema definitions for Kruize integration, including namespace variants.
internal/types/kruizePayload - RBAC query · Resource-scope query construction for authorization checks.
internal/rbac
External systems
Database, Kafka, Kruize, and OpenShift platform dependencies.
- PostgreSQL · Durable system of record managed through migrations.
migrations - Kafka · Asynchronous ingestion path for report and event messages.
internal/kafka - Kruize · Optimization engine used to create experiments, update results, and fetch recommendations.
internal/utils/kruize - Config · Service configuration and feature flag wiring.
internal/config - OpenShift · ClowdApp, deployment, and container runtime integration for managed OpenShift environments.
clowdapp.yaml
Operations
Deployment, CI/CD, observability, and support artifacts.
- CI/CD · GitHub Actions, Tekton, and build/deploy automation.
.github/workflows - Docs & ops · OpenAPI, dashboards, examples, and sample inputs for validation and monitoring.
openapi.json
Connections 27
- CLI bootstrap → HTTP API: starts · Bootstraps the HTTP service.
- CLI bootstrap → Report processor: starts · Launches background report processing.
- CLI bootstrap → Recommendation poller: starts · Launches recommendation refresh polling.
- HTTP API → Auth middleware: guards · Applies identity and RBAC checks.
- HTTP API → Domain model: reads/writes · Serves and persists domain objects.
- HTTP API → RBAC query: authorizes · Builds scoped access queries.
- Report processor → Kafka: consumes · Reads asynchronous report messages.
- Report processor → Conversion: normalizes · Converts inbound payloads into internal records.
- Report processor → Aggregator: aggregates · Derives workload and metrics rollups.
- Report processor → PostgreSQL: persists · Stores processed report state and metrics.
- Recommendation poller → Kruize: fetches · Polls external recommendation state.
- Recommendation poller → Kruize payloads: maps · Uses Kruize request/response schemas.
- Recommendation poller → PostgreSQL: updates · Refreshes current and historical recommendations.
- Aggregator → Domain model: produces · Builds persisted domain entities.
- Conversion → Domain model: maps to · Transforms raw input into model objects.
- Kruize payloads → Kruize: binds · Defines the external API contract.
- Domain model → PostgreSQL: schema · Backed by migration-managed tables.
- Housekeeper → PostgreSQL: cleans · Manages partitions and stale source data.
- Config → HTTP API: configures · Supplies runtime settings.
- Config → Recommendation poller: configures · Controls polling behavior and flags.
- Config → Report processor: configures · Controls ingestion and processing behavior.
- OpenShift → CLI bootstrap: runs · Provides the OpenShift deployment environment.
- OpenShift → Kafka: binds · Provides platform Kafka connectivity.
- OpenShift → PostgreSQL: binds · Provides platform database connectivity.
- CI/CD → OpenShift: deploys · Builds and delivers the service to OpenShift.
- Docs & ops → HTTP API: documents · Captures the HTTP surface and sample usage.
- Docs & ops → PostgreSQL: describes · Reflects database schema and examples.