Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Custom Pricing Provider in OpenCost for Public Cloud Kubernetes Clusters #2434

Merged
merged 10 commits into from
May 16, 2024
11 changes: 11 additions & 0 deletions pkg/cloud/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,16 @@ func getClusterProperties(node *v1.Node) clusterProperties {
accountID: "",
projectID: "",
}

// Check for custom provider settings
if env.IsUseCustomProvider() {
// Use CSV provider if set
if env.IsUseCSVProvider() {
cp.provider = opencost.CSVProvider
}
return cp
}

// The second conditional is mainly if you're running opencost outside of GCE, say in a local environment.
if metadata.OnGCE() || strings.HasPrefix(providerID, "gce") {
cp.provider = opencost.GCPProvider
Expand All @@ -303,6 +313,7 @@ func getClusterProperties(node *v1.Node) clusterProperties {
cp.provider = opencost.OracleProvider
cp.configFileName = "oracle.json"
}
// Override provider to CSV if CSVProvider is used and custom provider is not set
if env.IsUseCSVProvider() {
cp.provider = opencost.CSVProvider
}
Expand Down
7 changes: 7 additions & 0 deletions pkg/env/costmodelenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const (
RemotePWEnvVar = "REMOTE_WRITE_PASSWORD"
SQLAddressEnvVar = "SQL_ADDRESS"
UseCSVProviderEnvVar = "USE_CSV_PROVIDER"
UseCustomProviderEnvVar = "USE_CUSTOM_PROVIDER"
CSVRegionEnvVar = "CSV_REGION"
CSVEndpointEnvVar = "CSV_ENDPOINT"
CSVPathEnvVar = "CSV_PATH"
Expand Down Expand Up @@ -409,6 +410,12 @@ func IsUseCSVProvider() bool {
return env.GetBool(UseCSVProviderEnvVar, false)
}

// IsUseCustomProvider returns the environment variable value for UseCustomProviderEnvVar which represents
// whether or not the use of a custom cost provider is enabled.
func IsUseCustomProvider() bool {
return env.GetBool(UseCustomProviderEnvVar, false)
}

// GetCSVRegion returns the environment variable value for CSVRegionEnvVar which represents the
// region configured for a CSV provider.
func GetCSVRegion() string {
Expand Down
Loading