Skip to content

Conversation

@vladComan0
Copy link
Contributor

What does this PR change?

This Pull Request adds the --opencost flag to the cost command to setup standard OpenCost configuration. It is essentially an alias for the following flags:
--service-port 9003 --service-name opencost --kubecost-namespace opencost --allocation-path /allocation/compute

Does this PR rely on any other PRs?

N/A

How does this PR impact users? (This is the kind of thing that goes in release notes!)

The user will have the possibility to easily set OpenCost as the target service to the kubectl cost command by simply setting the --opencost instead of configuring the OpenCost default settings flag-by-flag.

Links to Issues or ZD tickets this PR addresses or fixes

How was this PR tested?

This Pull Request was tested in an Oracle Kubernetes Engine (OKE)-based Kubernetes cluster configured with OpenCost and identical behaviour with providing the following flags was asserted:
--service-port 9003 --service-name opencost --kubecost-namespace opencost --allocation-path /allocation/compute

Have you made an update to documentation?

An update was made in the README.md file.

Copy link
Contributor

@michaelmdresser michaelmdresser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I no longer work at Kubecost, but this is how I would have done it. LGTM.

Comment on lines +64 to +69
if o.OpenCost {
o.ServiceName = OpenCostServiceName
o.KubecostNamespace = OpenCostServiceNamespace
o.ServicePort = OpenCostServicePort
o.AllocationPath = OpenCostAllocationPath
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely done, I appreciate that the opencost defaults first, and then additional flags can override field-by-field.

cmd.Flags().BoolVar(&options.UseProxy, "use-proxy", false, "Instead of temporarily port-forwarding, proxy a request to Kubecost through the Kubernetes API server.")
cmd.Flags().StringVar(&options.AllocationPath, "allocation-path", "/model/allocation", "URL path at which Allocation queries can be served from the configured service. If using OpenCost, you may want to set this to '/allocation/compute'")
cmd.Flags().StringVar(&options.PredictSpecCostPath, "predict-speccost-path", "/model/prediction/speccost", "URL path at which Prediction queries can be served from the configured service.")
cmd.Flags().BoolVar(&options.OpenCost, "opencost", false, " Set true to configure Kubecost parameters according to the OpenCost default specification.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be worth calling out the defaulting behavior in the help text.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I initially thought it would be a little too verbose, but it will indeed make things clearer. I will commit the changes as soon as I get the chance. Thanks for the review!

@kaelanspatel kaelanspatel merged commit c8cda80 into kubecost:main Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants