Skip to content

Commit

Permalink
Merge pull request #126 from Icinga/fix-icinga-states
Browse files Browse the repository at this point in the history
Fix icinga states
  • Loading branch information
lippserd authored Sep 26, 2024
2 parents 0dbb703 + db93fed commit 9ac5d7b
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 44 deletions.
21 changes: 0 additions & 21 deletions pkg/schema/v1/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import (
"github.com/icinga/icinga-go-library/types"
kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
ktypes "k8s.io/apimachinery/pkg/types"
kcache "k8s.io/client-go/tools/cache"
"reflect"
"time"
)

var NameSpaceKubernetes = uuid.MustParse("3f249403-2bb0-428f-8e91-504d1fd7ddb6")
Expand Down Expand Up @@ -118,25 +116,6 @@ func NewNullableString(s any) sql.NullString {
panic(fmt.Sprintf("invalid type %T", s))
}

func IsWithinGracePeriod(k kmetav1.Object) *string {
const gracePeriod = 5 * time.Minute

deadline := k.GetCreationTimestamp().Add(gracePeriod)
now := time.Now()
if now.Before(deadline) {
key, _ := kcache.MetaNamespaceKeyFunc(k)
reason := fmt.Sprintf(
"%s %s is within grace period until %s, so its state is not yet evaluated.",
types.Name(k),
key,
deadline)

return &reason
}

return nil
}

// Assert interface compliance.
var (
_ kmetav1.Object = (*Meta)(nil)
Expand Down
4 changes: 0 additions & 4 deletions pkg/schema/v1/daemon_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,6 @@ func (d *DaemonSet) getIcingaState() (IcingaState, string) {
return Unknown, reason
}

if gracePeriodReason := IsWithinGracePeriod(d); gracePeriodReason != nil {
return Ok, *gracePeriodReason
}

switch {
case d.NumberAvailable == 0:
reason := fmt.Sprintf("DaemonSet %s/%s does not have a single pod available which should run on %d desired nodes.", d.Namespace, d.Name, d.DesiredNumberScheduled)
Expand Down
4 changes: 0 additions & 4 deletions pkg/schema/v1/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,6 @@ func (d *Deployment) Obtain(k8s kmetav1.Object) {
}

func (d *Deployment) getIcingaState() (IcingaState, string) {
if gracePeriodReason := IsWithinGracePeriod(d); gracePeriodReason != nil {
return Ok, *gracePeriodReason
}

for _, condition := range d.Conditions {
if condition.Type == string(kappsv1.DeploymentAvailable) && condition.Status != string(kcorev1.ConditionTrue) {
reason := fmt.Sprintf("Deployment %s/%s is not available: %s.", d.Namespace, d.Name, condition.Message)
Expand Down
12 changes: 1 addition & 11 deletions pkg/schema/v1/replica_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,6 @@ func (r *ReplicaSet) Obtain(k8s kmetav1.Object) {
}

func (r *ReplicaSet) getIcingaState() (IcingaState, string) {
if r.DesiredReplicas < 1 {
reason := fmt.Sprintf("ReplicaSet %s/%s has an invalid desired replica count: %d.", r.Namespace, r.Name, r.DesiredReplicas)

return Unknown, reason
}

if gracePeriodReason := IsWithinGracePeriod(r); gracePeriodReason != nil {
return Ok, *gracePeriodReason
}

for _, condition := range r.Conditions {
if condition.Type == string(kappsv1.ReplicaSetReplicaFailure) && condition.Status == string(kcorev1.ConditionTrue) {
reason := fmt.Sprintf("ReplicaSet %s/%s has a failure condition: %s.", r.Namespace, r.Name, condition.Message)
Expand All @@ -173,7 +163,7 @@ func (r *ReplicaSet) getIcingaState() (IcingaState, string) {
}

switch {
case r.AvailableReplicas < 1:
case r.AvailableReplicas < 1 && r.DesiredReplicas > 0:
reason := fmt.Sprintf("ReplicaSet %s/%s has no replica available from %d desired.", r.Namespace, r.Name, r.DesiredReplicas)

return Critical, reason
Expand Down
4 changes: 0 additions & 4 deletions pkg/schema/v1/stateful_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,6 @@ func (s *StatefulSet) Obtain(k8s kmetav1.Object) {
}

func (s *StatefulSet) getIcingaState() (IcingaState, string) {
if gracePeriodReason := IsWithinGracePeriod(s); gracePeriodReason != nil {
return Ok, *gracePeriodReason
}

switch {
case s.AvailableReplicas == 0:
reason := fmt.Sprintf("StatefulSet %s/%s has no replica available from %d desired.", s.Namespace, s.Name, s.DesiredReplicas)
Expand Down

0 comments on commit 9ac5d7b

Please sign in to comment.