Skip to content

Commit

Permalink
Add grace period check for DaemonSet availability
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoxhaa committed May 27, 2024
1 parent a238be8 commit bb37081
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/schema/v1/daemon_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 DaemonSet struct {
Expand Down Expand Up @@ -96,6 +97,18 @@ func (d *DaemonSet) getIcingaState() (IcingaState, string) {
return Unknown, reason
}

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

switch {
case d.NumberAvailable == 0:
reason := fmt.Sprintf("DaemonSet %s/%s has no available running nodes", d.Namespace, d.Name)
Expand Down

0 comments on commit bb37081

Please sign in to comment.