func getESCurrentOrPendingPlan()

in pkg/formatter/text_template_utils.go [256:307]


func getESCurrentOrPendingPlan(clusterInfo models.ElasticsearchClusterInfo) *models.ElasticsearchClusterPlanInfo {
	if clusterInfo.PlanInfo.Pending != nil {
		return clusterInfo.PlanInfo.Pending
	}
	// This will be returned if both (Current and Pending) are nil
	// It populates the info in a best-effort manner, so data might
	// be slightly off.
	if clusterInfo.PlanInfo.Current == nil {
		var (
			zoneCount        int32
			zoneNames        []string
			memoryPerNode    int32
			version          = "?.?.?"
			nodeCountPerZone = int32(0)
		)
		for _, i := range clusterInfo.Topology.Instances {
			if !stringInSlice(i.Zone, zoneNames) {
				zoneNames = append(zoneNames, i.Zone)
				zoneCount++
				if strings.Split(*i.InstanceName, "-")[0] == "instance" && memoryPerNode == 0 {
					if i.Memory != nil {
						memoryPerNode = *i.Memory.InstanceCapacity
					}
				}
			}
		}

		if len(clusterInfo.Topology.Instances) > 0 || zoneCount > 0 {
			nodeCountPerZone = int32(len(clusterInfo.Topology.Instances)) / zoneCount
		}

		if len(clusterInfo.Topology.Instances) > 0 {
			version = clusterInfo.Topology.Instances[0].ServiceVersion
		}

		return &models.ElasticsearchClusterPlanInfo{
			Plan: &models.ElasticsearchClusterPlan{
				Elasticsearch: &models.ElasticsearchConfiguration{
					Version: version,
				},
				ClusterTopology: []*models.ElasticsearchClusterTopologyElement{
					{
						NodeCountPerZone: nodeCountPerZone,
						MemoryPerNode:    memoryPerNode,
						ZoneCount: zoneCount,
					},
				},
			},
		}
	}
	return clusterInfo.PlanInfo.Current
}