From fabcf115b5ec39cd605695dcb118243bf6f743c3 Mon Sep 17 00:00:00 2001 From: sbadiger Date: Wed, 1 Jun 2022 00:36:53 -0700 Subject: [PATCH] fix minor bugs Signed-off-by: sbadiger --- Makefile | 2 +- controllers/upgrade.go | 21 ++++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 267d9eb8..8bbb7669 100644 --- a/Makefile +++ b/Makefile @@ -59,7 +59,7 @@ vet: go vet ./... # Generate code -generate: clean controller-gen +generate: controller-gen $(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..." # Build the docker image diff --git a/controllers/upgrade.go b/controllers/upgrade.go index 95cf30a1..24819774 100644 --- a/controllers/upgrade.go +++ b/controllers/upgrade.go @@ -418,7 +418,7 @@ func (r *RollingUpgradeContext) ReplaceNodeBatch(batch []*autoscaling.Instance) func (r *RollingUpgradeContext) SelectTargets(scalingGroup *autoscaling.Group) []*autoscaling.Instance { var ( batchSize = r.RollingUpgrade.MaxUnavailable() - totalNodes = len(scalingGroup.Instances) + totalNodes = int(aws.Int64Value(scalingGroup.DesiredCapacity)) targets = make([]*autoscaling.Instance, 0) ) unavailableInt := CalculateMaxUnavailable(batchSize, totalNodes) @@ -645,14 +645,17 @@ func CalculateMaxUnavailable(batchSize intstr.IntOrString, totalNodes int) int { } func (r *RollingUpgradeContext) SetProgress(nodesProcessed int, totalNodes int) { - completePercentage := int(math.Round(float64(nodesProcessed) / float64(totalNodes) * 100)) - r.RollingUpgrade.SetTotalNodes(totalNodes) - r.RollingUpgrade.SetNodesProcessed(nodesProcessed) - r.RollingUpgrade.SetCompletePercentage(completePercentage) - - // expose total nodes and nodes processed to prometheus - common.SetTotalNodesMetric(r.RollingUpgrade.ScalingGroupName(), totalNodes) - common.SetNodesProcessedMetric(r.RollingUpgrade.ScalingGroupName(), nodesProcessed) + if totalNodes > 0 && nodesProcessed >= 0 { + r.RollingUpgrade.SetTotalNodes(totalNodes) + r.RollingUpgrade.SetNodesProcessed(nodesProcessed) + + completePercentage := int(math.Round(float64(nodesProcessed) / float64(totalNodes) * 100)) + r.RollingUpgrade.SetCompletePercentage(completePercentage) + + // expose total nodes and nodes processed to prometheus + common.SetTotalNodesMetric(r.RollingUpgrade.ScalingGroupName(), totalNodes) + common.SetNodesProcessedMetric(r.RollingUpgrade.ScalingGroupName(), nodesProcessed) + } }