Thanks for your help improving the OpenCost project! There are many ways to contribute to the project, including the following:
If you have a question about OpenCost or have encountered problems using it, you can start by asking a question on Slack or via email at support@kubecost.com
This repository's contribution workflow follows a typical open-source model:
Follow these steps to build from source and deploy:
docker build --rm -f "Dockerfile" -t <repo>/kubecost-cost-model:<tag> .kubectl create namespace cost-modelkubectl apply -f kubernetes/ --namespace cost-modelkubectl port-forward --namespace cost-model service/cost-model 9003To test, build the cost-model docker container and then push it to a Kubernetes cluster with a running Prometheus.
To confirm that the server is running, you can hit http://localhost:9003/costDataModel?timeWindow=1d
To run locally cd into cmd/costmodel and go run main.go
cost-model requires a connection to Prometheus in order to operate so setting the environment variable PROMETHEUS_SERVER_ENDPOINT is required.
In order to expose Prometheus to cost-model it may be required to port-forward using kubectl to your Prometheus endpoint.
For example:
kubectl port-forward svc/kubecost-prometheus-server 9080:80
This would expose Prometheus on port 9080 and allow setting the environment variable as so:
PROMETHEUS_SERVER_ENDPOINT="http://127.0.0.1:9080"
If you want to run with a specific kubeconfig the environment variable KUBECONFIG_PATH can be used. cost-model will attempt to connect to your Kubernetes cluster in a similar fashion as kubectl so the env is not required. The order of precedence is KUBECONFIG_PATH > default kubeconfig file location ($HOME/.kube/config) > in cluster config
Example:
export KUBECONFIG_PATH=~/.kube/config
There are two more environment variables recommended to run locally. These should be set as the default file location used is /var/ which usually requires more permissions than kubecost actually needs to run. They do not need to match but keeping everything together can help cleanup when no longer needed.
ETL_PATH_PREFIX="/my/cool/path/kubecost/var/config"
CONFIG_PATH="/my/cool/path/kubecost/var/config"
An example of the full command:
ETL_PATH_PREFIX="/my/cool/path/kubecost/var/config" CONFIG_PATH="/my/cool/path/kubecost/var/config" PROMETHEUS_SERVER_ENDPOINT="http://127.0.0.1:9090" go run main.go
To run these tests:
kubectl port-forward --namespace kubecost service/kubecost-prometheus-server 9003:80go test -timeout 700s from the testing directory. The tests right now take about 10 minutes (600s) to run because they bring up and down pods and wait for Prometheus to scrape data about them.By contributing to this project, you certify that your contribution was created in whole or in part by you and that you have the right to submit it under the open source license indicated in the project. In other words, please confirm that you, as a contributor, have the legal right to make the contribution.
Please write a commit message with Fixes Issue # if there is an outstanding issue that is fixed. It’s okay to submit a PR without a corresponding issue; just please try to be detailed in the description of the problem you’re addressing.
Please run go fmt on the project directory. Lint can be okay (for example, comments on exported functions are nice but not required on the server).
Please email us (support@kubecost.com) or reach out to us on Slack if you need help or have any questions!