in ec/ecresource/deploymentresource/deployment/v2/deployment_read.go [388:441]
func getLowestVersion(res *models.DeploymentResources) (string, error) {
// We're starting off with a very high version so it can be replaced.
replaceVersion := `99.99.99`
version := semver.MustParse(replaceVersion)
for _, r := range res.Elasticsearch {
if !util.IsCurrentEsPlanEmpty(r) {
v := r.Info.PlanInfo.Current.Plan.Elasticsearch.Version
if err := swapLowerVersion(&version, v); err != nil && !elasticsearchv2.IsElasticsearchStopped(r) {
return "", fmt.Errorf("elasticsearch version '%s' is not semver compliant: %w", v, err)
}
}
}
for _, r := range res.Kibana {
if !util.IsCurrentKibanaPlanEmpty(r) && !kibanav2.IsKibanaStopped(r) {
v := r.Info.PlanInfo.Current.Plan.Kibana.Version
if err := swapLowerVersion(&version, v); err != nil {
return version.String(), fmt.Errorf("kibana version '%s' is not semver compliant: %w", v, err)
}
}
}
for _, r := range res.Apm {
if !util.IsCurrentApmPlanEmpty(r) && !apmv2.IsApmStopped(r) {
v := r.Info.PlanInfo.Current.Plan.Apm.Version
if err := swapLowerVersion(&version, v); err != nil {
return version.String(), fmt.Errorf("apm version '%s' is not semver compliant: %w", v, err)
}
}
}
for _, r := range res.IntegrationsServer {
if !util.IsCurrentIntegrationsServerPlanEmpty(r) && !integrationsserverv2.IsIntegrationsServerStopped(r) {
v := r.Info.PlanInfo.Current.Plan.IntegrationsServer.Version
if err := swapLowerVersion(&version, v); err != nil {
return version.String(), fmt.Errorf("integrations_server version '%s' is not semver compliant: %w", v, err)
}
}
}
for _, r := range res.EnterpriseSearch {
if !util.IsCurrentEssPlanEmpty(r) && !enterprisesearchv2.IsEnterpriseSearchStopped(r) {
v := r.Info.PlanInfo.Current.Plan.EnterpriseSearch.Version
if err := swapLowerVersion(&version, v); err != nil {
return version.String(), fmt.Errorf("enterprise search version '%s' is not semver compliant: %w", v, err)
}
}
}
if version.String() != replaceVersion {
return version.String(), nil
}
return "", errors.New("unable to determine the lowest version for any the deployment components")
}