|
| 1 | +# Cost Management Operator for Konflux Clusters |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +The Cost Management Operator provides cost tracking and optimization for Konflux build pipeline workloads on OpenShift. It integrates with Cost Explorer to offer detailed cost visibility and optimization recommendations. |
| 6 | + |
| 7 | + |
| 8 | +> **Note:** This solution currently applies only to Build pipeline workflows. Release and Integration workflows are not yet supported. |
| 9 | +
|
| 10 | +## Table of Contents |
| 11 | + |
| 12 | +- [Quick Start](#quick-start) |
| 13 | +- [Administrator Guide](#administrator-guide) |
| 14 | +- [Policy Configuration](#policy-configuration) |
| 15 | +- [References](#references) |
| 16 | +- [Maintainers](#maintainers) |
| 17 | +- [Demo](#demo) |
| 18 | + |
| 19 | + |
| 20 | +--- |
| 21 | + |
| 22 | +## Quick Start |
| 23 | + |
| 24 | +Here's how to get started with cost management: |
| 25 | + |
| 26 | +1. **Find Your Cost Center ID** |
| 27 | + - Option A: Use the lookup script |
| 28 | + ```bash |
| 29 | + git clone https://gitlab.cee.redhat.com/rrajashe/konflux-release-data.git |
| 30 | + cd konflux-release-data/tenants-config |
| 31 | + ./ldapsearch.sh resolve YOUR_USERNAME |
| 32 | + |
| 33 | + # Example output: |
| 34 | + ./ldapsearch.sh resolve rrajashe |
| 35 | + 678 |
| 36 | + ``` |
| 37 | + |
| 38 | + - Option B: Contact your manager to know your cost-center. |
| 39 | + |
| 40 | +2. **Label Your Namespace** |
| 41 | + - Add the required cost management labels to your tenant namespace: |
| 42 | + ```yaml |
| 43 | + cost-center: "<value>" |
| 44 | + insights_cost_management_optimizations: "true" |
| 45 | + ``` |
| 46 | + If you are not sure of your cost-center value, just run the [ldapsearch.sh](https://gitlab.cee.redhat.com/rrajashe/konflux-release-data/-/blob/main/tenants-config/ldapsearch.sh?ref_type=heads) |
| 47 | + ``` |
| 48 | + ./ldapsearch.sh resolve rrajashe |
| 49 | + 678 |
| 50 | + ``` |
| 51 | + |
| 52 | +3. **Verify your namespace labelling** |
| 53 | + - Check that your labels were applied correctly: |
| 54 | + ```bash |
| 55 | + oc get namespace my-team-tenant --show-labels |
| 56 | + ``` |
| 57 | + You should see both cost-center and insights_cost_management_optimizations labels in the output. |
| 58 | + |
| 59 | +4. **Confirm Access** |
| 60 | + - To get access to the [Cost Management UI](https://console.redhat.com/openshift/cost-management), create an [internal access request](https://console.redhat.com/internal): |
| 61 | + 1. Click on **Create request**. |
| 62 | + 2. Find your Account number and Organization ID by clicking your name in the top-right corner of console.redhat.com (in the dropdown menu). |
| 63 | + 3. Request access for up to one year, choosing a duration that fits your needs. |
| 64 | + 4. Select the following roles: |
| 65 | + - `Cost Price List viewer` |
| 66 | + - `Cost cloud viewer` |
| 67 | + - `Cost OpenShift Viewer` |
| 68 | + 5. Review the details and click **Submit**. Once approved, access the UI here: https://console.redhat.com/openshift/cost-management. |
| 69 | +  |
| 70 | + |
| 71 | +5. **Use Cost Explorer** |
| 72 | + |
| 73 | + On the Cost Explorer page: |
| 74 | + * Select **Perspective -> "OpenShift"**. |
| 75 | + * Filter by **project** and **cost-center label**. |
| 76 | + * Apply Filters: |
| 77 | + * Account -> `stonesoup-stage` |
| 78 | + * Project -> `-tenant` |
| 79 | + * Choose **Show cost as Amortized** (for Show-Back Reporting). |
| 80 | + * Use the **Optimizations** tab for efficiency recommendations. |
| 81 | + * Export reports (CSV, PDF, etc.) as needed. |
| 82 | + |
| 83 | + The "Optimizations" tab offers: |
| 84 | + * **Right-sizing suggestions**: Reduce over-provisioned resources. |
| 85 | + * **Idle resource identification**: Find unused or underutilized resources. |
| 86 | + * **Cost-saving opportunities**: Specific recommendations with estimated savings. |
| 87 | + |
| 88 | +6. **Get Help** |
| 89 | + |
| 90 | + Contact the **PV Observability team** or ping us in Slack. |
| 91 | + |
| 92 | +--- |
| 93 | +## Administrator Guide |
| 94 | + |
| 95 | +### Infrastructure Setup |
| 96 | + |
| 97 | +#### Prerequisites for Administrators |
| 98 | +* AWS account with administrative privileges |
| 99 | +* Konflux cluster administrative access |
| 100 | +* Understanding of Kyverno policies and ArgoCD |
| 101 | +* Access to Red Hat Hybrid Cloud Console |
| 102 | + |
| 103 | +#### Deploying to New Clusters |
| 104 | + |
| 105 | +1. **Configure ArgoCD Applications** |
| 106 | + |
| 107 | + Modify `argo-cd-apps/base/all-clusters/infra-deployments/cost-management/costmanagement-metrics-operator.yaml` to include your new cluster. |
| 108 | + |
| 109 | +2. **Create Cluster-Specific Configuration** |
| 110 | + |
| 111 | + Create the following files for your new cluster: |
| 112 | + ``` |
| 113 | + components/cost-management/<environment>/<new-cluster>/cost-management-config-source-patch.yaml |
| 114 | + components/cost-management/<environment>/<new-cluster>/kustomization.yaml |
| 115 | + ``` |
| 116 | +
|
| 117 | +3. **Set Up Cloud Integration** |
| 118 | +
|
| 119 | + Follow the [unfiltered AWS cloud integration guide](https://docs.redhat.com/en/documentation/cost_management_service/1-latest/html-single/integrating_amazon_web_services_aws_data_into_cost_management/index#assembly-adding-aws-int): |
| 120 | +
|
| 121 | + - Use **Manual configuration** (not recommended configuration mode) |
| 122 | + - Ensure cloud integration name matches your S3 bucket name |
| 123 | + - Use default data set for cost and usage reports |
| 124 | + - Copy External ID and Role ARN accurately |
| 125 | + - Complete IAM setup for cost data access |
| 126 | +  |
| 127 | +
|
| 128 | +--- |
| 129 | +
|
| 130 | +## Policy Configuration |
| 131 | +
|
| 132 | +**validate-cost-management-label** |
| 133 | +- Prevents tenant namespace creation without proper cost management labels |
| 134 | +- Ensures cost-center label exists and contains only numeric values |
| 135 | +- Blocks namespace creation if validation fails |
| 136 | +
|
| 137 | +**propagate-cost-management-labels** |
| 138 | +- Propagates the `cost-center` label from non-managed tenant namespaces to pods and sets the `insights_cost_management_optimizations` label to `true` on those pods. |
| 139 | +- Skips managed tenant namespaces (different use case) |
| 140 | +- Applied during pod creation |
| 141 | +
|
| 142 | +--- |
| 143 | +
|
| 144 | +## References |
| 145 | +
|
| 146 | +- [Red Hat Cost Management Docs](https://access.redhat.com/documentation/en-us/cost_management_service/) |
| 147 | +- [Namespace Label SOP](https://konflux.pages.redhat.com/docs/users/getting-started/create-tenant-namespace.html#manually-adding-a-namespace) |
| 148 | +- [Namespace Creation Script](https://gitlab.cee.redhat.com/releng/konflux-release-data/-/blob/main/tenants-config/add-namespace.sh?ref_type=heads) |
| 149 | +
|
| 150 | +--- |
| 151 | +
|
| 152 | +## Maintainers |
| 153 | +
|
| 154 | +- PV Observability & Monitoring Team |
| 155 | +- FinOps & Infra Stakeholders |
| 156 | +
|
| 157 | +For questions or updates, raise an issue or ping the team in Slack. |
| 158 | +
|
| 159 | +--- |
| 160 | +
|
| 161 | +## Demos |
| 162 | +
|
| 163 | +For more details, you can view the demos: |
| 164 | +
|
| 165 | +[Implementation Demo](https://drive.google.com/file/d/1F4SZUlMdDkc0O1zvsT5CbxhYi6jzE_ab/view?usp=drive_link) |
| 166 | +
|
| 167 | +[Cost Management UI Demo](https://drive.google.com/file/d/1-3YZtWy-ge9q2SxZMVGxCcs4YnD_3_1Y/view?usp=drive_link) |
| 168 | +
|
| 169 | +🎯 **Let’s make every core count!** |
0 commit comments