diff --git a/providers/k8s/core/services.go b/providers/k8s/core/services.go index f4b1a7ce7..ae0127490 100644 --- a/providers/k8s/core/services.go +++ b/providers/k8s/core/services.go @@ -8,6 +8,7 @@ import ( . "github.com/tailwarden/komiser/models" "github.com/tailwarden/komiser/providers" + oc "github.com/tailwarden/komiser/providers/k8s/opencost" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -16,6 +17,14 @@ func Services(ctx context.Context, client providers.ProviderClient) ([]Resource, var config metav1.ListOptions + opencostEnabled := true + serviceCost, err := oc.GetOpencostInfo(client.K8sClient.OpencostBaseUrl, "service") + if err != nil { + log.Errorf("ERROR: Couldn't get service info from OpenCost: %v", err) + log.Warn("Opencost disabled") + opencostEnabled = false + } + for { res, err := client.K8sClient.Client.CoreV1().Services("").List(ctx, config) if err != nil { @@ -32,6 +41,11 @@ func Services(ctx context.Context, client providers.ProviderClient) ([]Resource, }) } + cost := 0.0 + if opencostEnabled { + cost = serviceCost[service.Name].TotalCost + } + resources = append(resources, Resource{ Provider: "Kubernetes", Account: client.Name, @@ -39,7 +53,7 @@ func Services(ctx context.Context, client providers.ProviderClient) ([]Resource, ResourceId: string(service.UID), Name: service.Name, Region: service.Namespace, - Cost: 0, + Cost: cost, CreatedAt: service.CreationTimestamp.Time, FetchedAt: time.Now(), Tags: tags,