Skip to content

Commit

Permalink
Count control-plane labeled nodes as masters and omit empty fields wh…
Browse files Browse the repository at this point in the history
…en marshalling JSON

Signed-off-by: Raul Sevilla <[email protected]>
  • Loading branch information
rsevilla87 committed Nov 21, 2023
1 parent 6b6efc3 commit d9a5afb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
8 changes: 5 additions & 3 deletions ocp-metadata/ocp-metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,17 +225,19 @@ func (meta *Metadata) getNodesInfo(clusterMetadata *ClusterMetadata) error {
return err
}
clusterMetadata.TotalNodes = len(nodes.Items)
// When the master label is found, the node is considered a master, regarldess of other labels the node could have
// similar logic happens with the infra nodes
// When the master label is found, the node is considered a master, regardless of other labels the node could have
for _, node := range nodes.Items {
if _, ok := node.Labels["node-role.kubernetes.io/master"]; ok { // Check for master role
clusterMetadata.MasterNodesCount++
clusterMetadata.MasterNodesType = node.Labels["node.kubernetes.io/instance-type"]
if _, ok := node.Labels["node-role.kubernetes.io/worker"]; ok {
if len(node.Spec.Taints) == 0 { // When mastersSchedulable is true, master nodes have at least one taint
if len(node.Spec.Taints) == 0 { // When mastersSchedulable is false, master nodes have at least one taint
clusterMetadata.WorkerNodesCount++
}
}
} else if _, ok := node.Labels["node-role.kubernetes.io/control-plane"]; ok { // Check for control-plane role
clusterMetadata.MasterNodesCount++
clusterMetadata.MasterNodesType = node.Labels["node.kubernetes.io/instance-type"]
} else if _, ok := node.Labels["node-role.kubernetes.io/infra"]; ok { // Check for infra role
clusterMetadata.InfraNodesCount++
clusterMetadata.InfraNodesType = node.Labels["node.kubernetes.io/instance-type"]
Expand Down
32 changes: 16 additions & 16 deletions ocp-metadata/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,20 @@ type clusterVersion struct {
// Type to store cluster metadata
type ClusterMetadata struct {
MetricName string `json:"metricName,omitempty"`
Platform string `json:"platform"`
ClusterType string `json:"clusterType"`
OCPVersion string `json:"ocpVersion"`
OCPMajorVersion string `json:"ocpMajorVersion"`
K8SVersion string `json:"k8sVersion"`
MasterNodesType string `json:"masterNodesType"`
WorkerNodesType string `json:"workerNodesType"`
MasterNodesCount int `json:"masterNodesCount"`
InfraNodesType string `json:"infraNodesType"`
WorkerNodesCount int `json:"workerNodesCount"`
InfraNodesCount int `json:"infraNodesCount"`
OtherNodesCount int `json:"otherNodesCount"`
TotalNodes int `json:"totalNodes"`
SDNType string `json:"sdnType"`
ClusterName string `json:"clusterName"`
Region string `json:"region"`
Platform string `json:"platform,omitempty"`
ClusterType string `json:"clusterType,omitempty"`
OCPVersion string `json:"ocpVersion,omitempty"`
OCPMajorVersion string `json:"ocpMajorVersion,omitempty"`
K8SVersion string `json:"k8sVersion,omitempty"`
MasterNodesType string `json:"masterNodesType,omitempty"`
WorkerNodesType string `json:"workerNodesType,omitempty"`
MasterNodesCount int `json:"masterNodesCount,omitempty"`
InfraNodesType string `json:"infraNodesType,omitempty"`
WorkerNodesCount int `json:"workerNodesCount,omitempty"`
InfraNodesCount int `json:"infraNodesCount,omitempty"`
OtherNodesCount int `json:"otherNodesCount,omitempty"`
TotalNodes int `json:"totalNodes,omitempty"`
SDNType string `json:"sdnType,omitempty"`
ClusterName string `json:"clusterName,omitempty"`
Region string `json:"region,omitempty"`
}

0 comments on commit d9a5afb

Please sign in to comment.