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

add support for adding local to the response objects (#3013)

Signed-off-by: fix test <>

Signed-off-by: fix test <>
Signed-off-by: fix test <ameijer@kubecost.com>
Co-authored-by: fix test <>
Alex Meijer пре 1 година
родитељ
комит
3880307c09
1 измењених фајлова са 4 додато и 4 уклоњено
  1. 4 4
      core/pkg/opencost/asset_json.go

+ 4 - 4
core/pkg/opencost/asset_json.go

@@ -275,6 +275,7 @@ func (d *Disk) MarshalJSON() ([]byte, error) {
 	jsonEncodeString(buffer, "storageClass", d.StorageClass, ",")
 	jsonEncodeString(buffer, "volumeName", d.VolumeName, ",")
 	jsonEncodeString(buffer, "claimName", d.ClaimName, ",")
+	jsonEncodeFloat64(buffer, "local", d.Local, ",")
 	jsonEncodeString(buffer, "claimNamespace", d.ClaimNamespace, "")
 	buffer.WriteString("}")
 	return buffer.Bytes(), nil
@@ -375,10 +376,9 @@ func (d *Disk) InterfaceToDisk(itf interface{}) error {
 		d.ClaimNamespace = ClaimNamespace.(string)
 	}
 
-	// d.Local is not marhsaled, and cannot be calculated from marshaled values.
-	// Currently, it is just ignored and not set in the resulting unmarshal to Disk
-	//  be aware that this means a resulting Disk from an unmarshal is therefore NOT
-	// equal to the originally marshaled Disk.
+	if local, err := getTypedVal(fmap["local"]); err == nil {
+		d.Local = local.(float64)
+	}
 
 	return nil