Skip to content

Commit

Permalink
Add grace period check for ReplicaSet availability
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoxhaa committed May 27, 2024
1 parent 9194ec0 commit f8d53a9
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/schema/v1/replica_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
ktypes "k8s.io/apimachinery/pkg/types"
"strings"
"time"
)

type ReplicaSet struct {
Expand Down Expand Up @@ -136,6 +137,18 @@ func (r *ReplicaSet) getIcingaState() (IcingaState, string) {
}
}

// Check if the ReplicaSet was created within the last 5 minutes
createdTime := r.GetCreationTimestamp()
gracePeriodDeadline := createdTime.Add(5 * time.Minute)
now := time.Now()

// Wait for the grace period to end
if now.Before(gracePeriodDeadline) {
timeLeft := gracePeriodDeadline.Sub(now)
reason := fmt.Sprintf("ReplicaSet %s/%s is within the grace period. Time left: %s", r.Namespace, r.Name, timeLeft.Round(time.Second))
return Ok, reason
}

switch {
case r.AvailableReplicas < 1:
reason := fmt.Sprintf("ReplicaSet %s/%s has no available replicas", r.Namespace, r.Name)
Expand Down

0 comments on commit f8d53a9

Please sign in to comment.