diff --git a/internal/prober/prober.go b/internal/prober/prober.go index b621563f..1909dac5 100644 --- a/internal/prober/prober.go +++ b/internal/prober/prober.go @@ -118,12 +118,7 @@ func (p *Prober) probe(ctx context.Context) { if err != nil { return } - if len(candidateNodeLeases) == 0 { - p.l.Info("No owned node leases are present in the cluster, skipping scaling operation") - return - } if p.shouldPerformScaleUp(candidateNodeLeases) { - p.l.Info("Lease probe succeeded, performing scale up operation if required") if err = p.scaler.ScaleUp(ctx); err != nil { p.l.Error(err, "Failed to scale up resources") } @@ -139,13 +134,21 @@ func (p *Prober) probe(ctx context.Context) { // shouldPerformScaleUp returns true if the ratio of expired node leases to valid node leases is less than // the NodeLeaseFailureFraction set in the prober config func (p *Prober) shouldPerformScaleUp(candidateNodeLeases []coordinationv1.Lease) bool { + if len(candidateNodeLeases) == 0 { + p.l.Info("No owned node leases are present in the cluster, performing scale up operation if required") + return true + } var expiredNodeLeaseCount float64 for _, lease := range candidateNodeLeases { if p.isLeaseExpired(lease) { expiredNodeLeaseCount++ } } - return expiredNodeLeaseCount/float64(len(candidateNodeLeases)) < *p.config.NodeLeaseFailureFraction + shouldScaleUp := expiredNodeLeaseCount/float64(len(candidateNodeLeases)) < *p.config.NodeLeaseFailureFraction + if shouldScaleUp { + p.l.Info("Lease probe succeeded, performing scale up operation if required") + } + return shouldScaleUp } func (p *Prober) setupProbeClient(ctx context.Context, namespace string, kubeConfigSecretName string) (kubernetes.Interface, error) { diff --git a/internal/prober/prober_test.go b/internal/prober/prober_test.go index 18c66838..d3fbf44d 100644 --- a/internal/prober/prober_test.go +++ b/internal/prober/prober_test.go @@ -181,11 +181,13 @@ func TestAPIServerProbeShouldNotRunIfClientNotCreated(t *testing.T) { createAndRunProber(t, testProbeInterval.Duration, config, mocks) } -func TestScalingShouldNotHappenIfNoOwnedLeasesPresent(t *testing.T) { +func TestScaleUpShouldHappenIfNoOwnedLeasesPresent(t *testing.T) { entry := probeTestCase{ - name: "lease probe should reset if no owned lease is present", - leaseList: createNodeLeases(nil), - nodeList: createNodes(0), + name: "scale up should happen if no owned lease is present", + leaseList: createNodeLeases(nil), + nodeList: createNodes(0), + minScaleUpCount: 1, + maxScaleUpCount: math.MaxInt8, } mocks := createAndInitializeMocks(t, entry) config := createConfig(testProbeInterval, metav1.Duration{Duration: time.Microsecond}, metav1.Duration{Duration: 40 * time.Second}, 0.2)