Skip to content

Commit

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

type StatefulSet struct {
Expand Down Expand Up @@ -114,6 +115,18 @@ func (s *StatefulSet) Obtain(k8s kmetav1.Object) {
}

func (s *StatefulSet) getIcingaState() (IcingaState, string) {
// Check if the StatefulSet was created within the last 5 minutes
createdTime := s.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("StatefulSet %s/%s is within the grace period. Time left: %s", s.Namespace, s.Name, timeLeft.Round(time.Second))
return Ok, reason
}

switch {
case s.AvailableReplicas == 0:
reason := fmt.Sprintf("StatefulSet %s/%s has 0 available replicas", s.Namespace, s.Name)
Expand Down

0 comments on commit 0d2af4f

Please sign in to comment.