Преглед изворни кода

logic to prevent unallocated container labels from being used in intersections

Signed-off-by: Alex Meijer <ameijer@kubecost.com>
(cherry picked from commit a3c5e22f0d7b0f7c67c57271079406311de843c1)
Signed-off-by: Alex Meijer <ameijer@kubecost.com>
Alex Meijer пре 3 година
родитељ
комит
9a194ec597
1 измењених фајлова са 12 додато и 2 уклоњено
  1. 12 2
      pkg/kubecost/allocationprops.go

+ 12 - 2
pkg/kubecost/allocationprops.go

@@ -439,10 +439,20 @@ func (p *AllocationProperties) Intersection(that *AllocationProperties) *Allocat
 		intersectionProps.ControllerKind = p.ControllerKind
 	}
 	if p.Namespace == that.Namespace {
+
+		// ignore the incoming labels from unallocated or unmounted special case pods
 		intersectionProps.Namespace = p.Namespace
+		if p.Container == UnmountedSuffix || p.Container == UnallocatedSuffix {
+			intersectionProps.Annotations = that.Annotations
+			intersectionProps.Labels = that.Labels
+		} else if that.Container == UnmountedSuffix || that.Container == UnallocatedSuffix {
+			intersectionProps.Annotations = p.Annotations
+			intersectionProps.Labels = p.Labels
+		} else {
+			intersectionProps.Annotations = mapIntersection(p.Annotations, that.Annotations)
+			intersectionProps.Labels = mapIntersection(p.Labels, that.Labels)
+		}
 
-		intersectionProps.Annotations = mapIntersection(p.Annotations, that.Annotations)
-		intersectionProps.Labels = mapIntersection(p.Labels, that.Labels)
 	}
 	if p.Pod == that.Pod {
 		intersectionProps.Pod = p.Pod