Add methods to convert float to ResourceAmount. Add type Resources.

This commit is contained in:
kgrygiel 2017-12-11 12:30:55 +01:00
parent 589c6a1d97
commit f66218d68c
1 changed files with 15 additions and 2 deletions

View File

@ -26,6 +26,9 @@ type MetricName string
// ResourceAmount represents quantity of a certain resource within a container. // ResourceAmount represents quantity of a certain resource within a container.
type ResourceAmount int type ResourceAmount int
// Resources is a map from resource name to the corresponding ResourceAmount.
type Resources map[MetricName]ResourceAmount
const ( const (
// ResourceCPU represents CPU in millicores (1core = 1000millicores). // ResourceCPU represents CPU in millicores (1core = 1000millicores).
ResourceCPU MetricName = "cpu" ResourceCPU MetricName = "cpu"
@ -33,6 +36,16 @@ const (
ResourceMemory MetricName = "memory" ResourceMemory MetricName = "memory"
) )
// CPUAmountFromCores converts CPU cores to a ResourceAmount.
func CPUAmountFromCores(cores float64) ResourceAmount {
return ResourceAmount(cores * 1000.0)
}
// MemoryAmountFromBytes converts memory bytes to a ResourceAmount.
func MemoryAmountFromBytes(bytes float64) ResourceAmount {
return ResourceAmount(bytes)
}
// PodID contains information needed to identify a Pod within a cluster. // PodID contains information needed to identify a Pod within a cluster.
type PodID struct { type PodID struct {
// Namespaces where the Pod is defined. // Namespaces where the Pod is defined.
@ -62,7 +75,7 @@ type ContainerMetricsSnapshot struct {
// Duration of the measurement interval, which is [SnapshotTime - SnapshotWindow, SnapshotTime]. // Duration of the measurement interval, which is [SnapshotTime - SnapshotWindow, SnapshotTime].
SnapshotWindow time.Duration SnapshotWindow time.Duration
// Actual usage of the resources over the measurement interval. // Actual usage of the resources over the measurement interval.
Usage map[MetricName]ResourceAmount Usage Resources
} }
// BasicPodSpec contains basic information defining a pod and its containers. // BasicPodSpec contains basic information defining a pod and its containers.
@ -82,5 +95,5 @@ type BasicContainerSpec struct {
// Name of the image running within the container. // Name of the image running within the container.
Image string Image string
// Currently requested resources for this container. // Currently requested resources for this container.
Request map[MetricName]ResourceAmount Request Resources
} }