From c641c3ce357d2811879a615bc836b8511b1b1eb8 Mon Sep 17 00:00:00 2001 From: michaeljguarino Date: Thu, 19 Dec 2024 15:28:53 -0500 Subject: [PATCH 1/2] fix: Include idle node costs (#329) * Incldue idle allocation in node costs This is part of the intent of the cost aggregation * Incorporate idle allocations appropriately for cluster/node costs This is making the data a bit goofy, fixing now --- .../kubecostextractor_controller.go | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/internal/controller/kubecostextractor_controller.go b/internal/controller/kubecostextractor_controller.go index ddf483af..fe02e7a3 100644 --- a/internal/controller/kubecostextractor_controller.go +++ b/internal/controller/kubecostextractor_controller.go @@ -211,12 +211,15 @@ func (r *KubecostExtractorReconciler) fetch(host, path string, params map[string return buffer.Bytes(), nil } -func (r *KubecostExtractorReconciler) getAllocation(ctx context.Context, srv *corev1.Service, servicePort, aggregate string) (*allocationResponse, error) { +func (r *KubecostExtractorReconciler) getAllocation(ctx context.Context, srv *corev1.Service, servicePort, aggregate string, idle bool) (*allocationResponse, error) { queryParams := map[string]string{ "window": "30d", "aggregate": aggregate, "accumulate": "true", } + if idle { + queryParams["shareIdle"] = "true" + } var response []byte var err error @@ -239,7 +242,7 @@ func (r *KubecostExtractorReconciler) getAllocation(ctx context.Context, srv *co func (r *KubecostExtractorReconciler) getRecommendationAttributes(ctx context.Context, srv *corev1.Service, servicePort string, recommendationThreshold float64) ([]*console.ClusterRecommendationAttributes, error) { var result []*console.ClusterRecommendationAttributes for _, resourceType := range kubecostResourceTypes { - ar, err := r.getAllocation(ctx, srv, servicePort, resourceType) + ar, err := r.getAllocation(ctx, srv, servicePort, resourceType, false) if err != nil { return nil, err } @@ -267,7 +270,7 @@ func (r *KubecostExtractorReconciler) getRecommendationAttributes(ctx context.Co func (r *KubecostExtractorReconciler) getNamespacesCost(ctx context.Context, srv *corev1.Service, servicePort string) ([]*console.CostAttributes, error) { var result []*console.CostAttributes - ar, err := r.getAllocation(ctx, srv, servicePort, "namespace") + ar, err := r.getAllocation(ctx, srv, servicePort, "namespace", false) if err != nil { return nil, err } @@ -305,7 +308,7 @@ func (r *KubecostExtractorReconciler) getClusterCost(ctx context.Context, srv *c if err != nil { return nil, err } - ar, err := r.getAllocation(ctx, srv, servicePort, "cluster") + ar, err := r.getAllocation(ctx, srv, servicePort, "cluster", true) if err != nil { return nil, err } @@ -327,7 +330,7 @@ func (r *KubecostExtractorReconciler) getClusterCost(ctx context.Context, srv *c } func (r *KubecostExtractorReconciler) getControlPlaneCost(ctx context.Context, srv *corev1.Service, servicePort string) (*float64, error) { - ar, err := r.getAllocation(ctx, srv, servicePort, "controller") + ar, err := r.getAllocation(ctx, srv, servicePort, "controller", false) if err != nil { return nil, err } @@ -349,7 +352,7 @@ func (r *KubecostExtractorReconciler) getControlPlaneCost(ctx context.Context, s func (r *KubecostExtractorReconciler) getNodeCost(ctx context.Context, srv *corev1.Service, servicePort string) (*float64, error) { var totalNodeCost float64 - ar, err := r.getAllocation(ctx, srv, servicePort, "node") + ar, err := r.getAllocation(ctx, srv, servicePort, "node", true) if err != nil { return nil, err } @@ -360,10 +363,7 @@ func (r *KubecostExtractorReconciler) getNodeCost(ctx context.Context, srv *core if nodeCosts == nil { continue } - for name, allocation := range nodeCosts { - if name == opencost.IdleSuffix { - continue - } + for _, allocation := range nodeCosts { totalNodeCost += allocation.TotalCost() } } From 387f38be7b6f3129f42dc4a6c9aaea0eb9d65452 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 19 Dec 2024 16:14:15 -0500 Subject: [PATCH 2/2] Updated chart to release v0.5.3 (#330) Co-authored-by: michaeljguarino --- charts/deployment-operator/Chart.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/charts/deployment-operator/Chart.yaml b/charts/deployment-operator/Chart.yaml index df1fc061..bbfb2ea0 100644 --- a/charts/deployment-operator/Chart.yaml +++ b/charts/deployment-operator/Chart.yaml @@ -1,8 +1,8 @@ apiVersion: v2 name: deployment-operator description: creates a new instance of the plural deployment operator -appVersion: 0.5.2 -version: 0.5.2 +appVersion: 0.5.3 +version: 0.5.3 maintainers: - name: Plural url: https://www.plural.sh