Skip to content

Commit

Permalink
perform scale up if no candidate leases are present (#113)
Browse files Browse the repository at this point in the history
Co-authored-by: Rishabh Patel <[email protected]>
  • Loading branch information
gardener-ci-robot and rishabh-11 authored Apr 19, 2024
1 parent cd3ccdb commit e45fb22
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
15 changes: 9 additions & 6 deletions internal/prober/prober.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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) {
Expand Down
10 changes: 6 additions & 4 deletions internal/prober/prober_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit e45fb22

Please sign in to comment.