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

Add Icinga states to daemon set #74

Merged
merged 2 commits into from
Jun 3, 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
31 changes: 31 additions & 0 deletions pkg/schema/v1/daemon_set.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package v1

import (
"fmt"
"github.com/icinga/icinga-go-library/types"
"github.com/icinga/icinga-kubernetes/pkg/database"
"github.com/icinga/icinga-kubernetes/pkg/strcase"
Expand All @@ -24,6 +25,8 @@ type DaemonSet struct {
NumberAvailable int32
NumberUnavailable int32
Yaml string
IcingaState IcingaState
IcingaStateReason string
Conditions []DaemonSetCondition `db:"-"`
Labels []Label `db:"-"`
DaemonSetLabels []DaemonSetLabel `db:"-"`
Expand Down Expand Up @@ -61,6 +64,7 @@ func (d *DaemonSet) Obtain(k8s kmetav1.Object) {
d.UpdateNumberScheduled = daemonSet.Status.UpdatedNumberScheduled
d.NumberAvailable = daemonSet.Status.NumberAvailable
d.NumberUnavailable = daemonSet.Status.NumberUnavailable
d.IcingaState, d.IcingaStateReason = d.getIcingaState()

for _, condition := range daemonSet.Status.Conditions {
d.Conditions = append(d.Conditions, DaemonSetCondition{
Expand Down Expand Up @@ -92,6 +96,33 @@ func (d *DaemonSet) Obtain(k8s kmetav1.Object) {
d.Yaml = string(output)
}

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

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)

return Critical, reason
case d.NumberAvailable < d.DesiredNumberScheduled:
reason := fmt.Sprintf("DaemonSet %s/%s pods are only available on %d out of %d desired nodes", d.Namespace, d.Name, d.NumberAvailable, d.DesiredNumberScheduled)

return Warning, reason
default:
reason := fmt.Sprintf("DaemonSet %s/%s has pods available on all %d desired nodes", d.Namespace, d.Name, d.DesiredNumberScheduled)

return Ok, reason
}
}

func (d *DaemonSet) Relations() []database.Relation {
fk := database.WithForeignKey("daemon_set_uuid")

Expand Down
2 changes: 2 additions & 0 deletions schema/mysql/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,8 @@ CREATE TABLE daemon_set (
number_available int unsigned NOT NULL,
number_unavailable int unsigned NOT NULL,
yaml mediumblob DEFAULT NULL,
icinga_state enum('ok', 'warning', 'critical', 'unknown') COLLATE utf8mb4_unicode_ci NOT NULL,
icinga_state_reason text NOT NULL,
created bigint unsigned NOT NULL,
PRIMARY KEY (uuid)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
Expand Down
Loading