Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions ocp-metadata/ocp-metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,28 @@ func (meta *Metadata) GetCurrentPodCount(nodeLabelSelector string) (int, error)
return podCount, nil
}

// GetAggregatedNodeCapacity returns the aggregated allocatable resources of nodes matching the given label selector
func (meta *Metadata) GetAggNodeResources(nodeLabelSelector string) (NodeResources, error) {
var nodeResources NodeResources
nodeList, err := meta.connector.ClientSet().CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{LabelSelector: nodeLabelSelector})
if err != nil {
return nodeResources, err
}
nodeResources.NodeCount = len(nodeList.Items)
for _, node := range nodeList.Items {
if cpuQuantity, ok := node.Status.Allocatable["cpu"]; ok {
nodeResources.CPUMilliCores += cpuQuantity.MilliValue() / 1000
}
if memoryQuantity, ok := node.Status.Allocatable["memory"]; ok {
nodeResources.MemoryBytes += memoryQuantity.Value()
}
if podQuantity, ok := node.Status.Allocatable["pods"]; ok {
nodeResources.PodCapacity += podQuantity.Value()
}
}
return nodeResources, nil
}

// Returns the number of current running VMIs in the cluster
func (meta *Metadata) GetCurrentVMICount() (int, error) {
var vmiCount int
Expand Down
8 changes: 8 additions & 0 deletions ocp-metadata/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ type clusterVersion struct {
} `json:"status"`
}

// Type to store aggregated node capacity
type NodeResources struct {
CPUMilliCores int64
MemoryBytes int64
PodCapacity int64
NodeCount int
}

// Type to store cluster metadata
type ClusterMetadata struct {
MetricName string `json:"metricName,omitempty"`
Expand Down
Loading