Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix icinga states #126

Merged
merged 2 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading