func (c *Resources) requiredInstances(cluster core.ClusterInterface, service framework.ServiceConfig) (int, error) { requiredInstances := 0 deployedService, err := cluster.FindService(service.Namespace, service.ServiceName, service.CompatibilityVersion) if err != nil { return 0, err } if deployedService == nil { requiredInstances = service.Instances logger.Instance().Infof("The service is new in cluster %s, deploy needs resources for %d instances", cluster.Id(), requiredInstances) } else if len(deployedService.Instances) == service.Instances { requiredInstances = int(math.Max(1, math.Floor(float64(service.Instances)*0.2))) logger.Instance().Infof("Service replacement in cluster %s, deploy needs resources for %d instances", cluster.Id(), requiredInstances) } else if len(deployedService.Instances) < service.Instances { requiredInstances = service.Instances - len(deployedService.Instances) logger.Instance().Infof("Service up scale in cluster %s, deploy needs resources for %d instances", cluster.Id(), requiredInstances) } else { logger.Instance().Infof("Service down scale in cluster %s, the cluster should have enough resources", cluster.Id()) } return requiredInstances, nil }